[hpsdr] Ring buffers for double buffering sound samples.

L. Van Warren van at wdv.com
Mon Apr 14 20:38:48 PDT 2008


I don't know if the following is relevant, but I'll mention it just in case.

One solution is double buffering arrays of samples. A new buffer is filled,
and swapped with the old buffer. This can be implemented with a circular
ring buffer that uses a pair of running pointers to fill and play, or fill
and send. The ring buffer is larger than the worst case latency times the
frame size. There is code around to do this. The mod '%' function is used to
wrap around. In 'C' slang it looks something like this:

outBuffer[i%BUFSIZE] = *outGoingSample++; // buffer just wraps around

The "filler" keeps adding samples to the end of the buffer and uses one
pointer.

The "drainer" plays or sends samples and advances the currency pointer as it
does so. 

So its like filling and draining the kitchen sink. You have some slop to
work with and the size of the sink is dictated by the drain rate relative to
the fill rate. But if latency and throughput are bounded, one can guarantee
that the sink will never empty or overflow. Latency is the time required for
the first sample (or buffer) to be processed. Throughput is the time
required to process subsequent samples (or buffers) after the first.
 
I also discuss buffer matching page 37 of my online DSP book, in the chapter
on Filter Windows. One can use Hamming or Kaiser filter windows to join the
seams of consecutive buffers to minimize end mismatch. These introduce their
own bit of envelope distortion, which I find annoying.  
  

L. Van Warren MS CS, AE
web          wdv.com
FCC AE License AE5CC
 
"Slow is Fast and Fast is Slow"





More information about the Hpsdr mailing list