Aside from 3D manipulation of sounds, another technique used to bring out the realism of the games you play would be the effects added to already existing sounds. For example, walking across a wood floor would sound totally different in a small room from the way it would sound if you were in a large empty concert hall. Yelling in a cavern may cause your voice to echo among the cavern walls. These effects are an integral part of the immersion you are trying to create when developing a game, or any good interactive multimedia application.
Luckily, the act of using these special effects is pretty straightforward and there are quite a few of these effects already built into the DirectSound API. Revisiting the old example you created that was controlling the pan, update that to control some effects. Remove the timer since you won't be using that anymore. Then change the InitializeSound method as follows: public void InitializeSound() { device = new Device(); device.SetCooperativeLevel(this, CooperativeLevel.Normal); BufferDescription desc = new BufferDescription(); desc.ControlEffects = true; desc.GlobalFocus = true; sound = new SecondaryBuffer(@"..\..\drumpad-crash.wav",desc, device); EffectDescription[] effects = new EffectDescription[1]; effects[0].GuidEffectClass = DSoundHelper.StandardEchoGuid; sound.SetEffects(effects); sound.Play(0, BufferPlayFlags.Looping); } The big changes here are the ability to control the pan being removed, and change it to controlling the effects. Then you create an array of effect descriptions (currently with just one member), and assign that member to be the standard echo effect. You then pass in the effects that you have just created and start playing the buffer.
That's really all there is to setting the basic effects. If you run the application now you will be able to hear the echo that wasn't there before. It's also possible to add "stacks" of these effects on top of each other. If we wanted to have the sound played with an echo effect along with a flanger effect, followed by a distortion effect, you could update the method as follows: EffectDescription[] effects = new EffectDescription[3]; effects[0].GuidEffectClass = DSoundHelper.StandardEchoGuid; effects[1].GuidEffectClass = DSoundHelper.StandardFlangerGuid; effects[2].GuidEffectClass = DSoundHelper.StandardDistortionGuid; sound.SetEffects(effects); Well, you've managed to take the drum cymbal sound and make it sound like an airplane engine; at least that's what this sounds like to me. The effects also do not have to be different; you could just as easily pass in three flanger effects for the example above. As you can already tell, there are a few built-in effect types already, but what are they? You can find the effects listed in Table 14.4.
It is also possible to take any of the effects you've applied to the buffer and change any or all of the settings currently applied. You can do this with the GetEffects method on the secondary buffer. In order to better hear the changes you're making, get rid of all the effects you're currently playing except for the echo effect. Now, add the following section of code immediately after the call to SetEffects: EchoEffect echo = (EchoEffect)sound.GetEffects(0); EffectsEcho param = echo.AllParameters; param.Feedback = 1.0f; param.LeftDelay = 1060.2f; param.RightDelay = 1595.3f; param.PanDelay = 1; echo.AllParameters = param; Here, you use the GetEffects method to create an instance of the EchoEffect object, which holds all of the data for the echo effect that is currently being used. You then change a few properties on the echo effect, and you're done. Listen to the audio with and without this code running, the changes to the effect should be immediately obvious. Any effect that you load can have its options manipulated in this way.
|