Skip to content

Commit

Permalink
Merge pull request #440 from magumagu/dsound-revert
Browse files Browse the repository at this point in the history
Revert "DSound: use DSound notifications to produce sound."
  • Loading branch information
neobrain committed Jun 13, 2014
2 parents a8f32ad + 87a804f commit 2f6e559
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
26 changes: 8 additions & 18 deletions Source/Core/AudioCommon/DSoundStream.cpp
Expand Up @@ -29,7 +29,7 @@ bool DSound::CreateBuffer()

// Fill out DSound buffer description.
dsbdesc.dwSize = sizeof(DSBUFFERDESC);
dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS | DSBCAPS_CTRLPOSITIONNOTIFY;
dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS;
dsbdesc.dwBufferBytes = bufferSize = BUFSIZE;
dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&pcmwf;
dsbdesc.guid3DAlgorithm = DS3DALG_DEFAULT;
Expand All @@ -39,20 +39,6 @@ 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
Expand Down Expand Up @@ -117,7 +103,7 @@ void DSound::SoundLoop()
WriteDataToBuffer(lastPos, (char*)realtimeBuffer, numBytesToRender);
lastPos = ModBufferSize(lastPos + numBytesToRender);
}
WaitForSingleObject(soundSyncEvent, INFINITE);
soundSyncEvent.Wait();
}
}

Expand Down Expand Up @@ -150,6 +136,11 @@ void DSound::SetVolume(int volume)
dsBuffer->SetVolume(m_volume);
}

void DSound::Update()
{
soundSyncEvent.Set();
}

void DSound::Clear(bool mute)
{
m_muted = mute;
Expand All @@ -171,12 +162,11 @@ void DSound::Stop()
{
threadData = 1;
// kick the thread if it's waiting
SetEvent(soundSyncEvent);
soundSyncEvent.Set();

thread.join();
dsBuffer->Stop();
dsBuffer->Release();
ds->Release();
CloseHandle(soundSyncEvent);
}

5 changes: 3 additions & 2 deletions Source/Core/AudioCommon/DSoundStream.h
Expand Up @@ -13,14 +13,14 @@
#include <mmsystem.h>
#include <dsound.h>

#define BUFSIZE (256 * 8 * 4)
#define BUFSIZE (1024 * 8 * 4)
#endif

class DSound final : public SoundStream
{
#ifdef _WIN32
std::thread thread;
HANDLE soundSyncEvent;
Common::Event soundSyncEvent;
void *hWnd;

IDirectSound8* ds;
Expand Down Expand Up @@ -66,6 +66,7 @@ class DSound final : public SoundStream
virtual void Stop();
virtual void Clear(bool mute);
static bool isValid() { return true; }
virtual void Update();

#else
public:
Expand Down

0 comments on commit 2f6e559

Please sign in to comment.