From 764ea3fd2189d73fe41bd0ad4c16490581c1f3b8 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 4 Feb 2013 18:46:24 -0800 Subject: [PATCH] make diffLastWriteNextOutput check for NULL endOfLastWrite --- Source/Audio.cpp | 10 ++-------- Source/AudioRingBuffer.cpp | 16 ++++++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Source/Audio.cpp b/Source/Audio.cpp index 86d153d6fd..374a2d4cb8 100644 --- a/Source/Audio.cpp +++ b/Source/Audio.cpp @@ -418,20 +418,14 @@ void Audio::render(int screenWidth, int screenHeight) } glEnd(); - // show the next audio buffer and end of last write position - int scaleLength = currentX - startX; - - float nextOutputSampleOffset = data->ringBuffer->nextOutput - data->ringBuffer->buffer; - + // show the next audio buffer and end of last write position float remainingBuffer = 0; timeval currentTime; gettimeofday(¤tTime, NULL); float timeLeftInCurrentBuffer = diffclock(currentTime, data->lastCallback)/(1000.0*(float)BUFFER_LENGTH_SAMPLES/(float)SAMPLE_RATE) * frameWidth; //float timeLeftInCurrentBuffer = diffclock(currentTime, data->lastCallback)/23.22 * frameWidth; - if (data->ringBuffer->endOfLastWrite != NULL) { - remainingBuffer = (data->ringBuffer->diffLastWriteNextOutput())/BUFFER_LENGTH_SAMPLES*frameWidth; - } + remainingBuffer = data->ringBuffer->diffLastWriteNextOutput() / BUFFER_LENGTH_SAMPLES * frameWidth; glColor3f(1, 0, 0); glBegin(GL_QUADS); diff --git a/Source/AudioRingBuffer.cpp b/Source/AudioRingBuffer.cpp index 215d2c5ad5..3a34ef7454 100644 --- a/Source/AudioRingBuffer.cpp +++ b/Source/AudioRingBuffer.cpp @@ -23,13 +23,17 @@ AudioRingBuffer::~AudioRingBuffer() { short AudioRingBuffer::diffLastWriteNextOutput() { - short sampleDifference = endOfLastWrite - nextOutput; - - if (sampleDifference < 0) { - sampleDifference += ringBufferLengthSamples; + if (endOfLastWrite == NULL) { + return 0; + } else { + short sampleDifference = endOfLastWrite - nextOutput; + + if (sampleDifference < 0) { + sampleDifference += ringBufferLengthSamples; + } + + return sampleDifference; } - - return sampleDifference; } short AudioRingBuffer::bufferOverlap(int16_t *pointer, short addedDistance)