A DirectSound Buffer is a one-dimensional array of bytes which represent sound waves in a digital form. The data is laid out in a specified Microsoft.DirectX.DirectSound.WaveFormat which specifies the format type, number of channels, number of samples per second and so on.1
Each byte is a part of a sample, and a sample represents the average amplitude of the sound waves position at that point in time.2
There are two types of buffers used for output: Primary and Secondary. These both send data to an output device, represented by a Microsoft.DirectX.DirectSound.Device object.
Primary Buffer
There is only one Primary Buffer for a device, and the data it contains is exactly what will come out of that device.
Accessing and changing the primary buffer is possible, but usually unnecessary. It’s better to let DirectX handle the mixing, or you will have to take responsibility for outputting the buffer in real-time. You also lose the ability to use secondary buffers, and it prevents other applications from using buffers.
To access the primary buffer, create a Microsoft.DirectX.DirectSound.Buffer object using a DirectSound Device with its cooperative level set to CooperativeLevel.WritePrimary.
Secondary Buffer
The secondary buffer is a buffer of a specified size, and contains sound data ready to be output. An application can have as many secondary buffers as it wants, within memory limits.
When you call a buffer’s Play function the content is mixed into the primary buffer and output by DirectX.
If called with the BufferPlayFlags.Looping flag set, it will play the buffer from start to finish over and over again until stopped. By continually writing new data into the buffer just ahead of the current play position it is possible to output audio that would not have fitted into memory, or that did not even exist when you started the buffer. This is known as streaming.
You can either use a Microsoft.DirectX.DirectSound.Buffer, or a Microsoft.DirectX.DirectSound.SecondaryBuffer which inherits the previous and adds support for effects such as distortion, compression, reverb, and more.
- Only data which matches that format can be loaded into the an output buffer. Sound data with different formats can be played at the same time by using separate secondary buffers for each. [↩]
- Remember that sound is a waveform, and the buffer contains the actual wave data. Filling it with just one value will produce silence as the speaker cones will not move. To produce a tone programatically you need to fill the buffer with a waveform, such as a Sine Wave, a Square Wave, a Triangle Wave, or a Sawtooth Wave. [↩]

This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.