Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Dec 23, 2024
1 parent 0890000 commit 9080305
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions architecture/faust/audio/miniaudio-dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/******************************************************************************
Expand All @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 9080305

Please sign in to comment.