Browse Source

Use 8/8 in/out channels for Bridge audio

tags/v0.6.0
Andrew Belt 7 years ago
parent
commit
2465d44eaf
3 changed files with 14 additions and 26 deletions
  1. +5
    -9
      include/bridgeprotocol.hpp
  2. +1
    -1
      src/audio.cpp
  3. +8
    -16
      src/bridge.cpp

+ 5
- 9
include/bridgeprotocol.hpp View File

@@ -15,6 +15,8 @@ namespace rack {
#define BRIDGE_NUM_PARAMS 16 #define BRIDGE_NUM_PARAMS 16
/** An arbitrary number which prevents connection from other protocols (like WebSockets) and old Bridge versions */ /** An arbitrary number which prevents connection from other protocols (like WebSockets) and old Bridge versions */
#define BRIDGE_HELLO 0xff00fefd #define BRIDGE_HELLO 0xff00fefd
#define BRIDGE_INPUTS 8
#define BRIDGE_OUTPUTS 8




/** All commands are called from the client and served by the server /** All commands are called from the client and served by the server
@@ -40,18 +42,12 @@ enum BridgeCommand {
- uint32_t sampleRate - uint32_t sampleRate
*/ */
AUDIO_SAMPLE_RATE_SET_COMMAND, 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 /** Sends and receives an audio buffer
send send
- uint32_t length
- float input[length]
- uint32_t frames
- float input[BRIDGE_INPUTS * frames]
recv recv
- float output[length]
- float output[BRIDGE_OUTPUTS * frames]
*/ */
AUDIO_PROCESS_COMMAND, AUDIO_PROCESS_COMMAND,
/** Resumes the audio buffer, forcing Rack to wait on an audio buffer */ /** Resumes the audio buffer, forcing Rack to wait on an audio buffer */


+ 1
- 1
src/audio.cpp View File

@@ -106,7 +106,7 @@ int AudioIO::getDeviceChannels(int device) {
return max((int) deviceInfo.inputChannels, (int) deviceInfo.outputChannels); return max((int) deviceInfo.inputChannels, (int) deviceInfo.outputChannels);
} }
else if (driver == BRIDGE_DRIVER) { else if (driver == BRIDGE_DRIVER) {
return 2;
return max(BRIDGE_OUTPUTS, BRIDGE_INPUTS);
} }
return 0; return 0;
} }


+ 8
- 16
src/bridge.cpp View File

@@ -34,7 +34,6 @@ struct BridgeClientConnection {


int port = -1; int port = -1;
int sampleRate = 0; int sampleRate = 0;
int audioChannels = 0;
bool audioActive = false; bool audioActive = false;


~BridgeClientConnection() { ~BridgeClientConnection() {
@@ -159,30 +158,23 @@ struct BridgeClientConnection {
setSampleRate(sampleRate); setSampleRate(sampleRate);
} break; } break;


case AUDIO_CHANNELS_SET_COMMAND: {
uint8_t channels = 0;
recv<uint8_t>(&channels);
// TODO
} break;

case AUDIO_PROCESS_COMMAND: { case AUDIO_PROCESS_COMMAND: {
uint32_t length = 0;
recv<uint32_t>(&length);
if (length == 0 || length > (1<<16)) {
uint32_t frames = 0;
recv<uint32_t>(&frames);
if (frames == 0 || frames > (1<<16)) {
ready = false; ready = false;
return; 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; ready = false;
return; return;
} }
float output[length];
int frames = length / 2;
float output[BRIDGE_OUTPUTS * frames];
memset(&output, 0, sizeof(output)); memset(&output, 0, sizeof(output));
processStream(input, output, frames); processStream(input, output, frames);
send(&output, length * sizeof(float));
send(&output, BRIDGE_OUTPUTS * frames * sizeof(float));
// flush(); // flush();
} break; } break;


@@ -247,7 +239,7 @@ struct BridgeClientConnection {
if (!audioListeners[port]) if (!audioListeners[port])
return; return;
if (audioActive) if (audioActive)
audioListeners[port]->setChannels(2, 2);
audioListeners[port]->setChannels(BRIDGE_OUTPUTS, BRIDGE_INPUTS);
else else
audioListeners[port]->setChannels(0, 0); audioListeners[port]->setChannels(0, 0);
audioListeners[port]->setSampleRate(sampleRate); audioListeners[port]->setSampleRate(sampleRate);


Loading…
Cancel
Save