From efe05adcae892ecb4ce33ba1bd045a9cd4e0f911 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 16 Dec 2013 16:52:04 -0800 Subject: [PATCH] fix audio graphs for new audio infrastructure --- interface/src/Audio.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index d898bd8566..95b1a4fbd9 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -509,14 +509,15 @@ void Audio::render(int screenWidth, int screenHeight) { } glEnd(); - // Show a bar with the amount of audio remaining in ring buffer beyond current playback - float remainingBuffer = 0; + // show a bar with the amount of audio remaining in ring buffer and output device + // beyond the current playback int bytesLeftInAudioOutput = _audioOutput->bufferSize() - _audioOutput->bytesFree(); - float secondsLeftForAudioOutput = (bytesLeftInAudioOutput / sizeof(int16_t)) / _outputFormat.sampleRate(); - float timeLeftInCurrentBuffer = AUDIO_CALLBACK_MSECS - (secondsLeftForAudioOutput * 1000); - - remainingBuffer = 1 / AUDIO_CALLBACK_MSECS; + float secondsLeftForAudioOutput = (bytesLeftInAudioOutput / sizeof(int16_t)) + / ((float) _outputFormat.sampleRate() * _outputFormat.channelCount()); + float secondsLeftForRingBuffer = _ringBuffer.samplesAvailable() + / ((float) _desiredOutputFormat.sampleRate() * _desiredOutputFormat.channelCount()); + float msLeftForAudioOutput = (secondsLeftForAudioOutput + secondsLeftForRingBuffer) * 1000; if (_numFramesDisplayStarve == 0) { glColor3f(0, 1, 0); @@ -525,19 +526,19 @@ void Audio::render(int screenWidth, int screenHeight) { _numFramesDisplayStarve--; } + if (_averagedLatency == 0.0) { + _averagedLatency = msLeftForAudioOutput; + } else { + _averagedLatency = 0.99f * _averagedLatency + 0.01f * (msLeftForAudioOutput); + } + glBegin(GL_QUADS); glVertex2f(startX, topY + 2); - glVertex2f(startX + (remainingBuffer + timeLeftInCurrentBuffer) / AUDIO_CALLBACK_MSECS * frameWidth, topY + 2); - glVertex2f(startX + (remainingBuffer + timeLeftInCurrentBuffer) / AUDIO_CALLBACK_MSECS * frameWidth, bottomY - 2); + glVertex2f(startX + _averagedLatency / AUDIO_CALLBACK_MSECS * frameWidth, topY + 2); + glVertex2f(startX + _averagedLatency / AUDIO_CALLBACK_MSECS * frameWidth, bottomY - 2); glVertex2f(startX, bottomY - 2); glEnd(); - if (_averagedLatency == 0.0) { - _averagedLatency = remainingBuffer + timeLeftInCurrentBuffer; - } else { - _averagedLatency = 0.99f * _averagedLatency + 0.01f * (remainingBuffer + timeLeftInCurrentBuffer); - } - // Show a yellow bar with the averaged msecs latency you are hearing (from time of packet receipt) glColor3f(1,1,0); glBegin(GL_QUADS);