Re: Audio stuttering under CPU load
Re: Audio stuttering under CPU load
- Subject: Re: Audio stuttering under CPU load
- From: "Paul Sanders" <email@hidden>
- Date: Wed, 10 Feb 2010 19:49:07 -0000
Bertrand, Pierre-Luc wrote:
> Now I only lock to signal the processing thread to start
> processing a
> chunk of 800ms.
Well, I can't really comment on your code because I can't see
it, but the way I play audio is this (and it doesn't stutter):
1. In the processing thread - i.e. the thread preparing the
audio to be streamed - I fill buffers and put them on a queue.
When the queue reaches a certain length, I stall.
2. In the IOProc, I pull buffers from the queue until I have
filled the output buffer passed to me by CoreAudio. Then I
return, remembering the fact that I am part-way through an input
buffer. Each time I consume an input buffer, I signal the
processing thread (I use my own, posix-based primitives for
this, but I'm sure there are other ways).
3. *Absolutely* no mallocs in the IOProc. This includes
instantiating any Cocoa objects (obviously) and, I imagine,
calling NSLog. I found with even one malloc in there, I got the
occasional hiccup.
You can do quite a lot of processing in an IOProc. I resample
the audio, which is quite heavyweight. The key is to be
deterministic about it (i.e. never exceeed a certain amount of
time, per buffer-full), and resampling fits that constraint.
HTH - Paul Sanders.
_______________________________________________
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