Game Development Reference
In-Depth Information
'
Why bother? If you don
t do this, and set the priority level to DSSCL_NORMAL ,
you ' re basically informing the sound driver that you ' re happy with whatever pri-
mary sound buffer format is in place, which might not be the same sound format
you need for your game audio. The problem is one of conversion. Games use tons
of audio, and the last thing you need is for every sound to go through some conver-
sion process so it can be mixed in the primary buffer. If you have 100,000 audio
files and they are all stored in 44KHz, the last thing you want is to have each one
be converted to 22KHz, because it
'
s a waste of
time. Take control and use
DSSCL_PRIORITY .
The call to SetPrimaryBufferFormat() sets your primary buffer format to a fla-
vor you want; most likely, it will be 44KHz, 16-bit, and some number of channels
that you feel is a good trade-off between memory use and the number of simulta-
neous sound effects you ' ll have in your game. For the purposes of this class, I ' m
choosing eight channels, but in a commercial game you could have 32 channels or
even more. The memory you
ll spend with more channels is dependent on your
sound hardware, so be cautious about grabbing a high number of channels
'
you
might find some audio cards won
'
t support it.
HRESULT DirectSoundAudio::SetPrimaryBufferFormat(
DWORD dwPrimaryChannels,
DWORD dwPrimaryFreq,
DWORD dwPrimaryBitRate )
{
// !WARNING! - Setting the primary buffer format and then using this
// for DirectMusic messes up DirectMusic!
//
// If you want your primary buffer format to be 22KHz stereo, 16-bit
// call with these parameters: SetPrimaryBufferFormat(2, 22050, 16);
HRESULT hr;
LPDIRECTSOUNDBUFFER pDSBPrimary = NULL;
if( ! m_pDS )
return CO_E_NOTINITIALIZED;
// Get the primary buffer
DSBUFFERDESC dsbd;
ZeroMemory( &dsbd, sizeof(DSBUFFERDESC) );
dsbd.dwSize = sizeof(DSBUFFERDESC);
dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
dsbd.dwBufferBytes = 0;
dsbd.lpwfxFormat = NULL;
Search WWH ::




Custom Search