mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-29 01:03:41 +01:00
Remove polling requirement from DSound audio backend
Might as well sleep for a short period instead, same effect really.
This commit is contained in:
1 parent
a6e5d59d9a
commit
21bd50dcb0
8 files changed
+25
-60
No files matched your search
+14
-24
@@ -29,8 +29,8 @@ unsigned int WINAPI DSoundAudioBackend::soundThread(void *param) {
|
||||
}
|
||||
|
||||
bool DSoundAudioBackend::WriteDataToBuffer(DWORD offset, // Our own write cursor.
|
||||
char* soundData, // Start of our data.
|
||||
DWORD soundBytes) { // Size of block to copy.
|
||||
char* soundData, // Start of our data.
|
||||
DWORD soundBytes) { // Size of block to copy.
|
||||
void *ptr1, *ptr2;
|
||||
DWORD numBytes1, numBytes2;
|
||||
// Obtain memory address of write block. This will be in two parts if the block wraps around.
|
||||
@@ -41,15 +41,16 @@ bool DSoundAudioBackend::WriteDataToBuffer(DWORD offset, // Our own write cursor
|
||||
dsBuffer->Restore();
|
||||
hr=dsBuffer->Lock(dwOffset, dwSoundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0);
|
||||
} */
|
||||
if (SUCCEEDED(hr)) {
|
||||
memcpy(ptr1, soundData, numBytes1);
|
||||
if (ptr2)
|
||||
memcpy(ptr2, soundData+numBytes1, numBytes2);
|
||||
// Release the data back to DirectSound.
|
||||
dsBuffer_->Unlock(ptr1, numBytes1, ptr2, numBytes2);
|
||||
return true;
|
||||
if (FAILED(hr)) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
memcpy(ptr1, soundData, numBytes1);
|
||||
if (ptr2)
|
||||
memcpy(ptr2, soundData + numBytes1, numBytes2);
|
||||
// Release the data back to DirectSound.
|
||||
dsBuffer_->Unlock(ptr1, numBytes1, ptr2, numBytes2);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DSoundAudioBackend::CreateBuffer() {
|
||||
@@ -97,7 +98,6 @@ int DSoundAudioBackend::RunThread() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
soundSyncEvent_ = CreateEvent(0, false, false, 0);
|
||||
InitializeCriticalSection(&soundCriticalSection);
|
||||
|
||||
DWORD num1;
|
||||
@@ -115,6 +115,8 @@ int DSoundAudioBackend::RunThread() {
|
||||
|
||||
dsBuffer_->Play(0, 0, DSBPLAY_LOOPING);
|
||||
|
||||
auto ModBufferSize = [&](int x) { return (x + bufferSize_) % bufferSize_; };
|
||||
|
||||
while (!threadData_) {
|
||||
EnterCriticalSection(&soundCriticalSection);
|
||||
|
||||
@@ -135,7 +137,7 @@ int DSoundAudioBackend::RunThread() {
|
||||
}
|
||||
|
||||
LeaveCriticalSection(&soundCriticalSection);
|
||||
WaitForSingleObject(soundSyncEvent_, MAXWAIT);
|
||||
Sleep(5);
|
||||
}
|
||||
dsBuffer_->Stop();
|
||||
|
||||
@@ -146,9 +148,6 @@ int DSoundAudioBackend::RunThread() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
DSoundAudioBackend::DSoundAudioBackend() {
|
||||
}
|
||||
|
||||
DSoundAudioBackend::~DSoundAudioBackend() {
|
||||
if (!ds_)
|
||||
return;
|
||||
@@ -168,10 +167,6 @@ DSoundAudioBackend::~DSoundAudioBackend() {
|
||||
hThread_ = NULL;
|
||||
}
|
||||
|
||||
if (soundSyncEvent_ != NULL) {
|
||||
CloseHandle(soundSyncEvent_);
|
||||
}
|
||||
soundSyncEvent_ = NULL;
|
||||
LeaveCriticalSection(&soundCriticalSection);
|
||||
DeleteCriticalSection(&soundCriticalSection);
|
||||
}
|
||||
@@ -187,8 +182,3 @@ bool DSoundAudioBackend::Init(HWND window, StreamCallback _callback, int sampleR
|
||||
SetThreadPriority(hThread_, THREAD_PRIORITY_ABOVE_NORMAL);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DSoundAudioBackend::Update() {
|
||||
if (soundSyncEvent_ != NULL)
|
||||
SetEvent(soundSyncEvent_);
|
||||
}
|
||||
Reference in new issue
Block a user