Looping audio issues
by Chris \"Hobbiticus\" Weiland · in Torque Game Engine · 10/10/2002 (11:04 am) · 3 replies
I can't figure this one for the life of me. It's in player.cc in the updateMove function. Here's the code: (excuse the debug stuff)
if (!mJetting && mState != RecoverState && mDamageState == Enabled && move->trigger[3] && (mEnergy - 1) >= mDataBlock->minJetEnergy)
{
Con::printf("--------New Jet--------");
Con::printf("+You started jetting");
if(!alxIsPlaying(mJetStartSound)) {
Con::printf("+I started the jet start sound");
mJetStartSound = alxPlay(mDataBlock->sound[PlayerData::JetStartSnd], &getTransform());
alxSourceMatrixF(mJetStartSound, &getTransform());
}
}
bool mIsJetting = mJetting;
//Are we actually jetting?
mJetting = (mState != RecoverState && mDamageState == Enabled && move->trigger[3] && mEnergy > mDataBlock->minJetEnergy);
//If we're not jetting and the the jet sound happens to be playing, stop it
if (mJetting) {
...
//Play the jet sound
if (!alxIsPlaying(mJetSound))
{
mJetSound = alxPlay(mDataBlock->sound[PlayerData::JetSnd], &getTransform());
Con::printf("+++++++%i Started the LOOPING jet sound: %i", mId, mJetSound);
if (!alxIsValidHandle(mJetSound))
{
alxStop(mJetSound);
Con::printf("INVALID HANDLE! I TRIED TO STOP IT!"); //I know this doesn't make sense, but o well
}
}
alxSourceMatrixF(mJetSound, &getTransform());
}
else {
if (alxIsPlaying(mJetSound))
{
alxStop(mJetSound);
Con::printf("!!!!!!!%i STOPPED looping jet sound: %i", mId, mJetSound);
//mJetSound = NULL_AUDIOHANDLE;
}
if (alxIsPlaying(mJetStartSound))
{
alxStop(mJetStartSound);
Con::printf("--Stopped jet start sound");
//mJetStartSound = NULL_AUDIOHANDLE;
}
if (mIsJetting)
Con::printf("--------End Jet--------");
}
Ok, here's what's going on. And, it only happens in MULTIPLAYER ONLY, and when there is a certain combination of at least 2 people jetting. I can't figure out what the combination is either :( And, it works MOST of the time, but sometimes, it starts the jet sound in massive quantities when the other guy jets (the guy that started the jet doesn't get it).
The problem is that it starts up multiple looping jet sounds that NEVER STOP. Best of all, they start with an invalid audio handle. So, it starts the jet sound, get's a null audio handle back, so the next time it checks to see if it's playing, it doens't think it's playing since the alxIsPlaying function will return false if it gets passed a null audio handle. So, it starts up another, and another, and another...as long as the other guy jets.
I could half-get around this problem by creating another bool variable that gets set right after the sound starts playing, but without a valid audiohandle, you still can't stop it. Plus, that's just more memory.
The only thing that I can think of is that the audio function for starting sounds is bugged. Any an all suggestions would be appreciated.
if (!mJetting && mState != RecoverState && mDamageState == Enabled && move->trigger[3] && (mEnergy - 1) >= mDataBlock->minJetEnergy)
{
Con::printf("--------New Jet--------");
Con::printf("+You started jetting");
if(!alxIsPlaying(mJetStartSound)) {
Con::printf("+I started the jet start sound");
mJetStartSound = alxPlay(mDataBlock->sound[PlayerData::JetStartSnd], &getTransform());
alxSourceMatrixF(mJetStartSound, &getTransform());
}
}
bool mIsJetting = mJetting;
//Are we actually jetting?
mJetting = (mState != RecoverState && mDamageState == Enabled && move->trigger[3] && mEnergy > mDataBlock->minJetEnergy);
//If we're not jetting and the the jet sound happens to be playing, stop it
if (mJetting) {
...
//Play the jet sound
if (!alxIsPlaying(mJetSound))
{
mJetSound = alxPlay(mDataBlock->sound[PlayerData::JetSnd], &getTransform());
Con::printf("+++++++%i Started the LOOPING jet sound: %i", mId, mJetSound);
if (!alxIsValidHandle(mJetSound))
{
alxStop(mJetSound);
Con::printf("INVALID HANDLE! I TRIED TO STOP IT!"); //I know this doesn't make sense, but o well
}
}
alxSourceMatrixF(mJetSound, &getTransform());
}
else {
if (alxIsPlaying(mJetSound))
{
alxStop(mJetSound);
Con::printf("!!!!!!!%i STOPPED looping jet sound: %i", mId, mJetSound);
//mJetSound = NULL_AUDIOHANDLE;
}
if (alxIsPlaying(mJetStartSound))
{
alxStop(mJetStartSound);
Con::printf("--Stopped jet start sound");
//mJetStartSound = NULL_AUDIOHANDLE;
}
if (mIsJetting)
Con::printf("--------End Jet--------");
}
Ok, here's what's going on. And, it only happens in MULTIPLAYER ONLY, and when there is a certain combination of at least 2 people jetting. I can't figure out what the combination is either :( And, it works MOST of the time, but sometimes, it starts the jet sound in massive quantities when the other guy jets (the guy that started the jet doesn't get it).
The problem is that it starts up multiple looping jet sounds that NEVER STOP. Best of all, they start with an invalid audio handle. So, it starts the jet sound, get's a null audio handle back, so the next time it checks to see if it's playing, it doens't think it's playing since the alxIsPlaying function will return false if it gets passed a null audio handle. So, it starts up another, and another, and another...as long as the other guy jets.
I could half-get around this problem by creating another bool variable that gets set right after the sound starts playing, but without a valid audiohandle, you still can't stop it. Plus, that's just more memory.
The only thing that I can think of is that the audio function for starting sounds is bugged. Any an all suggestions would be appreciated.
#2
Have you solved this one yet?
If not, it seems like the best point of attack is the fact that you have alxPlay calls that start a sound but return a null audiohandle. That's a bad thing, and it's a specific code behavior that you can investigate by stepping through the audio code with the debugger.
What I would do in that situation is set up the command-line arguments with "-jSave badaudio" and arrange a breakpoint to fire if alxPlay returns a null audiohandle. Then run scenarios over and over again until you get the breakpoint to fire.
At that point, stop the game and change the command-line arguments to "-jPlay badaudio", to play back that session. Then use the debugger to step through the alxPlay call that produced the bad audiohandle, and maybe you'll find something interesting.
G'luck.
11/12/2002 (2:06 pm)
Well, I wouldn't want you to feel unimportant. :-) But nothing leaps out at me as being wrong in that code.Have you solved this one yet?
If not, it seems like the best point of attack is the fact that you have alxPlay calls that start a sound but return a null audiohandle. That's a bad thing, and it's a specific code behavior that you can investigate by stepping through the audio code with the debugger.
What I would do in that situation is set up the command-line arguments with "-jSave badaudio" and arrange a breakpoint to fire if alxPlay returns a null audiohandle. Then run scenarios over and over again until you get the breakpoint to fire.
At that point, stop the game and change the command-line arguments to "-jPlay badaudio", to play back that session. Then use the debugger to step through the alxPlay call that produced the bad audiohandle, and maybe you'll find something interesting.
G'luck.
#3
But, it still doesn't work. I "fixed" it by making it non-looping and extending the sound length so it won't run out, but sometimes it still hangs on after you stop jetting.
11/15/2002 (8:25 am)
Too bad I have no idea how to do what you're talking about....I really gotta learn how to use the vc debugger....But, it still doesn't work. I "fixed" it by making it non-looping and extending the sound length so it won't run out, but sometimes it still hangs on after you stop jetting.
Torque Owner Chris \"Hobbiticus\" Weiland