From eaf27a942efc8df31a25b5858c9df48cf8f6db44 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 11 Mar 2013 17:18:49 -0700 Subject: [PATCH 1/2] add trailing new line to mixer output --- mixer/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mixer/src/main.cpp b/mixer/src/main.cpp index 3196cded08..155f63f9e0 100644 --- a/mixer/src/main.cpp +++ b/mixer/src/main.cpp @@ -66,7 +66,7 @@ void *sendBuffer(void *args) while (true) { sentBytes = 0; - printf("Last send was %f us ago", usecTimestampNow() - usecTimestamp(&lastSend)); + printf("Last send was %f ms ago\n", (usecTimestampNow() - usecTimestamp(&lastSend)) / 1000); gettimeofday(&lastSend, NULL); for (int i = 0; i < agentList.getAgents().size(); i++) { From 4be337d34bc6b4d6797fd8f20d41f910fb86c5e1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 11 Mar 2013 17:27:27 -0700 Subject: [PATCH 2/2] only hold the threshold number of frames for audio output --- interface/src/Audio.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 40c9faac7f..60f28ca5df 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -193,6 +193,21 @@ int audioCallback (const void *inputBuffer, } // play whatever we have in the audio buffer + // check if we have more than we need to play out + int thresholdFrames = ceilf((PACKET_LENGTH_SAMPLES + JITTER_BUFFER_SAMPLES) / (float)PACKET_LENGTH_SAMPLES); + int thresholdSamples = thresholdFrames * PACKET_LENGTH_SAMPLES; + + if (ringBuffer->diffLastWriteNextOutput() > thresholdSamples) { + // we need to push the next output forwards + int samplesToPush = ringBuffer->diffLastWriteNextOutput() - thresholdSamples; + + if (ringBuffer->getNextOutput() + samplesToPush > ringBuffer->getBuffer()) { + ringBuffer->setNextOutput(ringBuffer->getBuffer() + (samplesToPush - (ringBuffer->getBuffer() + RING_BUFFER_SAMPLES - ringBuffer->getNextOutput()))); + } else { + ringBuffer->setNextOutput(ringBuffer->getNextOutput() + samplesToPush); + } + } + memcpy(outputLeft, ringBuffer->getNextOutput(), PACKET_LENGTH_BYTES_PER_CHANNEL); memcpy(outputRight, ringBuffer->getNextOutput() + PACKET_LENGTH_SAMPLES_PER_CHANNEL, PACKET_LENGTH_BYTES_PER_CHANNEL);