41 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
42 #include <CoreAudio/CoreAudioTypes.h>
44 #include <CoreAudioTypes.h>
48 #ifndef CARingBuffer_Header
49 #define CARingBuffer_Header
52 kCARingBufferError_WayBehind = -2,
53 kCARingBufferError_SlightlyBehind = -1,
54 kCARingBufferError_OK = 0,
55 kCARingBufferError_SlightlyAhead = 1,
56 kCARingBufferError_WayAhead = 2,
57 kCARingBufferError_TooMuch = 3,
58 kCARingBufferError_CPUOverload = 4
61 typedef SInt32 CARingBufferError;
63 const UInt32 kGeneralRingTimeBoundsQueueSize = 32;
64 const UInt32 kGeneralRingTimeBoundsQueueMask = kGeneralRingTimeBoundsQueueSize - 1;
68 typedef SInt64 SampleTime;
73 void Allocate(
int nChannels, UInt32 bytesPerFrame, UInt32 capacityFrames);
77 CARingBufferError Store(
const AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber);
87 CARingBufferError Fetch(AudioBufferList *abl, UInt32 nFrames, SampleTime frameNumber,
bool aheadOK);
90 CARingBufferError GetTimeBounds(SampleTime &startTime, SampleTime &endTime);
94 int FrameOffset(SampleTime frameNumber) {
return (frameNumber % mCapacityFrames) * mBytesPerFrame; }
96 CARingBufferError CheckTimeBounds(SampleTime& startRead, SampleTime& endRead);
99 SampleTime StartTime()
const {
return mTimeBoundsQueue[mTimeBoundsQueuePtr & kGeneralRingTimeBoundsQueueMask].mStartTime; }
100 SampleTime EndTime()
const {
return mTimeBoundsQueue[mTimeBoundsQueuePtr & kGeneralRingTimeBoundsQueueMask].mEndTime; }
101 void SetTimeBounds(SampleTime startTime, SampleTime endTime);
106 UInt32 mBytesPerFrame;
107 UInt32 mCapacityFrames;
109 UInt32 mCapacityBytes;
113 volatile SampleTime mStartTime;
114 volatile SampleTime mEndTime;
115 volatile UInt32 mUpdateCounter;
118 CARingBuffer::TimeBounds mTimeBoundsQueue[kGeneralRingTimeBoundsQueueSize];
119 UInt32 mTimeBoundsQueuePtr;