当前位置: 首页>>代码示例>>C++>>正文


C++ WaveFile::Format方法代码示例

本文整理汇总了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
}
开发者ID:kbinani,项目名称:dxrip,代码行数:71,代码来源:AudioDevice.cpp


注:本文中的WaveFile::Format方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。