Re: TPCircularBuffer Usage
Re: TPCircularBuffer Usage
- Subject: Re: TPCircularBuffer Usage
- From: Daniel Vollmer <email@hidden>
- Date: Sat, 17 Nov 2012 11:13:24 +0100
Hi,
On 17 Nov 2012, at 06:03, Pier <email@hidden> wrote:
> I'm using Michael Tyson's famous TCCircularBuffer from this page.
> http://atastypixel.com/blog/a-simple-fast-circular-buffer-implementation-for-audio-processing/
I'm not sure how strict people are about on-topic-ness here, but your question seems to have little direct relevance to coreaudio-api.
> I'm trying to use it in a way where I keep the pointer to the start of my audio data.
>
> SInt16 *buffer = TPCircularBufferTail(&THIS->buffer, &availableBytes);
> memcpy(targetBuffer, buffer, MIN(bytesToCopy, availableBytes)); // targetBuffer is playback buffer
> TPCircularBufferConsume(&THIS->buffer, sampleCount);
>
> The first time I go into the above code, I keep a copy of *buffer and name it *startPtr, so that I can use it in my audio code for playback manually. I know that the data has been "consumed" by TPCircularBufferConsume, but it seems to be still there.
Well, that's kind of how a ring-buffer works. After you consume the data, any use of the original is breaking the API contract of TPCircularBuffer. While the data might still be there for a bit, it'll be overwritten by fresh writes into the buffer eventually.
> Why is this so, and am I making a terrible mistake by doing the above?
I assume the pointer you kept around got overwritten by silence (because you told TPCircularBuffer that you had done everything you wanted with it by calling Consume). If you want to keep the original data around, you cannot call Consume. Nothing stops you from increasing your playback-pointer without actually consuming (as long as you still have valid data in the buffer and don't overtake your write-pointer).
You will have to think how much audio you want to keep around, and what happens when you get more than you can handle.
HTH,
Daniel.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden