Partager via


Mixing Sounds

[The feature associated with this page, DirectSound, is a legacy feature. It has been superseded by WASAPI and Audio Graphs. Media Casting have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Media Casting instead of DirectSound, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

Secondary buffers played simultaneously are automatically mixed in the primary buffer. Under the Windows driver model, the mixing is done in the kernel mixer. Different secondary buffers can have different WAV formats (for example, different sampling rates), and sounds are converted to the format of the primary buffer or kernel mixer as necessary.

On VXD drivers, the DirectSound mixer produces the best sound quality if all your application's sounds use the same WAV format and the hardware output format is matched to the format of the sounds. If this is done, the mixer does not need to perform any format conversion. Your application can change the hardware output format by creating a primary sound buffer object and calling the IDirectSoundBuffer8::SetFormat method. To do this, you need the Priority Cooperative Level. You must set the format of the primary buffer before creating any secondary buffers. DirectSound will restore the hardware format to the format specified in the last call every time the application gains the input focus.

On WDM drivers, setting the primary buffer format has no effect. The format is determined by the kernel mixer. For more information, see DirectSound Driver Models.