diff --git a/include/bridgeprotocol.hpp b/include/bridgeprotocol.hpp index d3194102..1b5e3c46 100644 --- a/include/bridgeprotocol.hpp +++ b/include/bridgeprotocol.hpp @@ -15,6 +15,8 @@ namespace rack { #define BRIDGE_NUM_PARAMS 16 /** An arbitrary number which prevents connection from other protocols (like WebSockets) and old Bridge versions */ #define BRIDGE_HELLO 0xff00fefd +#define BRIDGE_INPUTS 8 +#define BRIDGE_OUTPUTS 8 /** All commands are called from the client and served by the server @@ -40,18 +42,12 @@ enum BridgeCommand { - uint32_t sampleRate */ AUDIO_SAMPLE_RATE_SET_COMMAND, - /** Sets the number of audio channels - Currently not supported, hard-coded at 2. - send - - uint8_t channels - */ - AUDIO_CHANNELS_SET_COMMAND, /** Sends and receives an audio buffer send - - uint32_t length - - float input[length] + - uint32_t frames + - float input[BRIDGE_INPUTS * frames] recv - - float output[length] + - float output[BRIDGE_OUTPUTS * frames] */ AUDIO_PROCESS_COMMAND, /** Resumes the audio buffer, forcing Rack to wait on an audio buffer */ diff --git a/src/audio.cpp b/src/audio.cpp index 140e1b53..8fc81250 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -106,7 +106,7 @@ int AudioIO::getDeviceChannels(int device) { return max((int) deviceInfo.inputChannels, (int) deviceInfo.outputChannels); } else if (driver == BRIDGE_DRIVER) { - return 2; + return max(BRIDGE_OUTPUTS, BRIDGE_INPUTS); } return 0; } diff --git a/src/bridge.cpp b/src/bridge.cpp index 5629a5ec..4fe700af 100644 --- a/src/bridge.cpp +++ b/src/bridge.cpp @@ -34,7 +34,6 @@ struct BridgeClientConnection { int port = -1; int sampleRate = 0; - int audioChannels = 0; bool audioActive = false; ~BridgeClientConnection() { @@ -159,30 +158,23 @@ struct BridgeClientConnection { setSampleRate(sampleRate); } break; - case AUDIO_CHANNELS_SET_COMMAND: { - uint8_t channels = 0; - recv(&channels); - // TODO - } break; - case AUDIO_PROCESS_COMMAND: { - uint32_t length = 0; - recv(&length); - if (length == 0 || length > (1<<16)) { + uint32_t frames = 0; + recv(&frames); + if (frames == 0 || frames > (1<<16)) { ready = false; return; } - float input[length]; - if (!recv(&input, length * sizeof(float))) { + float input[BRIDGE_INPUTS * frames]; + if (!recv(&input, BRIDGE_INPUTS * frames * sizeof(float))) { ready = false; return; } - float output[length]; - int frames = length / 2; + float output[BRIDGE_OUTPUTS * frames]; memset(&output, 0, sizeof(output)); processStream(input, output, frames); - send(&output, length * sizeof(float)); + send(&output, BRIDGE_OUTPUTS * frames * sizeof(float)); // flush(); } break; @@ -247,7 +239,7 @@ struct BridgeClientConnection { if (!audioListeners[port]) return; if (audioActive) - audioListeners[port]->setChannels(2, 2); + audioListeners[port]->setChannels(BRIDGE_OUTPUTS, BRIDGE_INPUTS); else audioListeners[port]->setChannels(0, 0); audioListeners[port]->setSampleRate(sampleRate);