[hpsdr] Ring buffers for double buffering sound samples.

Bob McGwier rwmcgwier at gmail.com
Tue Apr 22 14:26:16 PDT 2008


DttSP

http://dttsp.org/

and PowerSDR

http://www.flex-radio.com

and

uwSDR

http://uwsdr.berlios.de/

(the latter two based on DttSP v 1.0)

have  always used ring buffers.  The ring buffer code in DttSP v 1.0 is 
five years old.

We do not use the % operator.  We limit ourselves to 2^ roof[log_2 
(latency) + 1)] and use mask instead of modulo.

Bob


L. Van Warren wrote:
> ***** High Performance Software Defined Radio Discussion List *****
>
> 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"
>
>
> _______________________________________________
> HPSDR Discussion List
> To post msg: hpsdr at hpsdr.org
> Subscription help: http://lists.hpsdr.org/listinfo.cgi/hpsdr-hpsdr.org
> HPSDR web page: http://hpsdr.org
> Archives: http://lists.hpsdr.org/pipermail/hpsdr-hpsdr.org/
>
>   


-- 
AMSAT Director and VP Engineering. Member: ARRL, AMSAT-DL,
TAPR, Packrats, NJQRP, QRP ARCI, QCWA, FRC. ARRL SDR WG Chair
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it." - Brian W. Kernighan 


 1208899576.0


More information about the Hpsdr mailing list