mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 20:13:40 +02:00
cleanup writing of silent frame to ring buffer
This commit is contained in:
parent
b6a41eeaaa
commit
7ed982a073
1 changed files with 12 additions and 10 deletions
|
@ -157,16 +157,18 @@ unsigned int AudioRingBuffer::samplesAvailable() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioRingBuffer::addSilentFrame(int numSilentSamples) {
|
void AudioRingBuffer::addSilentFrame(int numSilentSamples) {
|
||||||
// setup the silent frame
|
// memset zeroes into the buffer, accomodate a wrap around the end
|
||||||
int numSilentBytes = numSilentSamples * sizeof(int16_t);
|
// push the _endOfLastWrite to the correct spot
|
||||||
char* silentFrame = new char[numSilentBytes];
|
if (_endOfLastWrite + numSilentSamples <= _buffer + _sampleCapacity) {
|
||||||
memset(silentFrame, 0, numSilentBytes);
|
memset(_endOfLastWrite, 0, numSilentSamples * sizeof(int16_t));
|
||||||
|
_endOfLastWrite += numSilentSamples;
|
||||||
// write it
|
} else {
|
||||||
writeData(silentFrame, numSilentBytes);
|
int numSamplesToEnd = (_buffer + _sampleCapacity) - _endOfLastWrite;
|
||||||
|
memset(_endOfLastWrite, 0, numSilentSamples * sizeof(int16_t));
|
||||||
// delete the temporary silent frame
|
memset(_buffer, 0, (numSilentSamples - numSamplesToEnd) * sizeof(int16_t));
|
||||||
delete[] silentFrame;
|
|
||||||
|
_endOfLastWrite = _buffer + (numSilentSamples - numSamplesToEnd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AudioRingBuffer::isNotStarvedOrHasMinimumSamples(unsigned int numRequiredSamples) const {
|
bool AudioRingBuffer::isNotStarvedOrHasMinimumSamples(unsigned int numRequiredSamples) const {
|
||||||
|
|
Loading…
Reference in a new issue