Skip to content

Commit

Permalink
Limit standalone bridges audio to 2 IO
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Feb 26, 2023
1 parent 169a1bc commit 18f3fa3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 26 deletions.
12 changes: 12 additions & 0 deletions distrho/src/jackbridge/NativeBridge.hpp
Expand Up @@ -21,6 +21,18 @@

#include "../../extra/RingBuffer.hpp"

#if DISTRHO_PLUGIN_NUM_INPUTS > 2
# define DISTRHO_PLUGIN_NUM_INPUTS_2 2
#else
# define DISTRHO_PLUGIN_NUM_INPUTS_2 DISTRHO_PLUGIN_NUM_INPUTS
#endif

#if DISTRHO_PLUGIN_NUM_OUTPUTS > 2
# define DISTRHO_PLUGIN_NUM_OUTPUTS_2 2
#else
# define DISTRHO_PLUGIN_NUM_OUTPUTS_2 DISTRHO_PLUGIN_NUM_OUTPUTS
#endif

using DISTRHO_NAMESPACE::HeapRingBuffer;

struct NativeBridge {
Expand Down
10 changes: 5 additions & 5 deletions distrho/src/jackbridge/RtAudioBridge.hpp
Expand Up @@ -302,15 +302,15 @@ struct RtAudioBridge : NativeBridge {
if (withInput)
{
inParams.deviceId = rtAudio->getDefaultInputDevice();
inParams.nChannels = DISTRHO_PLUGIN_NUM_INPUTS;
inParams.nChannels = DISTRHO_PLUGIN_NUM_INPUTS_2;
inParamsPtr = &inParams;
}
#endif

#if DISTRHO_PLUGIN_NUM_OUTPUTS > 0
RtAudio::StreamParameters outParams;
outParams.deviceId = rtAudio->getDefaultOutputDevice();
outParams.nChannels = DISTRHO_PLUGIN_NUM_OUTPUTS;
outParams.nChannels = DISTRHO_PLUGIN_NUM_OUTPUTS_2;
RtAudio::StreamParameters* const outParamsPtr = &outParams;
#else
RtAudio::StreamParameters* const outParamsPtr = nullptr;
Expand Down Expand Up @@ -359,22 +359,22 @@ struct RtAudioBridge : NativeBridge {
if (self->jackProcessCallback == nullptr)
{
if (outputBuffer != nullptr)
std::memset((float*)outputBuffer, 0, sizeof(float)*numFrames*DISTRHO_PLUGIN_NUM_OUTPUTS);
std::memset((float*)outputBuffer, 0, sizeof(float)*numFrames*DISTRHO_PLUGIN_NUM_OUTPUTS_2);
return 0;
}

#if DISTRHO_PLUGIN_NUM_INPUTS > 0
if (float* const insPtr = static_cast<float*>(inputBuffer))
{
for (uint i=0; i<DISTRHO_PLUGIN_NUM_INPUTS; ++i)
for (uint i=0; i<DISTRHO_PLUGIN_NUM_INPUTS_2; ++i)
self->audioBuffers[i] = insPtr + (i * numFrames);
}
#endif

#if DISTRHO_PLUGIN_NUM_OUTPUTS > 0
if (float* const outsPtr = static_cast<float*>(outputBuffer))
{
for (uint i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS; ++i)
for (uint i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS_2; ++i)
self->audioBuffers[DISTRHO_PLUGIN_NUM_INPUTS + i] = outsPtr + (i * numFrames);
}
#endif
Expand Down
20 changes: 10 additions & 10 deletions distrho/src/jackbridge/SDL2Bridge.hpp
Expand Up @@ -68,7 +68,7 @@ struct SDL2Bridge : NativeBridge {

#if DISTRHO_PLUGIN_NUM_INPUTS > 0
SDL_SetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME, "Capure");
requested.channels = DISTRHO_PLUGIN_NUM_INPUTS;
requested.channels = DISTRHO_PLUGIN_NUM_INPUTS_2;
requested.callback = AudioInputCallback;

SDL_AudioSpec receivedCapture;
Expand All @@ -81,7 +81,7 @@ struct SDL2Bridge : NativeBridge {
return false;
#endif
}
else if (receivedCapture.channels != DISTRHO_PLUGIN_NUM_INPUTS)
else if (receivedCapture.channels != DISTRHO_PLUGIN_NUM_INPUTS_2)
{
SDL_CloseAudioDevice(captureDeviceId);
captureDeviceId = 0;
Expand All @@ -93,7 +93,7 @@ struct SDL2Bridge : NativeBridge {
#if DISTRHO_PLUGIN_NUM_OUTPUTS > 0
SDL_AudioSpec receivedPlayback;
SDL_SetHint(SDL_HINT_AUDIO_DEVICE_STREAM_NAME, "Playback");
requested.channels = DISTRHO_PLUGIN_NUM_OUTPUTS;
requested.channels = DISTRHO_PLUGIN_NUM_OUTPUTS_2;
requested.callback = AudioOutputCallback;

playbackDeviceId = SDL_OpenAudioDevice(nullptr, 0, &requested, &receivedPlayback,
Expand All @@ -104,7 +104,7 @@ struct SDL2Bridge : NativeBridge {
return false;
}

if (receivedPlayback.channels != DISTRHO_PLUGIN_NUM_OUTPUTS)
if (receivedPlayback.channels != DISTRHO_PLUGIN_NUM_OUTPUTS_2)
{
SDL_CloseAudioDevice(playbackDeviceId);
playbackDeviceId = 0;
Expand Down Expand Up @@ -211,15 +211,15 @@ struct SDL2Bridge : NativeBridge {
if (self->jackProcessCallback == nullptr)
return;

const uint numFrames = static_cast<uint>(len / sizeof(float) / DISTRHO_PLUGIN_NUM_INPUTS);
const uint numFrames = static_cast<uint>(len / sizeof(float) / DISTRHO_PLUGIN_NUM_INPUTS_2);
DISTRHO_SAFE_ASSERT_UINT2_RETURN(numFrames == self->bufferSize, numFrames, self->bufferSize,);

const float* const fstream = (const float*)stream;

for (uint i=0; i<DISTRHO_PLUGIN_NUM_INPUTS; ++i)
for (uint i=0; i<DISTRHO_PLUGIN_NUM_INPUTS_2; ++i)
{
for (uint j=0; j<numFrames; ++j)
self->audioBuffers[i][j] = fstream[j * DISTRHO_PLUGIN_NUM_INPUTS + i];
self->audioBuffers[i][j] = fstream[j * DISTRHO_PLUGIN_NUM_INPUTS_2 + i];
}

#if DISTRHO_PLUGIN_NUM_OUTPUTS == 0
Expand All @@ -245,18 +245,18 @@ struct SDL2Bridge : NativeBridge {
return;
}

const uint numFrames = static_cast<uint>(len / sizeof(float) / DISTRHO_PLUGIN_NUM_OUTPUTS);
const uint numFrames = static_cast<uint>(len / sizeof(float) / DISTRHO_PLUGIN_NUM_OUTPUTS_2);
DISTRHO_SAFE_ASSERT_UINT2_RETURN(numFrames == self->bufferSize, numFrames, self->bufferSize,);

const ScopedDenormalDisable sdd;
self->jackProcessCallback(numFrames, self->jackProcessArg);

float* const fstream = (float*)stream;

for (uint i=0; i < DISTRHO_PLUGIN_NUM_OUTPUTS; ++i)
for (uint i=0; i < DISTRHO_PLUGIN_NUM_OUTPUTS_2; ++i)
{
for (uint j=0; j < numFrames; ++j)
fstream[j * DISTRHO_PLUGIN_NUM_OUTPUTS + i] = self->audioBuffers[DISTRHO_PLUGIN_NUM_INPUTS + i][j];
fstream[j * DISTRHO_PLUGIN_NUM_OUTPUTS_2 + i] = self->audioBuffers[DISTRHO_PLUGIN_NUM_INPUTS + i][j];
}
}
#endif
Expand Down
23 changes: 12 additions & 11 deletions distrho/src/jackbridge/WebBridge.hpp
Expand Up @@ -163,7 +163,7 @@ struct WebBridge : NativeBridge {
if (WAB.audioContext.state === 'suspended')
WAB.audioContext.resume();
});
}, DISTRHO_PLUGIN_NUM_INPUTS, DISTRHO_PLUGIN_NUM_OUTPUTS, bufferSize, audioBufferStorage, WebAudioCallback, this);
}, DISTRHO_PLUGIN_NUM_INPUTS_2, DISTRHO_PLUGIN_NUM_OUTPUTS_2, bufferSize, audioBufferStorage, WebAudioCallback, this);

return true;
}
Expand Down Expand Up @@ -247,7 +247,7 @@ struct WebBridge : NativeBridge {
} else if (navigator.webkitGetUserMedia !== undefined) {
navigator.webkitGetUserMedia(constraints, success, fail);
}
}, DISTRHO_PLUGIN_NUM_INPUTS);
}, DISTRHO_PLUGIN_NUM_INPUTS_2);

