Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Setting the DirectSound Object

Windows CE .NET

Allowing DirectMusic to create and manage the DirectSound object works for applications that are not using DirectSound independently. However, if your application is using DirectSound to play wave data from a source other than the DirectMusic synthesizer, you must ensure that the same IDirectSound interface is used by DirectMusic. Create the DirectSound object first; then pass the interface pointer to DirectMusic. This can be done in the call to IDirectMusicPerformance::Init, as in the following example, in which pPerf is the IDirectMusicPerformance and pDS is a pointer to IDirectSound.

pPerf->Init(NULL, pDS, NULL);
Note   When an IDirectSound pointer is passed to IDirectMusicPerformance::Init, the third parameter, the window handle, is ignored. The application is responsible for setting the controlling window by calling IDirectSound::SetCooperativeLevel.
Set the DSSCL_PRIORITY cooperative level for any DirectSound object to be used with DirectMusic. If you set the DSSCL_NORMAL cooperative level, DirectMusic cannot upgrade the primary buffer format.

If you create the DirectMusic object by using CoCreateInstance, rather than letting the performance do it for you, you must also explicitly link it to an existing IDirectSound interface. This is done by using the IDirectMusic::SetDirectSound method.

You can also use the IDirectMusicPort::SetDirectSound method to assign a different DirectSound object to a port. Do this when different ports are on different audio devices, each represented by its own IDirectSound interface. The DirectSound object for a port cannot be changed once the port has been activated.

When a port that requires DirectSound is activated, it takes the first available IDirectSound interface pointer from the following list:

  1. The IDirectSound interface passed to IDirectMusicPort::SetDirectSound.
  2. The IDirectSound interface passed to IDirectMusic::SetDirectSound.
  3. The IDirectSound interface created by DirectMusic if NULL was passed to IDirectMusic::SetDirectSound.

When DirectSound is in emulation mode, it has exclusive use of the audio device. An application should release DirectSound whenever it loses the focus to allow other applications to use the device. Typically, this is done in response to a WM_ACTIVATE message.

If DirectMusic created the DirectSound object, it automatically releases the object when all ports are deactivated (and creates a new one when the first port using DirectMusic is reactivated). However, if you created the DirectSound object yourself, you are responsible for releasing it. This is done by using the IDirectMusic::SetDirectSound or the IDirectMusicPort::SetDirectSound method, passing NULL as the pDirectSound parameter.


 Last updated on Monday, April 12, 2004

© 1992-2002 Microsoft Corporation. All rights reserved.

Show:
© 2015 Microsoft