本文整理汇总了C++中IDirectSoundBuffer::GetFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirectSoundBuffer::GetFormat方法的具体用法?C++ IDirectSoundBuffer::GetFormat怎么用?C++ IDirectSoundBuffer::GetFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirectSoundBuffer
的用法示例。
在下文中一共展示了IDirectSoundBuffer::GetFormat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetPrimaryBufferMode
void DSound::SetPrimaryBufferMode()
{
#ifndef _XBOX
DSBUFFERDESC format;
memset( &format, 0, sizeof(format) );
format.dwSize = sizeof(format);
format.dwFlags = DSBCAPS_PRIMARYBUFFER;
format.dwBufferBytes = 0;
format.lpwfxFormat = NULL;
IDirectSoundBuffer *pBuffer;
HRESULT hr = this->GetDS()->CreateSoundBuffer( &format, &pBuffer, NULL );
/* hr */
if( FAILED(hr) )
{
LOG->Warn(hr_ssprintf(hr, "Couldn't create primary buffer"));
return;
}
WAVEFORMATEX waveformat;
memset( &waveformat, 0, sizeof(waveformat) );
waveformat.cbSize = 0;
waveformat.wFormatTag = WAVE_FORMAT_PCM;
waveformat.wBitsPerSample = 16;
waveformat.nChannels = 2;
waveformat.nSamplesPerSec = 44100;
waveformat.nBlockAlign = 4;
waveformat.nAvgBytesPerSec = waveformat.nSamplesPerSec * waveformat.nBlockAlign;
// Set the primary buffer's format
hr = IDirectSoundBuffer_SetFormat( pBuffer, &waveformat );
if( FAILED(hr) )
LOG->Warn( hr_ssprintf(hr, "SetFormat on primary buffer") );
DWORD got;
hr = pBuffer->GetFormat( &waveformat, sizeof(waveformat), &got );
if( FAILED(hr) )
LOG->Warn( hr_ssprintf(hr, "GetFormat on primary buffer") );
else if( waveformat.nSamplesPerSec != 44100 )
LOG->Warn( "Primary buffer set to %i instead of 44100", waveformat.nSamplesPerSec );
/* MS docs:
*
* When there are no sounds playing, DirectSound stops the mixer engine and halts DMA
* (direct memory access) activity. If your application has frequent short intervals of
* silence, the overhead of starting and stopping the mixer each time a sound is played
* may be worse than the DMA overhead if you kept the mixer active. Also, some sound
* hardware or drivers may produce unwanted audible artifacts from frequent starting and
* stopping of playback. If your application is playing audio almost continuously with only
* short breaks of silence, you can force the mixer engine to remain active by calling the
* IDirectSoundBuffer::Play method for the primary buffer. The mixer will continue to run
* silently.
*
* However, I just added the above code and I don't want to change more until it's tested.
*/
// pBuffer->Play( 0, 0, DSBPLAY_LOOPING );
pBuffer->Release();
#endif
}