Re: Settng and restarting an audio queue
Re: Settng and restarting an audio queue
- Subject: Re: Settng and restarting an audio queue
- From: William Stewart <email@hidden>
- Date: Mon, 29 Sep 2008 12:31:35 -0700
We cannot answer questions that are specific to iPhone development.
Neither can you ask specific questions related to iPhone development
on a public list.
We can only discuss APIs that are available on Mac OS X on this list.
On Sep 28, 2008, at 5:42 PM, Nitzan Wilnai wrote:
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
_______________________________________________
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