Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@PaperSloth
Created December 13, 2020 11:17
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/30b1c95baaaca6e7cf40299a1acd3918 to your computer and use it in GitHub Desktop.
Save PaperSloth/30b1c95baaaca6e7cf40299a1acd3918 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 <random>
#include <wrl/client.h>
#include <array>
#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);
// 範囲指定の乱数生成
uint64_t GenerateRandomRange(uint64_t min, uint64_t max)
{
std::random_device device;
static std::mt19937_64 mt64(device());
std::uniform_int_distribution<uint64_t> uniform(min, max);
return uniform(mt64);
}
int main(int argc, char* argv[])
{
if (argc <= 1)
{
wprintf(L"The number of arguments is not enough.\n");
return 1;
}
if (argc > 2)
{
wprintf(L"There are too many arguments, please specify one argument.\n");
return 1;
}
enum class BuildType : uint8_t
{
Start,
Finish
};
const std::array<std::wstring, 8> startArray
{
L"いいコード書いてる?.wav",
L"いっぱいがんばっててえらい!1.wav",
L"がんばれ~1.wav",
L"がんばれっがんばれっ.wav",
L"ちゃ~んとテストした?.wav",
L"ちゃんとテストした?.wav",
L"バグなおったかな?.wav",
L"今度はどうかな?.wav",
};
const std::array<std::wstring, 5> finishArray
{
L"コンパイルおわったよ~!.wav",
L"コンパイルおわり!その調子!.wav",
L"コンパイルおわり!順調かな?.wav",
L"コンパイルおわり!順調かな?2.wav",
L"コンパイル終わり~!その調子~!.wav",
};
BuildType type = BuildType::Start;
std::wstring file_path = L"Resources\\Voice\\";
std::string option = argv[1];
if (option.compare("start") == 0)
{
type = BuildType::Start;
file_path.append(startArray[GenerateRandomRange(0, startArray.size() - 1)]);
}
else if (option.compare("finish") == 0)
{
type = BuildType::Finish;
file_path.append(finishArray[GenerateRandomRange(0, finishArray.size() - 1)]);
}
else
{
wprintf(L"Incorrect argument options.\n");
return 1;
}
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;
}
#if defined(_DEBUG)
XAUDIO2_DEBUG_CONFIGURATION debug = { 0 };
debug.TraceMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS;
debug.BreakMask = XAUDIO2_LOG_ERRORS;
pXAudio2->SetDebugConfiguration(&debug, 0);
#endif
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(), file_path.c_str())))
{
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