Your application should follow these basic steps to implement DirectSound:
1Create a DirectSound object by calling the DirectSoundCreate function.
2Specify a cooperative level by calling the IDirectSound::SetCooperativeLevel method. Most applications use the lowest level, DSSCL_NORMAL.
3Create secondary sound buffers by using the IDirectSound::CreateSoundBuffer method. Your application need not specify in the DSBUFFERDESC structure that these buffers are secondary buffers; the creation of secondary buffers is the default.
4Load the secondary buffers with data. Use the IDirectSoundBuffer::Lock method to obtain a pointer to the data area and the IDirectSoundBuffer::Unlock method to set the data to the device.
5Use the IDirectSoundBuffer::Play method to play the secondary buffers.
6Stop all buffers when your application has finished playing sounds by using the IDirectSoundBuffer::Stop method of the DirectSoundBuffer object.
7Release the secondary buffers.
8Release the DirectSound object.
Your application can also perform the following optional items:
·Set the output format of the primary sound buffer by creating a primary buffer and calling the IDirectSoundBuffer::SetFormat method. This requires your application to set the cooperative level to DSSCL_PRIORITY before setting the output format of the primary buffer.
·Create a primary sound buffer and play the buffer by using the IDirectSoundBuffer::Play method. This guarantees that the primary buffer is always playing, even if no secondary buffers are playing. This action consumes some of the processing bandwidth, but it reduces startup time when the first secondary buffer is played.
This section contains code samples that perform the following common tasks related to the DirectSound component. An explanation of the code accompanies each sample.
·Creating a DirectSound Object
·Creating a DirectSound Object by Using CoCreateInstance