DirectX SDK

DSBUFFERDESC

The DSBUFFERDESC structure describes the necessary characteristics of a new DirectSoundBuffer object. This structure is used by the IDirectSound::CreateSoundBuffer method.

typedef struct { 
    DWORD           dwSize; 
    DWORD           dwFlags; 
    DWORD           dwBufferBytes; 
    DWORD           dwReserved; 
    LPWAVEFORMATEX  lpwfxFormat; 
    GUID            guid3DAlgorithm; 
} DSBUFFERDESC, *LPDSBUFFERDESC; 
 
typedef const DSBUFFERDESC *LPCDSBUFFERDESC;

Members

dwSize
Size of the structure, in bytes. This member must be initialized before the structure is used.
dwFlags
Identifies the capabilities to include when creating a new DirectSoundBuffer object. Specify one or more of the following:
DSBCAPS_CTRL3D
The buffer is either a primary buffer or a secondary buffer that uses 3-D control.
DSBCAPS_CTRLFREQUENCY
The buffer must have frequency control capability.
DSBCAPS_CTRLPAN
The buffer must have pan control capability.
DSBCAPS_CTRLPOSITIONNOTIFY
The buffer must have position notification capability. On VxD drivers, if a sound buffer is created with DSBCAPS_CTRLPOSITIONNOTIFY, this buffer will always be a software buffer. This is because the VxD driver model doesn't support the notify interface. With WDM drivers, a position notification enabled buffer may be in hardware, if hardware is available.
DSBCAPS_CTRLVOLUME
The buffer must have volume control capability.
DSBCAPS_GETCURRENTPOSITION2
Indicates that IDirectSoundBuffer::GetCurrentPosition should use the new behavior of the play cursor. In DirectSound in DirectX 1, the play cursor was significantly ahead of the actual playing sound on emulated sound cards; it was directly behind the write cursor. Now, if the DSBCAPS_GETCURRENTPOSITION2 flag is specified, the application can get a more accurate play position. If this flag is not specified, the old behavior is preserved for compatibility. Note that this flag affects only emulated sound cards; if a DirectSound driver is present, the play cursor is accurate for DirectSound in all versions of DirectX.
DSBCAPS_GLOBALFOCUS
The buffer is a global sound buffer. With this flag set, an application using DirectSound can continue to play its buffers if the user switches focus to another application, even if the new application uses DirectSound. The one exception is if you switch focus to a DirectSound application that uses the DSSCL_EXCLUSIVE or DSSCL_WRITEPRIMARY flag for its cooperative level. In this case, the global sounds from other applications will not be audible.
DSBCAPS_LOCDEFER
The buffer can be assigned to a hardware or software resource during playing. This flag must be set for buffers that will use the new voice allocation and management features of DirectX 7.0.
DSBCAPS_LOCHARDWARE
Forces the buffer to use hardware mixing, even if DSBCAPS_STATIC is not specified. If the device does not support hardware mixing or if the required hardware memory is not available, the call to the IDirectSound::CreateSoundBuffer method will fail. The application must ensure that a mixing channel will be available for this buffer; this condition is not guaranteed.
DSBCAPS_LOCSOFTWARE
Forces the buffer to be stored in software memory and use software mixing, even if DSBCAPS_STATIC is specified and hardware resources are available.
DSBCAPS_MUTE3DATMAXDISTANCE
The sound is to be reduced to silence at the maximum distance. The buffer will stop playing when the maximum distance is exceeded, so that processor time is not wasted.
DSBCAPS_PRIMARYBUFFER
Indicates that the buffer is a primary sound buffer. If this value is not specified, a secondary sound buffer will be created.
DSBCAPS_STATIC
Indicates that the buffer will be used for static sound data. Typically, these buffers are loaded once and played many times. These buffers are candidates for hardware memory.
DSBCAPS_STICKYFOCUS
Changes the focus behavior of the sound buffer. This flag can be specified in an IDirectSound::CreateSoundBuffer call. With this flag set, an application using DirectSound can continue to play its sticky focus buffers if the user switches to another application not using DirectSound. In this situation, the application's normal buffers are muted, but the sticky focus buffers are still audible. This is useful for nongame applications, such as movie playback (DirectShow), when the user wants to hear the soundtrack while typing in Microsoft Word or Microsoft Excel, for example. However, if the user switches to another DirectSound application, all sound buffers, both normal and sticky focus, in the previous application are muted.
dwBufferBytes
Size of the new buffer, in bytes. This value must be 0 when creating primary buffers. For secondary buffers, the minimum and maximum sizes allowed are specified by DSBSIZE_MIN and DSBSIZE_MAX, defined in Dsound.h.
dwReserved
This value is reserved. Do not use.
lpwfxFormat
Address of a structure specifying the waveform format for the buffer. This value must be NULL for primary buffers. The application can use IDirectSoundBuffer::SetFormat to set the format of the primary buffer.
guid3DAlgorithm
The guid3DAlgorithm member sets the 2-speaker virtualization algorithm used by the DirectSoun3D HEL. If the DSCAPS_CTRL3D flag is not set for the sound buffer, the guid3DAlgorithm parameter is ignored. These apply only to two-speaker virtualization algorithms when the speakerConfig is set to either two-speaker or headphone output. If the speakerConfig setting is other than a two speaker or headphone setting, processing will behave as if a two speaker setting was selected. If a NULL guid (GUID_NULL) is supplied, the behavior is identical to DS3DALG_DEFAULT. Note:: If DSBCAPS_CTRL3D is not set, this parameter must be GUID_NULL.

