Problems with Sounds
by Damir Slogar · in iTorque 2D · 03/23/2009 (12:34 pm) · 3 replies
I'm having some problems playing sounds.
1) Sometimes there is a loud clicking sound after playing a sound. I read a post that this is due to using a certain version of the OpenAL lib. Will the next release of iTGB address this?
2) If I try to play a sound with increasing pitch in a loop like this:
it will become cut off and eventually sounds will stop working until a new level is loaded. Using the instruments in xcode shows that there is a memory leak happening. Anybody have any idea whats going on?
3) $soundHandle = alxCreateSource( MyAudioProfile ); seems like it should create a handle that can be reused by passing it into alxPlay... The handle gets created but it seems that using it in alxPlay always fails. I think its because alxUpdate clears all the handles every tick if they are not playing. Is this the intended behavior?
1) Sometimes there is a loud clicking sound after playing a sound. I read a post that this is due to using a certain version of the OpenAL lib. Will the next release of iTGB address this?
2) If I try to play a sound with increasing pitch in a loop like this:
...
%pitch = 1.0;
for ( %i = 0;%i < 10; %i++ )
{
schedule( 100 * %i, 0, playSoundEffect, PopSound, %pitch );
%pitch += 0.1;
}
...
function playSoundEffect( %sound, %pitch )
{
%se = alxPlay(%sound);
alxSourcef( %se, "AL_PITCH", %pitch );
}it will become cut off and eventually sounds will stop working until a new level is loaded. Using the instruments in xcode shows that there is a memory leak happening. Anybody have any idea whats going on?
3) $soundHandle = alxCreateSource( MyAudioProfile ); seems like it should create a handle that can be reused by passing it into alxPlay... The handle gets created but it seems that using it in alxPlay always fails. I think its because alxUpdate clears all the handles every tick if they are not playing. Is this the intended behavior?
#3
If I try to save the handle as you suggest, like from the return value from alxPlay or alxCreateSource, that handle is only valid while the sound is playing (my third issue above).
I think I'm going to try checking to see if the sound is playing with alxIsPlaying before trying to play it again.
Does anyone know how many simultaneous sounds the iPhone can handle? It seems like its set up for 16 in the engine @ 44100 output rate...maybe this is set to high.
03/25/2009 (5:30 am)
Mat, the sound that I am trying to play is very short, so sometimes it is still playing but other times it is not. Since I'm trying to play the sound in rapid succession with increasing pitch, it seems that there is a race condition happening. Like you said, the handle doesn't get cleared until after the sound is done playing; this is not how OpenAL handles things - it's how torque is handling OpenAL.If I try to save the handle as you suggest, like from the return value from alxPlay or alxCreateSource, that handle is only valid while the sound is playing (my third issue above).
I think I'm going to try checking to see if the sound is playing with alxIsPlaying before trying to play it again.
Does anyone know how many simultaneous sounds the iPhone can handle? It seems like its set up for 16 in the engine @ 44100 output rate...maybe this is set to high.
Torque 3D Owner Mat Valadez
Default Studio Name
function playSoundEffect( %sound, %pitch ) { %se = alxPlay(%sound); alxSourcef( %se, "AL_PITCH", %pitch ); }In this case, you are playing a new sound every time you call this, and %se is the newly created sound. So each iteration is louder, but the old one is still playing, that could be you leak.
If you want to play a single single sound, and update the volume, you'll want to play the sound once, save the handle, and update the handle with the new sound each time (as opposed to creating a new,louder sound each time).