Platform SDK: DirectX

Reading Wave Data from a Resource

[Visual Basic]

Because sounds stored as resources are likely to be short, it is recommended that they be played through static buffers. To create a static buffer and fill it with data from a resource, use the DirectSound.CreateSoundBufferFromResource method. For an example, see Filling and Playing Static Buffers.

Longer sounds can be stored in wave files and played through streaming buffers. For more information, see the following topics:

[C++]

The DirectSound API does not include methods for reading a wave from a resource. However, there are helper functions in Dsutil3d.c, which you will find with the source code for the 3DMusic sample found in DirectMusic samples directory.

To store wave sounds in an executable or DLL, import your wave files as resources and give them string names. Note that Dsutil3d.c expects these resources to be of type "WAV." If you are using Microsoft® Visual C++®, imported wave files are turned into resources of type "WAVE." You must either change this nomenclature to "WAV" by editing the resource file, or else modify the assignment of c_szWAV in Dsutil3d.c so that the FindResource function is looking for "WAVE" resources.

You may also want to modify Dsutil3d.c so that the DSLoadSoundBuffer function sets only the appropriate control flags.

To create a static buffer and load the sound into it, simply pass the IDirectSound interface pointer and the name of the resource to the DSLoadSoundBuffer function. If successful, the function returns a pointer to the buffer. Here's a sample call, where lpds is the pointer to the IDirectSound interface:

#include "dsutil.h"
 
LPDIRECTSOUNDBUFFER  lpdsbFootstep;
 
lpdsbFootstep = DSLoadSoundBuffer(lpds, "FOOTSTEP");
if (lpdsbFootstep == NULL)
{
    // Failure
}