mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-21 06:01:13 +02:00
Fewer calls to RingBuffer::Put in case of trailing zeroes...
... so there is only one update per track of the atomics in RingBuffer in each pass of the loop in FillBuffers, which will be needed to synchronize RingBuffer and TimeQueue correctly.
This commit is contained in:
@@ -69,16 +69,18 @@ size_t RingBuffer::AvailForPut()
|
||||
}
|
||||
|
||||
size_t RingBuffer::Put(samplePtr buffer, sampleFormat format,
|
||||
size_t samplesToCopy)
|
||||
size_t samplesToCopy, size_t padding)
|
||||
{
|
||||
auto start = mStart.load( std::memory_order_acquire );
|
||||
auto end = mEnd.load( std::memory_order_relaxed );
|
||||
samplesToCopy = std::min( samplesToCopy, Free( start, end ) );
|
||||
const auto free = Free( start, end );
|
||||
samplesToCopy = std::min( samplesToCopy, free );
|
||||
padding = std::min( padding, free - samplesToCopy );
|
||||
auto src = buffer;
|
||||
size_t copied = 0;
|
||||
auto pos = end;
|
||||
|
||||
while(samplesToCopy) {
|
||||
while ( samplesToCopy ) {
|
||||
auto block = std::min( samplesToCopy, mBufferSize - pos );
|
||||
|
||||
CopySamples(src, format,
|
||||
@@ -91,6 +93,14 @@ size_t RingBuffer::Put(samplePtr buffer, sampleFormat format,
|
||||
copied += block;
|
||||
}
|
||||
|
||||
while ( padding ) {
|
||||
const auto block = std::min( padding, mBufferSize - pos );
|
||||
ClearSamples( mBuffer.ptr(), mFormat, pos, block );
|
||||
pos = (pos + block) % mBufferSize;
|
||||
padding -= block;
|
||||
copied += block;
|
||||
}
|
||||
|
||||
// Atomically update the end pointer with release, so the nonatomic writes
|
||||
// just done to the buffer don't get reordered after
|
||||
mEnd.store(pos, std::memory_order_release);
|
||||
|
Reference in New Issue
Block a user