mirror of
https://github.com/overte-org/overte.git
synced 2025-04-24 03:33:35 +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) {
|
||||
// setup the silent frame
|
||||
int numSilentBytes = numSilentSamples * sizeof(int16_t);
|
||||
char* silentFrame = new char[numSilentBytes];
|
||||
memset(silentFrame, 0, numSilentBytes);
|
||||
|
||||
// write it
|
||||
writeData(silentFrame, numSilentBytes);
|
||||
|
||||
// delete the temporary silent frame
|
||||
delete[] silentFrame;
|
||||
// memset zeroes into the buffer, accomodate a wrap around the end
|
||||
// push the _endOfLastWrite to the correct spot
|
||||
if (_endOfLastWrite + numSilentSamples <= _buffer + _sampleCapacity) {
|
||||
memset(_endOfLastWrite, 0, numSilentSamples * sizeof(int16_t));
|
||||
_endOfLastWrite += numSilentSamples;
|
||||
} else {
|
||||
int numSamplesToEnd = (_buffer + _sampleCapacity) - _endOfLastWrite;
|
||||
memset(_endOfLastWrite, 0, numSilentSamples * sizeof(int16_t));
|
||||
memset(_buffer, 0, (numSilentSamples - numSamplesToEnd) * sizeof(int16_t));
|
||||
|
||||
_endOfLastWrite = _buffer + (numSilentSamples - numSamplesToEnd);
|
||||
}
|
||||
}
|
||||
|
||||
bool AudioRingBuffer::isNotStarvedOrHasMinimumSamples(unsigned int numRequiredSamples) const {
|
||||
|
|
Loading…
Reference in a new issue