From af2405eefdee151e653a326d5f50dc27cb5325cc Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sat, 23 Aug 2014 11:18:00 -0700 Subject: [PATCH] Remove dsound audio backend. There isn't any reason to use dsound over xaudio. --- Source/Core/AudioCommon/AudioCommon.cpp | 5 - Source/Core/AudioCommon/AudioCommon.vcxproj | 2 - .../AudioCommon/AudioCommon.vcxproj.filters | 8 +- Source/Core/AudioCommon/CMakeLists.txt | 1 - Source/Core/AudioCommon/DSoundStream.cpp | 170 ------------------ Source/Core/AudioCommon/DSoundStream.h | 78 -------- Source/Core/Core/ConfigManager.h | 1 - Source/Core/DolphinWX/ConfigMain.cpp | 3 +- 8 files changed, 2 insertions(+), 266 deletions(-) delete mode 100644 Source/Core/AudioCommon/DSoundStream.cpp delete mode 100644 Source/Core/AudioCommon/DSoundStream.h diff --git a/Source/Core/AudioCommon/AudioCommon.cpp b/Source/Core/AudioCommon/AudioCommon.cpp index 3550b3cb16ec..270bbec0ebbd 100644 --- a/Source/Core/AudioCommon/AudioCommon.cpp +++ b/Source/Core/AudioCommon/AudioCommon.cpp @@ -7,7 +7,6 @@ #include "AudioCommon/AOSoundStream.h" #include "AudioCommon/AudioCommon.h" #include "AudioCommon/CoreAudioSoundStream.h" -#include "AudioCommon/DSoundStream.h" #include "AudioCommon/Mixer.h" #include "AudioCommon/NullSoundStream.h" #include "AudioCommon/OpenALStream.h" @@ -37,8 +36,6 @@ namespace AudioCommon soundStream = new OpenALStream(mixer); else if (backend == BACKEND_NULLSOUND && NullSound::isValid()) soundStream = new NullSound(mixer); - else if (backend == BACKEND_DIRECTSOUND && DSound::isValid()) - soundStream = new DSound(mixer, hWnd); else if (backend == BACKEND_XAUDIO2) { if (XAudio2::isValid()) @@ -111,8 +108,6 @@ namespace AudioCommon if (NullSound::isValid()) backends.push_back(BACKEND_NULLSOUND); - if (DSound::isValid()) - backends.push_back(BACKEND_DIRECTSOUND); if (XAudio2_7::isValid() || XAudio2::isValid()) backends.push_back(BACKEND_XAUDIO2); if (AOSound::isValid()) diff --git a/Source/Core/AudioCommon/AudioCommon.vcxproj b/Source/Core/AudioCommon/AudioCommon.vcxproj index 4bf2996e44a1..d80bed06d6e4 100644 --- a/Source/Core/AudioCommon/AudioCommon.vcxproj +++ b/Source/Core/AudioCommon/AudioCommon.vcxproj @@ -38,7 +38,6 @@ - @@ -55,7 +54,6 @@ - diff --git a/Source/Core/AudioCommon/AudioCommon.vcxproj.filters b/Source/Core/AudioCommon/AudioCommon.vcxproj.filters index d79b6928286a..2832422073f7 100644 --- a/Source/Core/AudioCommon/AudioCommon.vcxproj.filters +++ b/Source/Core/AudioCommon/AudioCommon.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -11,9 +11,6 @@ - - SoundStreams - SoundStreams @@ -37,9 +34,6 @@ SoundStreams - - SoundStreams - SoundStreams diff --git a/Source/Core/AudioCommon/CMakeLists.txt b/Source/Core/AudioCommon/CMakeLists.txt index ab4207fa8708..8423164226de 100644 --- a/Source/Core/AudioCommon/CMakeLists.txt +++ b/Source/Core/AudioCommon/CMakeLists.txt @@ -32,7 +32,6 @@ if(PULSEAUDIO_FOUND) endif(PULSEAUDIO_FOUND) if(WIN32) - set(SRCS ${SRCS} DSoundStream.cpp) set(SRCS ${SRCS} XAudio2Stream.cpp) endif(WIN32) diff --git a/Source/Core/AudioCommon/DSoundStream.cpp b/Source/Core/AudioCommon/DSoundStream.cpp deleted file mode 100644 index dd5675428627..000000000000 --- a/Source/Core/AudioCommon/DSoundStream.cpp +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include -#include -#include - -#include "AudioCommon/AudioCommon.h" -#include "AudioCommon/DSoundStream.h" -#include "Common/Thread.h" - -bool DSound::CreateBuffer() -{ - PCMWAVEFORMAT pcmwf; - DSBUFFERDESC dsbdesc; - - memset(&pcmwf, 0, sizeof(PCMWAVEFORMAT)); - memset(&dsbdesc, 0, sizeof(DSBUFFERDESC)); - - pcmwf.wf.wFormatTag = WAVE_FORMAT_PCM; - pcmwf.wf.nChannels = 2; - pcmwf.wf.nSamplesPerSec = m_mixer->GetSampleRate(); - pcmwf.wf.nBlockAlign = 4; - pcmwf.wf.nAvgBytesPerSec = pcmwf.wf.nSamplesPerSec * pcmwf.wf.nBlockAlign; - pcmwf.wBitsPerSample = 16; - - // Fill out DSound buffer description. - dsbdesc.dwSize = sizeof(DSBUFFERDESC); - dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRLVOLUME | DSBCAPS_GLOBALFOCUS; - dsbdesc.dwBufferBytes = bufferSize = BUFSIZE; - dsbdesc.lpwfxFormat = (WAVEFORMATEX *)&pcmwf; - dsbdesc.guid3DAlgorithm = DS3DALG_DEFAULT; - - HRESULT res = ds->CreateSoundBuffer(&dsbdesc, &dsBuffer, nullptr); - if (SUCCEEDED(res)) - { - dsBuffer->SetCurrentPosition(0); - dsBuffer->SetVolume(m_volume); - return true; - } - else - { - // Failed. - PanicAlertT("Sound buffer creation failed: %08x", res); - dsBuffer = nullptr; - return false; - } -} - -bool DSound::WriteDataToBuffer(DWORD dwOffset, // Our own write cursor. - char* soundData, // Start of our data. - DWORD dwSoundBytes) // Size of block to copy. -{ - // I want to record the regular audio to, how do I do that? - - void *ptr1, *ptr2; - DWORD numBytes1, numBytes2; - // Obtain memory address of write block. This will be in two parts if the block wraps around. - HRESULT hr = dsBuffer->Lock(dwOffset, dwSoundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0); - - // If the buffer was lost, restore and retry lock. - if (DSERR_BUFFERLOST == hr) - { - dsBuffer->Restore(); - hr = dsBuffer->Lock(dwOffset, dwSoundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0); - } - if (SUCCEEDED(hr)) - { - memcpy(ptr1, soundData, numBytes1); - if (ptr2 != 0) - memcpy(ptr2, soundData + numBytes1, numBytes2); - - // Release the data back to DirectSound. - dsBuffer->Unlock(ptr1, numBytes1, ptr2, numBytes2); - return true; - } - - return false; -} - -// The audio thread. -void DSound::SoundLoop() -{ - Common::SetCurrentThreadName("Audio thread - dsound"); - - currentPos = 0; - lastPos = 0; - dsBuffer->Play(0, 0, DSBPLAY_LOOPING); - - while (!threadData) - { - // No blocking inside the csection - dsBuffer->GetCurrentPosition((DWORD*)¤tPos, 0); - int numBytesToRender = FIX128(ModBufferSize(currentPos - lastPos)); - if (numBytesToRender >= 256) - { - if (numBytesToRender > sizeof(realtimeBuffer)) - PanicAlert("soundThread: too big render call"); - m_mixer->Mix(realtimeBuffer, numBytesToRender / 4); - WriteDataToBuffer(lastPos, (char*)realtimeBuffer, numBytesToRender); - lastPos = ModBufferSize(lastPos + numBytesToRender); - } - soundSyncEvent.Wait(); - } -} - -bool DSound::Start() -{ - if (FAILED(DirectSoundCreate8(0, &ds, 0))) - return false; - if (hWnd) - { - HRESULT hr = ds->SetCooperativeLevel((HWND)hWnd, DSSCL_PRIORITY); - } - if (!CreateBuffer()) - return false; - - DWORD num1; - short* p1; - dsBuffer->Lock(0, bufferSize, (void* *)&p1, &num1, 0, 0, DSBLOCK_ENTIREBUFFER); - memset(p1, 0, num1); - dsBuffer->Unlock(p1, num1, 0, 0); - thread = std::thread(&DSound::SoundLoop, this); - return true; -} - -void DSound::SetVolume(int volume) -{ - // This is in "dBA attenuation" from 0 to -10000, logarithmic - m_volume = (int)floor(log10((float)volume) * 5000.0f) - 10000; - - if (dsBuffer != nullptr) - dsBuffer->SetVolume(m_volume); -} - -void DSound::Update() -{ - soundSyncEvent.Set(); -} - -void DSound::Clear(bool mute) -{ - m_muted = mute; - - if (dsBuffer != nullptr) - { - if (m_muted) - { - dsBuffer->Stop(); - } - else - { - dsBuffer->Play(0, 0, DSBPLAY_LOOPING); - } - } -} - -void DSound::Stop() -{ - threadData = 1; - // kick the thread if it's waiting - soundSyncEvent.Set(); - - thread.join(); - dsBuffer->Stop(); - dsBuffer->Release(); - ds->Release(); -} - diff --git a/Source/Core/AudioCommon/DSoundStream.h b/Source/Core/AudioCommon/DSoundStream.h deleted file mode 100644 index 6ce946c4a2f4..000000000000 --- a/Source/Core/AudioCommon/DSoundStream.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#pragma once - -#include - -#include "AudioCommon/SoundStream.h" -#include "Common/Event.h" - -#ifdef _WIN32 -#include -#include -#include - -#define BUFSIZE (1024 * 8 * 4) -#endif - -class DSound final : public SoundStream -{ -#ifdef _WIN32 - std::thread thread; - Common::Event soundSyncEvent; - void *hWnd; - - IDirectSound8* ds; - IDirectSoundBuffer* dsBuffer; - - int bufferSize; //i bytes - int m_volume; - - // playback position - int currentPos; - int lastPos; - short realtimeBuffer[BUFSIZE / sizeof(short)]; - - inline int FIX128(int x) - { - return x & (~127); - } - - inline int ModBufferSize(int x) - { - return (x + bufferSize) % bufferSize; - } - - bool CreateBuffer(); - bool WriteDataToBuffer(DWORD dwOffset, char* soundData, DWORD dwSoundBytes); - -public: - DSound(CMixer *mixer, void *_hWnd) - : SoundStream(mixer) - , bufferSize(0) - , currentPos(0) - , lastPos(0) - , dsBuffer(0) - , ds(0) - , hWnd(_hWnd) - {} - - virtual ~DSound() {} - - virtual bool Start(); - virtual void SoundLoop(); - virtual void SetVolume(int volume); - virtual void Stop(); - virtual void Clear(bool mute); - static bool isValid() { return true; } - virtual void Update(); - -#else -public: - DSound(CMixer *mixer, void *_hWnd) - : SoundStream(mixer) - {} -#endif -}; diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index e867a304d884..eeadd35a2966 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -17,7 +17,6 @@ #define BACKEND_ALSA "ALSA" #define BACKEND_AOSOUND "AOSound" #define BACKEND_COREAUDIO "CoreAudio" -#define BACKEND_DIRECTSOUND "DSound" #define BACKEND_OPENAL "OpenAL" #define BACKEND_PULSEAUDIO "Pulse" #define BACKEND_XAUDIO2 "XAudio2" diff --git a/Source/Core/DolphinWX/ConfigMain.cpp b/Source/Core/DolphinWX/ConfigMain.cpp index f251595856e2..34261e87922d 100644 --- a/Source/Core/DolphinWX/ConfigMain.cpp +++ b/Source/Core/DolphinWX/ConfigMain.cpp @@ -1004,8 +1004,7 @@ bool CConfigMain::SupportsVolumeChanges(std::string backend) //FIXME: this one should ask the backend whether it supports it. // but getting the backend from string etc. is probably // too much just to enable/disable a stupid slider... - return (backend == BACKEND_DIRECTSOUND || - backend == BACKEND_COREAUDIO || + return (backend == BACKEND_COREAUDIO || backend == BACKEND_OPENAL || backend == BACKEND_XAUDIO2); }