return true;
}
Expand Down Expand Up @@ -279,7 +279,7 @@ struct WebBridge : NativeBridge {
WAB.captureStreamNode.disconnect(WAB.processor);

return 1;
}, DISTRHO_PLUGIN_NUM_INPUTS, DISTRHO_PLUGIN_NUM_OUTPUTS, newBufferSize) != 0;
}, DISTRHO_PLUGIN_NUM_INPUTS_2, DISTRHO_PLUGIN_NUM_OUTPUTS_2, newBufferSize) != 0;

if (!success)
return false;
Expand All @@ -292,9 +292,10 @@ struct WebBridge : NativeBridge {
bufferSizeCallback(newBufferSize, jackBufferSizeArg);

EM_ASM({
var numInputs = $0;
var numOutputs = $1;
var bufferSize = $2;
var numInputsR = $0;
var numInputs = $1;
var numOutputs = $2;
var bufferSize = $3;
var WAB = Module['WebAudioBridge'];

// store the new processor
Expand All @@ -309,13 +310,13 @@ struct WebBridge : NativeBridge {
var buffer = e['inputBuffer']['getChannelData'](i);
for (var j = 0; j < bufferSize; ++j) {
// setValue($3 + ((bufferSize * i) + j) * 4, buffer[j], 'float');
HEAPF32[$3 + (((bufferSize * i) + j) << 2) >> 2] = buffer[j];
HEAPF32[$4 + (((bufferSize * i) + j) << 2) >> 2] = buffer[j];
}
}
dynCall('vi', $4, [$5]);
dynCall('vi', $5, [$6]);
for (var i = 0; i < numOutputs; ++i) {
var buffer = e['outputBuffer']['getChannelData'](i);
var offset = bufferSize * (numInputs + i);
var offset = bufferSize * (numInputsR + i);
for (var j = 0; j < bufferSize; ++j) {
buffer[j] = HEAPF32[$3 + ((offset + j) << 2) >> 2];
}
Expand All @@ -329,7 +330,7 @@ struct WebBridge : NativeBridge {
if (WAB.captureStreamNode)
WAB.captureStreamNode.connect(WAB.processor);

}, DISTRHO_PLUGIN_NUM_INPUTS, DISTRHO_PLUGIN_NUM_OUTPUTS, bufferSize, audioBufferStorage, WebAudioCallback, this);
}, DISTRHO_PLUGIN_NUM_INPUTS, DISTRHO_PLUGIN_NUM_INPUTS_2, DISTRHO_PLUGIN_NUM_OUTPUTS_2, bufferSize, audioBufferStorage, WebAudioCallback, this);

return true;
}
Expand Down Expand Up @@ -452,7 +453,7 @@ struct WebBridge : NativeBridge {
}
else
{
for (uint i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS; ++i)
for (uint i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS_2; ++i)
std::memset(self->audioBuffers[DISTRHO_PLUGIN_NUM_INPUTS + i], 0, sizeof(float)*numFrames);
}
}
Expand Down

0 comments on commit 18f3fa3

Please sign in to comment.