Game Development Community

Turning off weapon state sounds

by Shai Perry · in Torque Game Engine · 06/08/2006 (5:46 pm) · 3 replies

I was wondering if it's possible when I'm in a given state to turn off a previous state's sound in ShapeBaseImageData.

For example let's say I'm in state 2 and I have "stateSound[2] = SomeLongSound;" and then I switch to state 3 it still finishes the sound that was playing in state 2 whereas I want it to completely turn off when I switch states.

I tried setting the state 3 sound to "stateSound[3] = BlankSound" where BlankSound is just a blank .ogg.
But it didn't work.

Any Ideas?

Thanks

#1
06/08/2006 (9:49 pm)
The TGE engine uses a looped audio sound which, for fast firing weapons was causing all of the audio channels to fill up.

I reworked this code to use one audio channel only and use singular (non-looped) sounds.

The result is a much cleaner and clearer sounding weapon.

Engine\Game\ShapeImage.cc

Lines at approx 1616 look like this:
// Play sound
   if (stateData.sound && isGhost()) {
      Point3F vel = getVelocity();
      image.animSound = alxPlay(stateData.sound, &getRenderTransform(), &vel);
      ALint value = 0;
      alxGetSourcei(image.animSound, AL_LOOPING, &value);
      image.animLoopingSound = (value == AL_TRUE);
   }

Replace with this:

// Play sound
   if (stateData.sound && isGhost()) {
      Point3F vel = getVelocity();
	  if(image.animSound)
	  {
		  alxStop(image.animSound);
		  image.animSound = 0;
	  }
      image.animSound = alxPlay(stateData.sound, &getRenderTransform(), &vel);
      ALint value = 0;
      //alxGetSourcei(image.animSound, AL_LOOPING, &value);
      image.animLoopingSound = false;//(value == AL_TRUE);
   }

What this does is plays a sound and, if that sound is still playing when the next firing sound is played, it stops it before playing the next sound.

This means you can use a nice long 2 second rifle sound in an automatic rifle (if you wish)
and the last firing sound will have that nice long fade.
#2
06/08/2006 (11:33 pm)
Oh, and just incase you were wondering... the above code will fix your problem. As far as ShapeImage sounds are concerned, a new sound that is played will cancel out any previously played sounds.
#3
06/09/2006 (12:41 pm)
It totally worked. Thank you so much for the fix Tim!