Reusing an audio queue
My problem is simple but the solution is elusive.
I am using the iPhone SDK Core Audio Services to play a real-time audio stream (e.g. internet radio station) based on the SpeakHere example.
My code works just fine the first time around, but when I change streams or restart the stream without stoping and reloading the app the audio queue has extra noise in it (jitter, skips, etc).
I've tried many things like:
1. AudioQueuePrime before playing new buffers.
2. AudioQueueFlush with and without waiting for buffer to finish before AudioQueueStop (with immediate set to yes and no) and AudioQueueDispose.
3. AudioQueueReset along with and without 1 and 2 above.
4. I've freed the audio queue and built a new one for each stream change
5. I've lowered and raised the gain before playing a new stream.
6. I've put sleeps and NSThread..sleeps to see if the audio queue needed time to reset between streams.
7. I've checked that all my variables are reinitialized, zeroized, etc.
8. Many combinations of 1 thru 7.
But none of these things worked.
The only thing that seems to work is if I set the audio queue buffers to larger than necessary values (like using a 128kbps buffer for a 64kbps stream), but this seems inefficient and causes a longer delay for the music to start.
I see lots of posts for this problem and no good solutions.
Anyone?
|