Buffer Management

The IDirectSoundBuffer::GetCaps method retrieves the capabilities of the DirectSoundBuffer object.

Your application can use the IDirectSoundBuffer::GetStatus method to determine if the current sound buffer is playing or if it has stopped.

You can use the IDirectSoundBuffer::GetFormat method to retrieve information about the format of the sound data in the buffer. You also can use the IDirectSoundBuffer::GetFormat and IDirectSoundBuffer::SetFormat methods to retrieve and set the format of the sound data in the primary sound buffer.

Note  After a secondary sound buffer is created, its format is fixed. If you need a secondary buffer that uses another format, you must create a new sound buffer with this format.

Memory for a sound buffer can be lost in certain situations. In particular, this can occur when buffers are located in the hardware sound memory. In the worst case, the sound card itself might be removed from the system while in use; this situation can occur with PCMCIA sound cards.

Loss can also occur when an application with the write-primary cooperative level moves to the foreground. If this flag is set, DirectSound makes all other sound buffers lost so that the foreground application can write directly to the primary buffer. The DSERR_BUFFERLOST error code is returned when the IDirectSoundBuffer::Lock or IDirectSoundBuffer::Play method is called for any other buffer. When the application lowers its cooperative level from write-primary, or moves to the background, other applications can attempt to reallocate the buffer memory by calling the IDirectSoundBuffer::Restore method. If successful, this method restores the buffer memory and all other settings for the buffer, such as volume and pan settings. However, a restored buffer does not contain valid sound data. The owning application must rewrite the data to the restored buffer.