Some updates to TPCircularBuffer

I’ve recently made some updates to TPCircularBuffer (on GitHub), my C circular/ring buffer implementation, which add a memory barrier on read and write, inline the main functions for a potential performance boost, and add support for use within C++ projects.

If you’re using TPCircularBuffer at all, I recommend updating!

, , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.


  1. Jean-François Brouil
    Posted February 14, 2012 at 11:08 pm | Permalink

    You might want to consider using NS_INLINE rather than static inline'. My experience is that the former, probably due to the "always_inline" attribute *does* inline my C++ header code, whereas barestatic inline’ doesn’t:

        #define NS_INLINE static inline attribute((always_inline))

    • Posted February 15, 2012 at 8:29 am | Permalink

      Ah, thanks very much for the suggestion, Jean-François! I’ll try it out.

  2. Shahzeb
    Posted March 14, 2012 at 4:03 pm | Permalink

    Hi Michael,

    Thanks for this wonderful implementation.

    I have seen TPCircularBuffer working absolutely fine in AudioGraph’s sample project, but when I add the .h and .c files of TPCircularBuffer to my project, and import the .h file in my, it gives me the ‘Apple Mach-o-linker error’ saying :

    Undefined symbols for architecture armv7: “__Z20TPCircularBufferInitP22TPCircularBufferRecordi”, referenced from: -[RealtimeAudioController initDelayBuffer] in RealtimeAudioController.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

    I have checked and all the required frameworks are added. No idea why that’s happening.

    Any help in this regard will be highly appreciated.


    • Shahzeb
      Posted March 14, 2012 at 4:17 pm | Permalink

      In case somebody else is having the same problem as me, here is the solution that worked for me,

      When you import the header, instead of writing, import TPCircularBuffer.h

      Just write the following, extern “C” { include “TPCircularBuffer.h” };

  3. Posted February 8, 2013 at 1:55 am | Permalink

    Thanks a lot for sharing the circular buffer implementation; easy to use, and fast.

    For the benefit of those who want to use the circular buffer for playing large audio files while processing PCM samples, I created a sample application:

    • Posted February 8, 2013 at 2:54 am | Permalink

      My pleasure Chamin!

      One thing you should know: You should never (ever) allocate or free memory, or perform Objective-C calls from within the Remote IO callback (or the Core Audio thread, generally). The result will be occasional (maybe even frequent) horrible audio glitches.

      Here’s a decent article on this:

    • Posted February 8, 2013 at 2:55 am | Permalink

      Incidentally, also check out the AudioBufferList stuff from TPCircularBuffer – that’s designed to make a lot of this stuff easier, and you might find yourself saving quite a few lines of code.

      • Posted February 8, 2013 at 4:56 am | Permalink

        Thanks a lot! will check both and refine the code, too.