I’ve recently made some updates to [TPCircularBuffer](http://atastypixel.com/circular-ring-buffer-plus-neat-virtual-memory-mapping-trick/) ([on GitHub](https://github.com/michaeltyson/TPCircularBuffer)), 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!
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 bare
static inline’ doesn’t:Ah, thanks very much for the suggestion, Jean-François! I’ll try it out.
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 RealTimeAudioController.mm, 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.
Thanks.
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” };
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:
https://github.com/iitotoro/BufferedAudioPlayer.git
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: http://www.rossbencina.com/code/real-time-audio-programming-101-time-waits-for-nothing
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.
Thanks a lot! will check both and refine the code, too.