Microsoft DirectX 8.1 (Visual Basic)

Cooperative Levels

Because Windows is a multitasking environment, more than one application can be working with a device driver at any one time. Through the use of cooperative levels, DirectX makes sure that each application does not gain access to the device in the wrong way or at the wrong time. Each DirectSound application has a cooperative level that determines the extent to which it is allowed to access the device.

After creating a DirectSound8 object, you must set the cooperative level for the device with the DirectSound8.SetCooperativeLevel method before you can play sounds.

The following example code sets the cooperative level for the DirectSound8 object m_ds. The hwnd argument is the handle to the application window.

m_ds.SetCooperativeLevel Me.hWnd, DSSCL_PRIORITY

DirectSound defines three cooperative levels for sound devices, represented by the values DSSCL_NORMAL, DSSCL_PRIORITY, and DSSCL_WRITEPRIMARY.

Note

The DSSCL_EXCLUSIVE cooperative level available in versions earlier than DirectX 8.0 is obsolete. It is no longer possible for a DirectX application to mute other applications. Applications that request the exclusive level are granted the priority level instead.

Normal Cooperative Level

At the normal cooperative level, the application cannot set the format of the primary buffer or write to the primary buffer. All applications at this cooperative level use a primary buffer format of 22 kHz, stereo sound, and 8-bit samples, so that the device can switch between applications as smoothly as possible.

Priority Cooperative Level

When using a DirectSound device with the priority cooperative level, the application has first rights to hardware resources, such as hardware mixing, and can set the format of the primary sound buffer.

Game applications should use the priority cooperative level in almost all circumstances. This level gives the most robust behavior while allowing the application control over sampling rate and bit depth. The priority cooperative level also allows audio from other applications, such as IP telephony, to be heard along with the audio from the game.

Write-primary Cooperative Level

Visual Basic applications should not use the DSSCL_WRITEPRIMARY cooperative level. This level is for specialized applications that do not use the DirectSound mixer.