Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- internal void
- Win32InitWASAPI(void)
- {
- win32_audio *Result = 0;
- Result = (win32_audio *) Win32AllocateMemory(sizeof(win32_audio));
- ZeroMemory(Result, sizeof(win32_audio));
- IMMDeviceEnumerator *DeviceEnumerator = 0;
- HRESULT Result1 = CoCreateInstance(__uuidof(MMDeviceEnumerator), 0,
- CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
- (void **)&DeviceEnumerator);
- if(Result1 == S_OK)
- {
- IMMDevice *Device = 0;
- HRESULT Result2 = DeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &Device);
- if(Result2 == S_OK)
- {
- HRESULT Result3 = Device->Activate(__uuidof(IAudioClient), CLSCTX_ALL,
- 0, (void **)&Result->WriteAudioClient);
- if(Result3 == S_OK)
- {
- // NOTE(zak): This is just a default normal PCM format
- // nothing special really. We might wanna change the SamplesPerSec,
- // and BitsPerSample when we get real sound effects and music
- // into the game
- WAVEFORMATEX WaveFormat = {0};
- WaveFormat.wFormatTag = WAVE_FORMAT_PCM;
- WaveFormat.nChannels = 2;
- WaveFormat.nSamplesPerSec = 44100;
- WaveFormat.wBitsPerSample = 16;
- WaveFormat.nBlockAlign = (WaveFormat.nChannels * WaveFormat.wBitsPerSample) / 8;
- WaveFormat.nAvgBytesPerSec = WaveFormat.nSamplesPerSec * WaveFormat.nBlockAlign;
- Result->SamplesPerSecond = WaveFormat.nSamplesPerSec;
- Result->ChannelCount = WaveFormat.nChannels;
- REFERENCE_TIME TimeRequested = 10000000;
- HRESULT Result4 = Result->WriteAudioClient->Initialize(AUDCLNT_SHAREMODE_SHARED,
- AUDCLNT_STREAMFLAGS_EVENTCALLBACK|AUDCLNT_STREAMFLAGS_RATEADJUST | AUDCLNT_STREAMFLAGS_AUTOCONVERTPCM,
- (WaveFormat.nSamplesPerSec * (sizeof(s16) * 2)),
- 0,
- &WaveFormat,
- 0);
- if(Result4 == S_OK)
- {
- HRESULT Result5 = Result->WriteAudioClient->GetService(__uuidof(IAudioRenderClient),
- (void **)&Result->AudioRenderClient);
- if(Result5 == S_OK)
- {
- SAFE_RELEASE(DeviceEnumerator);
- CreateThread(0, 0, Win32AudioThreadProc, Result, 0, 0);
- }
- else
- {
- WriteCOMErrorToLog("Failed to GetService for AudioRenderClient with error", Result5);
- }
- }
- else
- {
- WriteCOMErrorToLog("Failed to Initialize WriteAudioClient with error", Result4);
- }
- }
- else
- {
- WriteCOMErrorToLog("Failed to Activate AudioDevice and get WriteAudioClient with error", Result3);
- }
- }
- else
- {
- WriteCOMErrorToLog("GetDefaultAudioEndpoint failed with error", Result2);
- }
- }
- else
- {
- WriteCOMErrorToLog("CoCreateInstance failed to create MMDeviceEnumerator with error", Result1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement