DirectSound

Note: DirectSound is being replaced by XAudio2 and will be removed from the SDK in the near future and so should now be considered deprecated.

The DirectSound API allows you to play back sound effects in your game. Unlike DirectShow you can play multiple sounds at once. You can also:

  • use hardware controlled buffers for extra speed
  • position sounds in 3D space
  • add effects to sound e.g. reverb, echo
  • record sounds

Note: Microsoft intend to replace DirectSound with another API in the near future. This will be Xbox and PC cross platform.

DirectSound Demo and Source

DirectSound is not as easy to use as some of the other DirectX APIs. For instance you need to load .wav files yourself (there are no handy functions like in Direct3D). I have created a demo application that demonstrates playing multiple sounds using DirectSound and the dsutil files that came with an earlier version of the SDK. You can download the executable here: SoundPlayerDemo.zip. The source code is available here: SoundPlayerSource.zip. Most of the work is done in the CSoundPlayer class. This is briefly described below:

  • This class has a CSoundManager member variable. This manager is defined in the dsutil files and allows us to load and play sounds.
  • In the Initialise function an instance of the sound manager is created and the priority and the format of the primary sound buffer defined.
  • CSoundPlayer maintains a vector of sounds called m_soundVector. When a new sound is added we ask the sound manager to create a CSound class for us. This class handles the loading of the sound and later play back.
  • To play a sound the id of the sound (it is the index of the sound in the vector) is used in the call to the CSound play function.

For general DirectX questions and answers please see this page: DirectX.

 



© 2004-2016 Keith Ditchburn