Game Development Reference
In-Depth Information
HRESULT SetPrimaryBufferFormat(
DWORD dwPrimaryChannels,
DWORD dwPrimaryFreq,
DWORD dwPrimaryBitRate );
};
Theonlypieceofdatainthisclassisapointertoan IDirectSound8 object, which is
DirectSound
s gatekeeper, so to speak. Initialization, shutdown, and creating audio buffers
are all done through this object. One way to look at this is that DirectSoundAudio is a
C++ wrapper around IDirectSound8 .Let
'
'
s look at initialization and shutdown first:
bool DirectSoundAudio::VInitialize(HWND hWnd)
{
if ( m_Initialized )
return true;
m_Initialized=false;
m_AllSamples.clear();
SAFE_RELEASE( m_pDS );
HRESULT hr;
// Create IDirectSound using the primary sound device
if( FAILED( hr = DirectSoundCreate8( NULL, &m_pDS, NULL ) ) )
return false;
// Set DirectSound coop level
if( FAILED( hr = m_pDS->SetCooperativeLevel( hWnd, DSSCL_PRIORITY) ) )
return false;
if( FAILED( hr = SetPrimaryBufferFormat( 8, 44100, 16 ) ) )
return false;
m_Initialized = true;
return true;
}
This code is essentially lifted straight from the DirectX sound samples, so it might
look pretty familiar. When you set the cooperative level on the DirectSound object,
you
re telling the sound driver you want more control over the sound system, specif-
ically how the primary sound buffer is structured and how other applications run at
the same time. The DSSCL_PRIORITY level is better than DSSCL_NORMAL because
you can change the format of the output buffer. This is a good setting for games
that still want to allow background applications like Microsoft Messenger or Outlook
to be able to send something to the speakers.
'
Search WWH ::




Custom Search