DirectX SDK

Reading Wave Data from a Resource

[Visual Basic]

This topic applies only to applications written in C++.

[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
}