Windows8 で pcm udp オーディオ ストリームを再生しようとしています。xaudio2 を実行するよりも簡単な方法はありますか?
私はxaudio2に非常に慣れていないため、xaudioプレーヤーを作成すると例外がスローされます:
public ref class Player sealed
{
public:
void feedData(Platform::Array<unsigned char> ^byteArray)
{
buffer.AudioBytes = byteArray->Length;
buffer.pAudioData = new byte[byteArray->Length];
memcpy(buffer.pAudioData, &byteArray[0], byteArray->Length);
if( FAILED(hr = SourceVoice->SubmitSourceBuffer( &buffer ) ) )
throw Platform::Exception::CreateException(hr);
}
Player()
{
HRESULT hr;
if ( FAILED(hr = XAudio2Create( &XAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ) ) )
throw Platform::Exception::CreateException(hr);
if ( FAILED(hr = XAudio2->CreateMasteringVoice( &MasterVoice ) ) )
throw Platform::Exception::CreateException(hr);
ZeroMemory(&wfx,sizeof(WAVEFORMATEXTENSIBLE));
wfx.Format.wFormatTag = WAVE_FORMAT_PCM;
wfx.Format.nChannels = 1;
wfx.Format.nSamplesPerSec = 16000;
wfx.Format.nAvgBytesPerSec = 32000;
wfx.Format.nBlockAlign = 2;
wfx.Format.wBitsPerSample = 16;
if( FAILED(hr = XAudio2->CreateSourceVoice( &SourceVoice, (WAVEFORMATEX*)&wfx ) ))
throw Platform::Exception::CreateException(hr);
if ( FAILED(hr = SourceVoice->Start( 0 ) ) )
throw Platform::Exception::CreateException(hr);
}
~Player()
{
MasterVoice->DestroyVoice();
SourceVoice->DestroyVoice();
}
private:
Microsoft::WRL::ComPtr<IXAudio2> XAudio2;
IXAudio2MasteringVoice* MasterVoice;
IXAudio2SourceVoice* SourceVoice;
WAVEFORMATEXTENSIBLE wfx;
XAUDIO2_BUFFER buffer;
};
WinRT コンポーネント dll として実行していますが、次の行で例外が発生します。
if( FAILED(hr = XAudio2->CreateSourceVoice( &SourceVoice, (WAVEFORMATEX*)&wfx ) ))
throw Platform::Exception::CreateException(hr);
デバッガーをステップ実行すると、wfx と SourceVoice の構造が正常に開始されたように見えます。誰かが何が問題なのかを理解するのを手伝ってくれますか?