Bug fixes for audio textures

This commit is contained in:
Digital Artifex
2025-08-10 05:06:15 -04:00
parent 396b1cb104
commit 49ae3bb429
7 changed files with 73 additions and 96 deletions

View File

@@ -5,8 +5,9 @@
#include <QQuickImageProvider>
#include "AudioModel.h"
#include "Komplex_global.h"
class AudioImageProvider : public QQuickImageProvider
class KOMPLEX_EXPORT AudioImageProvider : public QQuickImageProvider
{
public:
explicit AudioImageProvider();

View File

@@ -120,6 +120,9 @@ AudioModel::~AudioModel()
void AudioModel::startCapture()
{
if(!m_instance)
m_instance = new AudioModel();
if(m_thread->isRunning())
return;
@@ -139,6 +142,9 @@ void AudioModel::startCaptureAsync()
QPixmap AudioModel::frame()
{
if(!m_instance)
return QPixmap();
return m_instance->m_frame;
}
@@ -319,7 +325,8 @@ void AudioModel::on_process(void *userdata)
}
// Blackman window function
std::vector<double> AudioModel::createBlackmanWindow(int size) {
std::vector<double> AudioModel::createBlackmanWindow(int size)
{
std::vector<double> window(size);
const double a0 = 0.42;
const double a1 = 0.5;

View File

@@ -12,7 +12,7 @@
* https://webaudio.github.io/web-audio-api/#smoothing-over-time
*
* The described smoothing method was resulting in inconsistent data. This
* is likely to a poor implementation. A linear smoothing algo seems to work
* is likely due to a poor implementation. A linear smoothing algo seems to work
* (at least visually). Will need to revisit the temporal implementation if
* things do not work as expected.
*

View File

@@ -7,6 +7,15 @@
#include "ShaderPackModel.h"
#include "Komplex_global.h"
AudioModel *komplexAudioSingletonProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
AudioModel *model = new AudioModel();
return model;
}
class KOMPLEX_EXPORT KomplexPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
@@ -16,7 +25,7 @@ public:
{
Q_ASSERT(QLatin1String(uri) == QLatin1String("com.github.digitalartifex.komplex"));
qmlRegisterType<AudioModel>(uri, 1, 0, "AudioModel");
qmlRegisterSingletonType<AudioModel*>(uri, 1, 0, "AudioModel", komplexAudioSingletonProvider);
qmlRegisterType<ShaderPackModel>(uri, 1, 0, "ShaderPackModel");
}