mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
only hold the threshold number of frames for audio output
This commit is contained in:
parent
eaf27a942e
commit
4be337d34b
1 changed files with 15 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue