Skip to content

Instantly share code, notes, and snippets.

@ddribin
Created November 16, 2009 16:35
Show Gist options
  • Save ddribin/236116 to your computer and use it in GitHub Desktop.
Save ddribin/236116 to your computer and use it in GitHub Desktop.
class CARingBuffer {
public:
typedef SInt64 SampleTime;
CARingBuffer();
~CARingBuffer();
void Allocate(int nChannels, UInt32 bytesPerFrame, UInt32 capacityFrames);
// capacityFrames will be rounded up to a power of 2
void Deallocate();
CARingBufferError Store(const AudioBufferList *abl, UInt32 nFrames, SampleTime c);
// Copy nFrames of data into the ring buffer at the specified sample time.
// The sample time should normally increase sequentially, though gaps
// are filled with zeroes. A sufficiently large gap effectively empties
// the buffer before storing the new data.
// If frameNumber is less than the previous frame number, the behavior is undefined.
// Return false for failure (buffer not large enough).
CARingBufferError Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber);
// will alter mNumDataBytes of the buffers
CARingBufferError GetTimeBounds(SampleTime &startTime, SampleTime &endTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment