Microsoft DirectX 9.0

Playing Sounds on Audiopaths

If your application has created a default audiopath in the call to IDirectMusicPerformance8::InitAudio, you can play a segment on this path by using IDirectMusicPerformance8::PlaySegment. You can also play a segment on the default path by passing NULL in the pAudioPath parameter of IDirectMusicPerformance8::PlaySegmentEx.

If there is no default audiopath, or if you want to play a segment on another path, you must use PlaySegmentEx rather than PlaySegment. You can specify the audiopath in two ways:

Note   An audiopath created in response to the DMUS_SEGF_USE_AUDIOPATH flag is released as soon as the segment has stopped playing. If the audiopath contains an effect such as reverberation, the effect is cut short prematurely. To prevent this from happening, the application should create the audiopath manually and release it only after a suitable delay.

Bands are not downloaded for segments played with the DMUS_SEGF_USE_AUDIOPATH flag unless automatic downloading is enabled. For more information, see Automatically Downloading Bands.

The following example function plays a segment on an embedded audiopath configuration if one is available, or on the default audiopath otherwise:

HRESULT PlayOnEmbedded(IDirectMusicPerformance8* pPerf, IDirectMusicSegment8 *pSeg)
  IDirectMusicAudioPath8 * pPath =  NULL;
  IUnknown *pConfig;
  if (pSeg)
    if (SUCCEEDED(hr = pSeg->GetAudioPathConfig(&pConfig)))
      hr = pPerf->CreateAudioPath(pConfig, TRUE, &pPath);
    hr = pPerf->PlaySegmentEx(pSeg, NULL, NULL, 0, 0, NULL, NULL, pPath);
    if (pPath) 
      pPath = NULL;
  return hr;

If you have an interface to the audiopath, you can change the volume by using IDirectMusicAudioPath8::SetVolume. Unlike the global parameter GUID_PerfMasterVolume, which affects all sounds playing on the synthesizer, this method sets the volume only on the performance channels playing on this audiopath.