本文整理汇总了C++中WaveFile::Format方法的典型用法代码示例。如果您正苦于以下问题:C++ WaveFile::Format方法的具体用法?C++ WaveFile::Format怎么用?C++ WaveFile::Format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WaveFile
的用法示例。
在下文中一共展示了WaveFile::Format方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PlayWaveFile
void AudioDevice::PlayWaveFile(WaveFile &File, bool LoopForever)
{
#ifdef USE_DIRECTX_AUDIO
if(_Device == NULL)
{
return;
}
RemoveVoices(true);
if(_ActiveSourceVoices.Length() > 4)
{
return;
}
// Get format of wave file
WAVEFORMATEX& pwfx = File.Format();
// Create the source voice
IXAudio2SourceVoice* _SourceVoice;
HRESULT hr = _Device->CreateSourceVoice( &_SourceVoice, &pwfx );
Assert(SUCCEEDED(hr), "CreateSourceVoice failed");
_ActiveSourceVoices.PushEnd(_SourceVoice);
// Submit the wave sample data using an XAUDIO2_BUFFER structure
XAUDIO2_BUFFER buffer = {0};
buffer.pAudioData = (BYTE *)File.Data().CArray();
buffer.Flags = XAUDIO2_END_OF_STREAM; // tell the source voice not to expect any data after this buffer
buffer.AudioBytes = File.Data().Length();// * sizeof(DWORD);
if(LoopForever)
{
buffer.LoopBegin = 1;
buffer.LoopLength = 0;
buffer.LoopCount = XAUDIO2_LOOP_INFINITE;
}
hr = _SourceVoice->SubmitSourceBuffer( &buffer );
Assert(SUCCEEDED(hr), "SubmitSourceBuffer failed");
hr = _SourceVoice->Start( 0 );
Assert(SUCCEEDED(hr), "SubmitSourceBuffer failed");
//delete[] pbWaveData;
//Sleep(3000);
//_SourceVoice->DestroyVoice();
// Let the sound play
/*BOOL isRunning = TRUE;
while( SUCCEEDED( hr ) && isRunning )
{
XAUDIO2_VOICE_STATE state;
pSourceVoice->GetState( &state );
isRunning = ( state.BuffersQueued > 0 ) != 0;
// Wait till the escape key is pressed
if( GetAsyncKeyState( VK_ESCAPE ) )
break;
Sleep( 10 );
}
// Wait till the escape key is released
while( GetAsyncKeyState( VK_ESCAPE ) )
Sleep( 10 );
pSourceVoice->DestroyVoice();
SAFE_DELETE_ARRAY( pbWaveData );
return hr;*/
#endif
}