You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RingBuffer.Resample on a part-filled buffer stretches the samples across the whole new length, inventing data and marking the buffer full #98
It maps oldCount (the number of valid elements) onto length (the new capacity). The XML docs describe resampling as old length → new length, for example when the sample rate changes. When the buffer isn't full, the few real samples get stretched to fill every slot, and the buffer comes back full.
Reproduction
Confirmed with a scratch console app against the net10.0 build:
Setup
Call
Result
new RingBuffer<int>(10), push 1, 2
Resample(10) (same length)
Count = 10, [1,1,1,1,1,2,2,2,2,2]
capacity 1000, push 10 samples
Resample(2000)
Count = 2000
capacity 4, push 7
Resample(4)
[7,7,7,7]
Why it matters
A history or metering buffer that is only partly filled at the moment of a rate change gets padded with duplicated samples and reports itself as full. Any consumer that reads Count or iterates then works on data that never existed.
Resample(Length) should be a no-op, but it changes both the contents and Count.
The existing RingBufferTests only resample full or empty buffers, so none of them catch this.
Suggested fix / acceptance criteria
Scale the element count by the length ratio, newCount = clamp(round(oldCount * (double)length / oldLength), 1, length), and interpolate oldCount samples onto newCount slots instead of onto length.
New tests:
Resample(Length) on a part-filled buffer leaves Count and the contents unchanged.
A capacity-1000 buffer holding 10 samples, resampled to 2000, gives Count == 20.
Behaviour for full and empty buffers is unchanged.
Activity
matt-edmondson commentedon Oct 5, 2026
Triage
Count, but only on theResamplepathRingBuffer<T>.ResampleOverflowExceptionfor sizes above 2^30, and a failedRingBuffer.Resizecorrupts the buffer #89 (size overflow) touch the same method and should be coordinated or fixed in one PRNext step: scale the element count by the length ratio, interpolate only the valid samples, and add tests for part-filled buffers.
Generated by Claude Code