From 90803052313842c6af3e889a0ad7141ef4966938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Letz?= Date: Mon, 23 Dec 2024 01:37:43 +0100 Subject: [PATCH] Cleanup. --- architecture/faust/audio/miniaudio-dsp.h | 50 ++++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/architecture/faust/audio/miniaudio-dsp.h b/architecture/faust/audio/miniaudio-dsp.h index c4fc69211b..c24061c66f 100644 --- a/architecture/faust/audio/miniaudio-dsp.h +++ b/architecture/faust/audio/miniaudio-dsp.h @@ -36,6 +36,7 @@ #define MA_NO_ENCODING #define MA_NO_RESOURCE_MANAGER #define MA_NO_NODE_GRAPH +#define MA_DEBUG_OUTPUT #include "faust/miniaudio.h" /****************************************************************************** @@ -55,9 +56,6 @@ class miniaudio : public audio { long fSampleRate; long fBufferSize; - AudioChannels* fInputs; - AudioChannels* fOutputs; - // Callback function for MiniAudio stream static void audioCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { @@ -67,29 +65,36 @@ class miniaudio : public audio { virtual void processAudio(const void* pInput, void* pOutput, ma_uint32 frameCount) { AVOIDDENORMALS; + + float* in_buffers[fDSP->getNumInputs()]; + for (int i = 0; i < fDSP->getNumInputs(); ++i) { + in_buffers[i] = (float*)alloca(frameCount * sizeof(float)); + } + float* out_buffers[fDSP->getNumOutputs()]; + for (int i = 0; i < fDSP->getNumOutputs(); ++i) { + out_buffers[i] = (float*)alloca(frameCount * sizeof(float)); + } - // Read interleaved input data into the DSP input buffer - fInputs->interleavedRead((float*)pInput, frameCount, fDSP->getNumInputs()); - - // Compute DSP - fDSP->compute(frameCount, fInputs->buffers(), fOutputs->buffers()); - - // Write interleaved output data from the DSP output buffer - fOutputs->interleavedWrite((float*)pOutput, frameCount, fDSP->getNumOutputs()); + // Deinterleave the input audio frames into the input buffers + ma_deinterleave_pcm_frames(ma_format_f32, fDSP->getNumInputs(), frameCount, pInput, (void **)in_buffers); + + // Compute the DSP process on the deinterleaved buffers + fDSP->compute(frameCount, in_buffers, out_buffers); + + // Re-interleave the output frames back into a single interleaved buffer + ma_interleave_pcm_frames(ma_format_f32, fDSP->getNumOutputs(), frameCount, (const void **)out_buffers, pOutput); } public: miniaudio(long srate, long bsize) : - fDSP(nullptr), fSampleRate(srate), fBufferSize(bsize), fInputs(nullptr), fOutputs(nullptr) + fDSP(nullptr), fSampleRate(srate), fBufferSize(bsize) {} virtual ~miniaudio() { ma_device_stop(&fAudioDevice); ma_device_uninit(&fAudioDevice); - delete fInputs; - delete fOutputs; } virtual bool init(const char* name, ::dsp* DSP) @@ -124,40 +129,35 @@ class miniaudio : public audio { void setDsp(::dsp* DSP) { fDSP = DSP; - - // Allocate the stream adapters - fInputs = new AudioChannels(4096, fDSP->getNumInputs()); - fOutputs = new AudioChannels(4096, fDSP->getNumOutputs()); - fDSP->init(fSampleRate); } - virtual bool start() + bool start() { return ma_device_start(&fAudioDevice) == MA_SUCCESS; } - virtual void stop() + void stop() { ma_device_stop(&fAudioDevice); } - virtual int getBufferSize() + int getBufferSize() { return fBufferSize; } - virtual int getSampleRate() + int getSampleRate() { return fSampleRate; } - virtual int getNumInputs() + int getNumInputs() { return fDSP->getNumInputs(); } - virtual int getNumOutputs() + int getNumOutputs() { return fDSP->getNumOutputs(); }