Skip to content

Instantly share code, notes, and snippets.

@PaperSloth
Created December 13, 2020 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaperSloth/187312edf82aaacefa086cfad9187acc to your computer and use it in GitHub Desktop.
Save PaperSloth/187312edf82aaacefa086cfad9187acc to your computer and use it in GitHub Desktop.
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <iostream>
#include <xaudio2.h>
#include <string>
#include <wrl/client.h>
#include "WAVFileReader.h"
#pragma comment(lib,"xaudio2.lib")
HRESULT PlayWave(_In_ IXAudio2* pXaudio2, _In_z_ LPCWSTR szFilename);
HRESULT FindMediaFileCch(_Out_writes_(cchDest) WCHAR* strDestPath, _In_ int cchDest, _In_z_ LPCWSTR strFilename);
int main(int argc, char* argv[])
{
Microsoft::WRL::ComPtr<IXAudio2> pXAudio2 = nullptr;
UINT32 flags = 0;
HRESULT hr = XAudio2Create(&pXAudio2, flags);
if (FAILED(hr))
{
wprintf(L"Failed to init XAudio2 engine: %#X\n", hr);
return 1;
}
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
IXAudio2MasteringVoice* pMasteringVoice = nullptr;
if (FAILED(hr = pXAudio2->CreateMasteringVoice(&pMasteringVoice)))
{
wprintf(L"Failed creating mastering voice: %#X\n", hr);
CoUninitialize();
return 1;
}
if (FAILED(hr = PlayWave(pXAudio2.Get(), L"Resources\\Voice\\再生したよ~!.wav")))
{
wprintf(L"Failed creating source voice: %#X\n", hr);
CoUninitialize();
return 1;
}
pMasteringVoice->DestroyVoice();
CoUninitialize();
return 0;
}
_Use_decl_annotations_
HRESULT PlayWave(IXAudio2* pXaudio2, LPCWSTR szFilename)
{
// 省略
}
_Use_decl_annotations_
HRESULT FindMediaFileCch(WCHAR* strDestPath, int cchDest, LPCWSTR strFilename)
{
// 省略
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment