Settng and restarting an audio queue
Settng and restarting an audio queue
- Subject: Settng and restarting an audio queue
- From: Nitzan Wilnai <email@hidden>
- Date: Sun, 28 Sep 2008 17:42:00 -0700 (PDT)
Not sure if this is the right place to ask this, but I need help with audio programming on the iPhone.
My iPhone game has several levels and I want to play a looping audio stream for each level. When the user progresses from one level to the next, I want to stop the current music track and start a new music track instead. I am using SoundEngine.cpp from the CrashLanding example.
In QueueCallback() in SoundEngine.cpp I changed
UInt32 theNextFileIndex = (THIS->mCurrentFileIndex < THIS->mBGFileInfo.size()-1) ? THIS->mCurrentFileIndex+1 : 0;
to:
UInt32 theNextFileIndex = THIS->mNewTrackIndex;
I manually set mNewTrackIndex when a level changes.
This seems to work except for 2 problems:
1. The track changes only when the previous track has finished playing.
2. Sometimes when changing tracks the upper left part of the screen is
corrupted for a split second, as if something stomped the video buffer.
Now my questions are:
1. Is my solution to looping and changing the audio track in
QueueCallback correct? What could be causing the video memory
corruption on track change?
2. Instead of waiting for the previous track to finish, how do I change the music track at will? I tried the following:
AudioQueueDispose ( mQueue, true );
mCurrentTrackIndex = currentTrackIndex;
SetupQueue( CurFileInfo );
SetupBuffers( CurFileInfo );
AudioQueueStart( mQueue, NULL );
Which seems to work. It stops the current audio queue and creates a new one, calling QueueCallback in the process which selects a new audio track using my mNewTrackIndex vaiable. Unfortunately if I call it over and over again a few times by the 7th time the audio is corrupted and by the 8th time no audio
plays anymore. So obviously some memory is getting
leaked/stomped/corrupted.
I also tried calling AudioQueueReset and AudioQueueFlush instead
of AudioQueueDispose but that did not help either.
Thanks.
Nitzan Wilnai
_______________________________________________
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