make diffLastWriteNextOutput check for NULL endOfLastWrite

This commit is contained in:
Stephen Birarda 2013-02-04 18:46:24 -08:00
parent 18c057ef5e
commit 764ea3fd21
2 changed files with 12 additions and 14 deletions

View file

@ -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(&currentTime, 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);

View file

@ -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)