This series of articles by Net_assassin finishing, reproduced please indicate the source.
http://blog.csdn.net/net_assassin/article/category/1100363
Author: Net_assassin e-mail: net_assassin@hotmail.com look forward to interacting with like-minded friends
Audio is critical to the game. For gamers to immerse themselves in the unreal experience of the game, sound effects and music play a big role, and emotional responses are created among the players.
While exploring DirectSound, this chapter will also take advantage of this opportunity to further deal with sprite collisions.using DirectSound DirectSound is a component of DirectX that handles all sound output for the game, and it has a multichannel sound mixer. Basically, just tell the DirectSound to play the sound, it will handle all the details (including mixing the sound with the sound in the current playback). The code required to create, initialize, load, and play a waveform file using DirectSound is more complex than the bitmap and sprite code we learned earlier. So, to avoid duplication of effort, here's how to use Microsoft's own DirectSound wrapper to introduce you. The directx SDK includes a utility library called Dxutsound. The latest version of DirectX hides these classes in a set of files: SDKsound.h sdksound.cpp sdkwavefile.h. Because of the inconsistency problem, I created a pair of new audio files for our own use, with their names DirectSound.h DirectSound.cpp. We are interested in the three classes defined in Sdksound (formerly Dxutsound): Csoundmanager &NBSP ; main DirectSound equipment Csound &N Bsp , &NB Sp for creating DirectSound buffers Cwavefile &N Bsp &NBSp Help to load waveform files into the csound buffer
Initialize DirectSound
First, create an instance of the Csoundmanager class
Csoundmanager *dsound = new Csoundmanager ();
Next, call the Initialize function to initialize the DirectSound Manager:
dsound->initialize (window_handle,dsscl_priority);
After initializing the DirectSound, we must format the audio buffer.
Dsound->setprimarybufferformat (2,22050,16);
Create a sound bufferCsound *wave;
Load Waveform file
HRESULT Create (
csound** ppsound, //Specifies the Csound object used for newly loaded waveform sounds.
LPTSTR strwavefilename,//filename
DWORD dwcreateflags = 0,
GUID guid3dalgorithm = guid_ NULL,
DWORD dwnumbuffers = 1
);
Dsound->create (&wave, "snicker.wav");
Play Sound
HRESULT Play (
DWORD dwpriority = 0,//priority, must always be set to zero.
DWORD dwFlags = 0,//whether loop play, if loop, use dsbplay_looping
LONG lvolume = 0,//last three parameters specify sound volume, frequency, and left and right channel balance
long lfrequency =-1,
long lpan = 0
);
Wave->play (); Use loop words wave->play (0,dsbplay_looping);
Test DirectSound