Browse Source

Router audio stream from Bridge to AudioIO

tags/v0.6.0
Andrew Belt 6 years ago
parent
commit
b1722af5a4
3 changed files with 19 additions and 8 deletions
  1. +1
    -1
      include/audio.hpp
  2. +5
    -5
      src/Core/AudioInterface.cpp
  3. +13
    -2
      src/bridge.cpp

+ 1
- 1
include/audio.hpp View File

@@ -51,7 +51,7 @@ struct AudioIO {


std::vector<int> getSampleRates(); std::vector<int> getSampleRates();


virtual void processStream(const float *input, float *output, int length) {}
virtual void processStream(const float *input, float *output, int frames) {}
virtual void onCloseStream() {} virtual void onCloseStream() {}
virtual void onOpenStream() {} virtual void onOpenStream() {}
json_t *toJson(); json_t *toJson();


+ 5
- 5
src/Core/AudioInterface.cpp View File

@@ -40,10 +40,10 @@ struct AudioInterfaceIO : AudioIO {
setDevice(-1, 0); setDevice(-1, 0);
} }


void processStream(const float *input, float *output, int length) override {
void processStream(const float *input, float *output, int frames) override {
if (numInputs > 0) { if (numInputs > 0) {
// TODO Do we need to wait on the input to be consumed here? Experimentally, it works fine if we don't. // TODO Do we need to wait on the input to be consumed here? Experimentally, it works fine if we don't.
for (int i = 0; i < length; i++) {
for (int i = 0; i < frames; i++) {
if (inputBuffer.full()) if (inputBuffer.full())
break; break;
Frame<INPUTS> f; Frame<INPUTS> f;
@@ -56,19 +56,19 @@ struct AudioInterfaceIO : AudioIO {
if (numOutputs > 0) { if (numOutputs > 0) {
std::unique_lock<std::mutex> lock(audioMutex); std::unique_lock<std::mutex> lock(audioMutex);
auto cond = [&] { auto cond = [&] {
return (outputBuffer.size() >= (size_t) length);
return (outputBuffer.size() >= (size_t) frames);
}; };
auto timeout = std::chrono::milliseconds(100); auto timeout = std::chrono::milliseconds(100);
if (audioCv.wait_for(lock, timeout, cond)) { if (audioCv.wait_for(lock, timeout, cond)) {
// Consume audio block // Consume audio block
for (int i = 0; i < length; i++) {
for (int i = 0; i < frames; i++) {
Frame<OUTPUTS> f = outputBuffer.shift(); Frame<OUTPUTS> f = outputBuffer.shift();
memcpy(&output[numOutputs * i], &f, numOutputs * sizeof(float)); memcpy(&output[numOutputs * i], &f, numOutputs * sizeof(float));
} }
} }
else { else {
// Timed out, fill output with zeros // Timed out, fill output with zeros
memset(output, 0, length * numOutputs * sizeof(float));
memset(output, 0, frames * numOutputs * sizeof(float));
} }
} }




+ 13
- 2
src/bridge.cpp View File

@@ -139,9 +139,12 @@ struct BridgeClientConnection {
} }
else { else {
if (recvQueue.size() >= (size_t) audioBufferLength) { if (recvQueue.size() >= (size_t) audioBufferLength) {
// TODO Do something with the data
recvQueue.start += audioBufferLength;
debug("Received %d audio samples", audioBufferLength); debug("Received %d audio samples", audioBufferLength);
float input[audioBufferLength];
float output[audioBufferLength] = {};
recvQueue.shiftBuffer((uint8_t*) input, sizeof(float) * audioBufferLength);
int frames = audioBufferLength / 2;
processStream(input, output, frames);
audioBufferLength = -1; audioBufferLength = -1;
currentCommand = NO_COMMAND; currentCommand = NO_COMMAND;
return true; return true;
@@ -180,6 +183,14 @@ struct BridgeClientConnection {
// Loop the state machine until it returns false // Loop the state machine until it returns false
while (step()) {} while (step()) {}
} }

void processStream(const float *input, float *output, int length) {
if (!(0 <= channel && channel < BRIDGE_CHANNELS))
return;
if (!audioListeners[channel])
return;
audioListeners[channel]->processStream(input, output, length);
}
}; };






Loading…
Cancel
Save