|MSDN Home > MSDN Library Archive > DirectX 8.1 (Visual Basic) > DirectX Audio > Using DirectX Audio > Wave Playback in DirectSound > Using Wave Data|
Archived content. No warranty is made as to technical accuracy. Content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
Microsoft DirectX 8.1 (Visual Basic)
This topic explains how to load data from wave files into DirectSound buffers without the help of the DirectMusic loader and performance. Most applications do not need to work directly with wave data and buffers. For the preferred method of loading and playing waves, see Loading Audio Data and Playing Sounds.
For short sounds, the easiest way to play a wave file using DirectSound alone is to load it into a
For larger files that will not conveniently fit in memory, you need to create a
Wave files are in the Resource Interchange File Format (RIFF), which consists of a file header followed by variable number of "chunks," each made up of a header and data. The chunk header consists of a four-character tag identifying the type of data and a Long giving the length of the data.
The wave file header is organized as follows:
The first chunk is always the format chunk, which looks like this:
The PCM sample data in a wave file is contained in a chunk beginning with the string "data", which can also be read as the Long &H61746164. Most often this chunk immediately follows the format chunk, but because RIFF is an extensible format, there is no guarantee that some other type of chunk will not precede it. Your file parser must be capable of ignoring chunks it cannot handle.
To parse a wave file, it is helpful to have three user-defined types. The first will receive all the information in the file header and in the header of the format chunk.
The second type will receive the format data. You can't use the WAVEFORMATEX type for this, because the members are in a different order. Your user-defined type needs to retrieve only 16 bytes, because if WAVEFORMATEX.nSize is present, it is always zero in standard PCM files.
The third type can be used to retrieve the header of any chunk, including the data chunk.
The following sample function verifies that a file is a RIFF wave file, seeks the beginning of the sample data, and returns a WAVEFORMATEX type containing information about the wave format:
The application can now begin reading data from the file and streaming that data into the secondary sound buffer. It's impossible to read data directly from the file into the secondary buffer, so you must first read the data into a private buffer and then copy it to the secondary buffer by using DirectSoundSecondaryBuffer8.WriteBuffer.