Microsoft DirectX 8.1 (C++)

Setting Effects on Buffers

If you are playing segments authored in DirectMusic Producer with audiopath configurations, any effects are set up when you create the audiopath from the configuration object. A standard audiopath might also contain effects. However, in some cases you may prefer to implement an effect on a custom audiopath at run time or add an effect to a standard audiopath. For example, you might want to add an effect to a standard audiopath so that you can apply the effect to wave or MIDI files.

To apply an effect to an audiopath, first obtain an IDirectSoundBuffer8 interface to a buffer on the path. Then set one or more effects on that buffer by using IDirectSoundBuffer8::SetFX.

To learn how to obtain a buffer interface, see Retrieving Objects from an Audiopath. For information on how to identify standard audiopath buffers in the call to GetObjectInPath, see the audiopath types under Standard Audiopaths.

The following sample code sets a standard audiopath, retrieves a buffer from the path, and sets an echo effect on the buffer:

// Assume that pPerformance is a valid IDirectMusicPerformance8
// interface pointer.
 
IDirectMusicAudioPath*  g_p3DAudioPath;
IDirectSoundBuffer8*  g_pDSBuffer;
HRESULT       hr;
 
// Create a standard audiopath with a source and 
// environment reverb buffers. Don't activate the path;
// SetFX fails if the buffer is running. 
 
if( FAILED(hr = pPerformance->CreateStandardAudioPath(
  DMUS_APATH_DYNAMIC_3D, 64, FALSE, &g_p3DAudioPath)))
  return hr;
 
// Get the buffer in the audiopath.
 
if( FAILED(hr = g_p3DAudioPath->GetObjectInPath(DMUS_PCHANNEL_ALL,
  DMUS_PATH_BUFFER, 0, GUID_NULL, 0, IID_IDirectSoundBuffer8, 
  (LPVOID*) &g_pDSBuffer)))
  return hr;
 
// Describe the effect.
 
DSEFFECTDESC dsEffect;
dsEffect.dwSize = sizeof(DSEFFECTDESC);
dsEffect.dwFlags = 0;
dsEffect.guidDSFXClass = GUID_DSFX_STANDARD_ECHO;
dsEffect.dwReserved1 = 0;
dsEffect.dwReserved2 = 0;
 
DWORD dwResults;
 
// Set the effect
if (FAILED(hr = g_pDSBuffer->SetFX(1, &dsEffect, &dwResults)))
  return hr;
 
// You can check the value of dwResults here to see if and how 
// the effect was allocated.
 
// Activate the path.
 
g_p3DAudioPath->Activate(TRUE);