Created
August 17, 2011 20:04
-
-
Save Themaister/1152464 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From b027713ef8ccc7f1150484ec42bf2628764ac5e7 Mon Sep 17 00:00:00 2001 | |
From: Themaister <[email protected]> | |
Date: Wed, 17 Aug 2011 22:03:32 +0200 | |
Subject: [PATCH] Use events in XAudio2 for more sane syncing. | |
--- | |
bsnes/ruby/audio/xaudio2.cpp | 13 ++++++++++++- | |
1 files changed, 12 insertions(+), 1 deletions(-) | |
diff --git a/bsnes/ruby/audio/xaudio2.cpp b/bsnes/ruby/audio/xaudio2.cpp | |
index d629859..a69087b 100755 | |
--- a/bsnes/ruby/audio/xaudio2.cpp | |
+++ b/bsnes/ruby/audio/xaudio2.cpp | |
@@ -13,6 +13,7 @@ public: | |
IXAudio2 *pXAudio2; | |
IXAudio2MasteringVoice* pMasterVoice; | |
IXAudio2SourceVoice *pSourceVoice; | |
+ HANDLE hEvent; | |
// inherited from IXAudio2VoiceCallback | |
STDMETHODIMP_(void) OnBufferStart(void *pBufferContext){} | |
@@ -93,7 +94,7 @@ public: | |
if(settings.synchronize == true) { | |
//wait until there is at least one other free buffer for the next sample | |
while(device.submitbuffers == device.buffers - 1) { | |
- //Sleep(0); | |
+ WaitForSingleObject(hEvent, INFINITE); | |
} | |
} else { //we need one free buffer for the next sample, so ignore the current contents | |
return; | |
@@ -121,6 +122,10 @@ public: | |
bool init() { | |
term(); | |
+ if (!hEvent) { | |
+ hEvent = CreateEvent(0, false, false, 0); | |
+ } | |
+ | |
device.buffers = 8; | |
device.latency = settings.frequency * settings.latency / device.buffers / 1000.0 + 0.5; | |
device.buffer = new uint32_t[device.latency * device.buffers]; | |
@@ -173,16 +178,22 @@ public: | |
delete[] device.buffer; | |
device.buffer = 0; | |
} | |
+ if(hEvent) { | |
+ CloseHandle(hEvent); | |
+ hEvent = 0; | |
+ } | |
} | |
STDMETHODIMP_(void) OnBufferEnd(void *pBufferContext) { | |
InterlockedDecrement(&device.submitbuffers); | |
+ SetEvent(hEvent); | |
} | |
pAudioXAudio2() { | |
pXAudio2 = 0; | |
pMasterVoice = 0; | |
pSourceVoice = 0; | |
+ hEvent = 0; | |
device.buffer = 0; | |
device.bufferoffset = 0; | |
-- | |
1.7.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment