diff options
| author | shuffle2 <godisgovernment@gmail.com> | 2014-05-23 17:02:55 -0700 |
|---|---|---|
| committer | shuffle2 <godisgovernment@gmail.com> | 2014-05-23 17:02:55 -0700 |
| commit | ca3002977b6e1efa5d7297886d8e0994a7106e47 (patch) | |
| tree | a31df29ec17db44070ef8245c6a49eb5ab00fef5 /Source/Core/AudioCommon/DSoundStream.cpp | |
| parent | d71e20880f4ab5405f3d46be3452e09a7eaf9e76 (diff) | |
| parent | 4990b8910bc0fe5d576f92396f761a79b3f1a7e3 (diff) | |
Merge pull request #256 from magumagu/dsound-notify
DSound: use DSound notifications to produce sound.
Diffstat (limited to 'Source/Core/AudioCommon/DSoundStream.cpp')
| -rw-r--r-- | Source/Core/AudioCommon/DSoundStream.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Source/Core/AudioCommon/DSoundStream.cpp b/Source/Core/AudioCommon/DSoundStream.cpp index df96a9551f..d25ebf5804 100644 --- a/Source/Core/AudioCommon/DSoundStream.cpp +++ b/Source/Core/AudioCommon/DSoundStream.cpp @@ -29,7 +29,7 @@ bool DSound::CreateBuffer() // Fill out DSound buffer description. dsbdesc.dwSize = sizeof(DSBUFFERDESC); - dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS; + dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY; dsbdesc.dwBufferBytes = bufferSize = BUFSIZE; dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&pcmwf; dsbdesc.guid3DAlgorithm = DS3DALG_DEFAULT; @@ -39,6 +39,20 @@ bool DSound::CreateBuffer() { dsBuffer->SetCurrentPosition(0); dsBuffer->SetVolume(m_volume); + + soundSyncEvent = CreateEvent(NULL, TRUE, FALSE, TEXT("DSound Buffer Notification")); + + IDirectSoundNotify *dsnotify; + dsBuffer->QueryInterface(IID_IDirectSoundNotify, (void**)&dsnotify); + DSBPOSITIONNOTIFY notify_positions[3]; + for (unsigned i = 0; i < ARRAYSIZE(notify_positions); ++i) + { + notify_positions[i].dwOffset = i * (BUFSIZE / ARRAYSIZE(notify_positions)); + notify_positions[i].hEventNotify = soundSyncEvent; + } + dsnotify->SetNotificationPositions(ARRAYSIZE(notify_positions), notify_positions); + dsnotify->Release(); + return true; } else @@ -103,7 +117,7 @@ void DSound::SoundLoop() WriteDataToBuffer(lastPos, (char*)realtimeBuffer, numBytesToRender); lastPos = ModBufferSize(lastPos + numBytesToRender); } - soundSyncEvent.Wait(); + WaitForSingleObject(soundSyncEvent, INFINITE); } } @@ -136,11 +150,6 @@ void DSound::SetVolume(int volume) dsBuffer->SetVolume(m_volume); } -void DSound::Update() -{ - soundSyncEvent.Set(); -} - void DSound::Clear(bool mute) { m_muted = mute; @@ -162,11 +171,12 @@ void DSound::Stop() { threadData = 1; // kick the thread if it's waiting - soundSyncEvent.Set(); + SetEvent(soundSyncEvent); thread.join(); dsBuffer->Stop(); dsBuffer->Release(); ds->Release(); + CloseHandle(soundSyncEvent); } |
