Commit 855f8f17 authored by Leander Schulten's avatar Leander Schulten

Modules + Audio: Update Modules FFT view when the capturing device changes,...

Modules + Audio: Update Modules FFT view when the capturing device changes, otherwise no new data will be available
parent 6040e6ea
Pipeline #271447 passed with stage
in 18 minutes and 15 seconds
......@@ -35,7 +35,8 @@ void AudioCaptureManager::initCallback(int channels, int samplesPerSecond) {
if (GUI::Colorplot::getLast()) {
GUI::Colorplot::getLast()->setBlockSize(512);
}
spectrumAnalysis.emplace(2048, samplesPerFrame);
spectrumAnalysis.emplace(SPECTRUM_BUCKET_COUNT, samplesPerFrame);
emit capturingStarted();
}
void AudioCaptureManager::dataCallback(float* data, unsigned int frames, bool*done){
......
......@@ -43,6 +43,7 @@ class AudioCaptureManager : public QObject
ModelVector<QString> captureDeviceNames;
// we use a optional to delay the creation of the object until we know the samplesPerFrame value
std::optional<Aubio::SpectrumAnalysis> spectrumAnalysis;
static constexpr int SPECTRUM_BUCKET_COUNT = 2048;
int channels = -1;
int samplesPerSecond = -1;
......@@ -131,6 +132,11 @@ public:
signals:
void capturingStatusChanged();
void currentCaptureDeviceChanged();
/**
* @brief capturingStarted is emmited when the capturing really starts (the init callback is called).
* You now should update your reference from the getFFTOutput() function
*/
void capturingStarted();
};
template <typename String>
......
#include "modulemanager.h"
#include <QLibrary>
#include "dmxconsumer.h"
#include "ledconsumer.h"
#include "module.h"
#include <QDebug>
#include "scanner.h"
#include "scanner.hpp"
#include "settings.h"
#include <QJsonObject>
#include <QJsonArray>
#include "audio/audiocapturemanager.h"
#include "dmxconsumer.h"
#include "scanner.hpp"
#include "scanner.h"
#include "ledconsumer.h"
#include <QDebug>
#include <QJsonArray>
#include <QJsonObject>
#include <QLibrary>
#include <QtDebug>
namespace Modules {
......@@ -75,13 +76,21 @@ typedef Modules::Program* (*CreateProgramm)(unsigned int index);
ModuleManager::ModuleManager()
{
fftOutputView = Audio::AudioCaptureManager::get().getFFTOutput();
captureStatusChangedConnection = QObject::connect(&Audio::AudioCaptureManager::get(),&Audio::AudioCaptureManager::capturingStatusChanged,[this](){
for(const auto & info : loadedLibraryMap){
if(info.second.supportAudioFunc){
captureStatusChangedConnection = QObject::connect(&Audio::AudioCaptureManager::get(), &Audio::AudioCaptureManager::capturingStatusChanged, [this]() {
for (const auto &info : loadedLibraryMap) {
if (info.second.supportAudioFunc) {
info.second.supportAudioFunc(Audio::AudioCaptureManager::get().isCapturing());
}
}
});
QObject::connect(&Audio::AudioCaptureManager::get(), &Audio::AudioCaptureManager::capturingStarted, [this]() {
fftOutputView = Audio::AudioCaptureManager::get().getFFTOutput();
for (const auto &info : loadedLibraryMap) {
if (info.second.setFFTOutputViewFunc) {
info.second.setFFTOutputViewFunc(&fftOutputView);
}
}
});
// add the DMXConsumer for the old driver
consumer.emplace("DMXConsumer","With the DMXConsumer class you can write to the DMX Channels",-1,[](){
return new DMXConsumer;
......@@ -193,8 +202,9 @@ typedef Modules::Program* (*CreateProgramm)(unsigned int index);
}
lastLibraryIdentifier++;
SupportAudioFunc supportAudioFunc = nullptr;
SetFFTOutputViewFunc setFFTOutputViewFunc = nullptr;
if(f(MODUL_TYPE::Audio)){
supportAudioFunc = loadAudio(lib,&fftOutputView);
std::tie(supportAudioFunc, setFFTOutputViewFunc) = loadAudio(lib, &fftOutputView);
}
if(f(MODUL_TYPE::Spotify)){
typedef void (*SetSpotifyFunc)(Modules::SpotifyState const *);
......@@ -271,8 +281,7 @@ typedef Modules::Program* (*CreateProgramm)(unsigned int index);
});
}
loadedLibraryMap.emplace_back(lib.fileName(),LibInfo{lastLibraryIdentifier,supportAudioFunc});
loadedLibraryMap.emplace_back(lib.fileName(), LibInfo{lastLibraryIdentifier, supportAudioFunc, setFFTOutputViewFunc});
}else{
#ifdef Q_OS_WIN
if(lib.errorString().endsWith("Unknown error 0x000000c1.")){
......@@ -297,19 +306,15 @@ typedef Modules::Program* (*CreateProgramm)(unsigned int index);
}
}
ModuleManager::SupportAudioFunc ModuleManager::loadAudio(QLibrary &lib, Modules::FFTOutputView<float> *fftOutputView) {
//typedef void (*SupportAudioFunc )(bool);
typedef void (*SetFFTOutputViewFunc )(Modules::FFTOutputView<float>*);
//using SupportAudioFunc = unsigned int (bool);
//using SetFFTOutputViewFunc = char const * (Modules::FFTOutputView<float>*);
std::tuple<ModuleManager::SupportAudioFunc, ModuleManager::SetFFTOutputViewFunc> ModuleManager::loadAudio(QLibrary &lib, Modules::FFTOutputView<float> *fftOutputView) {
auto supportAudioFunc = reinterpret_cast<SupportAudioFunc>(lib.resolve("_supportAudio"));
auto setFFTOutputViewFunc = reinterpret_cast<SetFFTOutputViewFunc>(lib.resolve("_setFFTOutputView"));
if (!supportAudioFunc || !setFFTOutputViewFunc) {
qDebug() << "Error loading audio functions : "<< supportAudioFunc << setFFTOutputViewFunc;
return nullptr;
qWarning() << "Error loading audio functions : " << supportAudioFunc << setFFTOutputViewFunc;
return {nullptr, nullptr};
}
setFFTOutputViewFunc(fftOutputView);
supportAudioFunc(Audio::AudioCaptureManager::get().isCapturing());
return supportAudioFunc;
return {supportAudioFunc, setFFTOutputViewFunc};
}
} // namespace Modules
......@@ -267,10 +267,12 @@ signals:
typedef ModuleContainer<detail::Entry<Program>> ProgrammModuleContainer;
typedef ModuleContainer<detail::Entry<Filter>> FilterModuleContainer;
typedef ModuleContainer<detail::Entry<Consumer>> ConsumerModuleContainer;
typedef void (*SupportAudioFunc)(bool);
using SupportAudioFunc = void (*)(bool);
using SetFFTOutputViewFunc = void (*)(Modules::FFTOutputView<float> *);
struct LibInfo{
int libraryIdentifier = -1;
SupportAudioFunc supportAudioFunc = nullptr;
SetFFTOutputViewFunc setFFTOutputViewFunc = nullptr;
};
std::vector<std::pair<QString,LibInfo>> loadedLibraryMap;
int lastLibraryIdentifier = 0;
......@@ -286,7 +288,7 @@ signals:
template<typename Type, typename String, typename Callback>
static void loadType(QLibrary & lib, ModuleContainer<detail::Entry<Type>> &c,String name, int libraryIdentifier, Callback = nullptr);
static SupportAudioFunc loadAudio(QLibrary & lib,Modules::FFTOutputView<float> * fftOutputView);
static std::tuple<SupportAudioFunc, SetFFTOutputViewFunc> loadAudio(QLibrary &lib, Modules::FFTOutputView<float> *fftOutputView);
public:
ModuleManager();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment