Circular (ring) buffer plus neat virtual memory mapping trick
I’ve just updated my [C circular buffer implementation](http://atastypixel.com/a-simple-fast-circular-buffer-implementation-for-audio-processing/), adopting the trick originally proposed by [Philip Howard](http://vrb.slashusr.org/) and [adapted to Darwin](http://www.snoize.com/Code/PlayBufferedSoundFile.tar.gz) by [Kurt Revis](http://www.snoize.com): A virtual copy of the buffer is inserted directly after the end of the buffer, so that you can write past the end of the buffer, but have your writes automatically wrapped around to the start — no need to manually implement buffer wrapping logic.
This dramatically simplifies the use of a circular buffer — you can use chunks of the buffer without any need to worry about where the wrap point is.
See the new implementation, which is thread-safe with one consumer and one producer, with no need for locks, making it perfect for use with high-priority Core Audio threads, on [GitHub: TPCircularBuffer](https://github.com/michaeltyson/TPCircularBuffer).
There’s a basic example of its use over on the [original post](http://atastypixel.com/a-simple-fast-circular-buffer-implementation-for-audio-processing/).
Read More