The valid algorithms that can be specified are:

DS3DALG _DEFAULT
Applies to Software Mixing Only.

The HEL is set to be the default algorithm. Currently, this will select the DS3DALG_NO_VIRTUALIZATION algorithm, which provides a CPU- efficient, but basic 3-D effect. In the future, the algorithm used when DS3DALG_DEFAULT is set may be based on the user's preference by means of a control panel setting.

AVAILABLE ON: WDM or Vxd Drivers

DS3DALG _NO_VIRTUALIZATION
Applies to Software Mixing Only.

The Direct3D API is mapped onto normal left and right stereo panning. At 90 degrees to the left, the sound is coming out of only the left speaker; at 90 degrees to the right, sound is coming out of only the right speaker. The vertical axis is ignored except for scaling of volume due to distance. Doppler shift and volume scaling are still applied, but the 3-D filtering is not performed on this buffer. This is the most efficient software implementation, but provides no virtual 3-D audio effect. When the DS3DALG_NO_VIRTUALIZATION flag is specified, Head Related Transfer Function (HRTF) processing will not be done. Note: Since DS3DALG_NO_VIRTUALIZATION uses only normal stereo panning, a buffer created with this algorithm may be accelerated by a 2-D hardware voice if no free 3-D hardware voices are available.

AVAILABLE ON: WDM or Vxd Drivers

DS3DALG_HRTF_FULL
Applies to Software Mixing Only.

The 3-D API is processed with the high quality 3-D audio algorithm. This flag applies only to the software HEL. This algorithm gives the highest quality 3-D audio effect, but uses more CPU.

AVAILABLE ON: Microsoft® Windows® 98 Second Edition and Windows 2000 that use WDM drivers. .

Note: If a sound buffer is created using one of the HRTF algorithms, and the HRTF algorithm is not available on the system (for example a non-WDM system), a partial-success code, DS_NO_VIRTUALIZATION, is returned. The sound buffer created will use the DS3DALG_NO_VIRTUALIZATION instead.

For this reason, applications should use the "SUCCEDED()" or "FAILED()" macros, rather than check explicitly for DS_OK when calling CreateSoundBuffer.

DS3DALG_HRTF_LIGHT
Applies to Software Mixing Only.

The 3-D API is processed with the efficient 3-D audio algorithm. This flag applies only to the software HEL. This algorithm gives a good 3-D audio effect, but uses less CPU than DS3DALG_HRTF_FULL.

AVAILABLE ON: Windows 98 Second Edition and Windows 2000 that use WDM drivers.

Note: If a sound buffer is created using one of the HRTF algorithms, and the HRTF algorithm is not available on the system (for example a non-WDM system), a partial-success code, DS_NO_VIRTUALIZATION, is returned. The sound buffer created will use the DS3DALG_NO_VIRTUALIZATION instead.

For this reason, applications should use the "SUCCEDED()" or "FAILED()" macros, rather than check explicitly for DS_OK when calling CreateSoundBuffer.

Remarks

DSBCAPS_CTRLDEFAULT has been removed to encourage use of the individual flags that DSBCAPS_CTRLDEFAULT represents. DSBCAPS_CTRLDEFAULT was previously defined as DSBCAPS_CTRLPAN | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLFREQUENCY. By specifying only the flags you need, you cut down on unnecessary resource usage.

The DSBCAPS_LOCHARDWARE and DSBCAPS_LOCSOFTWARE flags used in the dwFlags member are optional and mutually exclusive. DSBCAPS_LOCHARDWARE forces the buffer to reside in memory located in the sound card. DSBCAPS_LOCSOFTWARE forces the buffer to reside in main system memory, if possible.

These flags are also defined for the dwFlags member of the DSBCAPS structure, and when used there, the specified flag indicates the actual location of the DirectSoundBuffer object.

When creating a primary buffer, applications must set the dwBufferBytes member to 0; DirectSound will determine the optimal buffer size for the particular sound device in use. To determine the size of a created primary buffer, call IDirectSoundBuffer::GetCaps.

The 3-D algorithms represent selection of the software emulation layer only; that is the software algorithm that is used when no hardware is present for acceleration. In order to maximize hardware utilization, DS3DALG_NO_VIRTUALIZATION is treated as a special case. If no free 3-D hardware voices are available, the buffer is then treated as a 2-D buffer, but with 3-D API control. Specifically, when a sound buffer is created with DS3DALG_NO_VIRTUALIZATION (or the buffer is played if the buffer is created with DSBPLAY_LOCDEFER) the following procedure is followed:

If a free hardware 3-D voice is available, that 3-D hardware voice is used.

If no free hardware 3-D voices are available and a 2-D hardware voice is available, that 2-D hardware voice will be used. This is possible since the NO_VIRTUALIZATION algorithm is a simple stereo pan algorithm

If no free 2-D or 3-D hardware voices are available, the voice will be played in software using the NO_VIRTUALIZATION algorithm.

Note  Sound buffers created with the DSBCAPS_CTRLPOSITIONNOTIFY flag must set a notification event. If you create a sound buffer with the NOTIFY flag, but don't actually set any notifications, the behavior is undefined. You may experience sounds being played back twice. Therefore, applications should not use DSBCAPS_CTRLPOSITIONNOTIFY unless they actually set a notification event.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable for Windows 95.
  Header: Declared in dsound.h.

See Also

IDirectSound::CreateSoundBuffer