Remove dsound audio backend.
There isn't any reason to use dsound over xaudio.
This commit is contained in:
parent
8bb3fa561b
commit
af2405eefd
|
@ -7,7 +7,6 @@
|
||||||
#include "AudioCommon/AOSoundStream.h"
|
#include "AudioCommon/AOSoundStream.h"
|
||||||
#include "AudioCommon/AudioCommon.h"
|
#include "AudioCommon/AudioCommon.h"
|
||||||
#include "AudioCommon/CoreAudioSoundStream.h"
|
#include "AudioCommon/CoreAudioSoundStream.h"
|
||||||
#include "AudioCommon/DSoundStream.h"
|
|
||||||
#include "AudioCommon/Mixer.h"
|
#include "AudioCommon/Mixer.h"
|
||||||
#include "AudioCommon/NullSoundStream.h"
|
#include "AudioCommon/NullSoundStream.h"
|
||||||
#include "AudioCommon/OpenALStream.h"
|
#include "AudioCommon/OpenALStream.h"
|
||||||
|
@ -37,8 +36,6 @@ namespace AudioCommon
|
||||||
soundStream = new OpenALStream(mixer);
|
soundStream = new OpenALStream(mixer);
|
||||||
else if (backend == BACKEND_NULLSOUND && NullSound::isValid())
|
else if (backend == BACKEND_NULLSOUND && NullSound::isValid())
|
||||||
soundStream = new NullSound(mixer);
|
soundStream = new NullSound(mixer);
|
||||||
else if (backend == BACKEND_DIRECTSOUND && DSound::isValid())
|
|
||||||
soundStream = new DSound(mixer, hWnd);
|
|
||||||
else if (backend == BACKEND_XAUDIO2)
|
else if (backend == BACKEND_XAUDIO2)
|
||||||
{
|
{
|
||||||
if (XAudio2::isValid())
|
if (XAudio2::isValid())
|
||||||
|
@ -111,8 +108,6 @@ namespace AudioCommon
|
||||||
|
|
||||||
if (NullSound::isValid())
|
if (NullSound::isValid())
|
||||||
backends.push_back(BACKEND_NULLSOUND);
|
backends.push_back(BACKEND_NULLSOUND);
|
||||||
if (DSound::isValid())
|
|
||||||
backends.push_back(BACKEND_DIRECTSOUND);
|
|
||||||
if (XAudio2_7::isValid() || XAudio2::isValid())
|
if (XAudio2_7::isValid() || XAudio2::isValid())
|
||||||
backends.push_back(BACKEND_XAUDIO2);
|
backends.push_back(BACKEND_XAUDIO2);
|
||||||
if (AOSound::isValid())
|
if (AOSound::isValid())
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
<ClCompile Include="aldlist.cpp" />
|
<ClCompile Include="aldlist.cpp" />
|
||||||
<ClCompile Include="AudioCommon.cpp" />
|
<ClCompile Include="AudioCommon.cpp" />
|
||||||
<ClCompile Include="DPL2Decoder.cpp" />
|
<ClCompile Include="DPL2Decoder.cpp" />
|
||||||
<ClCompile Include="DSoundStream.cpp" />
|
|
||||||
<ClCompile Include="Mixer.cpp" />
|
<ClCompile Include="Mixer.cpp" />
|
||||||
<ClCompile Include="NullSoundStream.cpp" />
|
<ClCompile Include="NullSoundStream.cpp" />
|
||||||
<ClCompile Include="OpenALStream.cpp" />
|
<ClCompile Include="OpenALStream.cpp" />
|
||||||
|
@ -55,7 +54,6 @@
|
||||||
<ClInclude Include="AudioCommon.h" />
|
<ClInclude Include="AudioCommon.h" />
|
||||||
<ClInclude Include="CoreAudioSoundStream.h" />
|
<ClInclude Include="CoreAudioSoundStream.h" />
|
||||||
<ClInclude Include="DPL2Decoder.h" />
|
<ClInclude Include="DPL2Decoder.h" />
|
||||||
<ClInclude Include="DSoundStream.h" />
|
|
||||||
<ClInclude Include="Mixer.h" />
|
<ClInclude Include="Mixer.h" />
|
||||||
<ClInclude Include="NullSoundStream.h" />
|
<ClInclude Include="NullSoundStream.h" />
|
||||||
<ClInclude Include="OpenALStream.h" />
|
<ClInclude Include="OpenALStream.h" />
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="SoundStreams">
|
<Filter Include="SoundStreams">
|
||||||
|
@ -11,9 +11,6 @@
|
||||||
<ClCompile Include="DPL2Decoder.cpp" />
|
<ClCompile Include="DPL2Decoder.cpp" />
|
||||||
<ClCompile Include="Mixer.cpp" />
|
<ClCompile Include="Mixer.cpp" />
|
||||||
<ClCompile Include="WaveFile.cpp" />
|
<ClCompile Include="WaveFile.cpp" />
|
||||||
<ClCompile Include="DSoundStream.cpp">
|
|
||||||
<Filter>SoundStreams</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="NullSoundStream.cpp">
|
<ClCompile Include="NullSoundStream.cpp">
|
||||||
<Filter>SoundStreams</Filter>
|
<Filter>SoundStreams</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -37,9 +34,6 @@
|
||||||
<ClInclude Include="AOSoundStream.h">
|
<ClInclude Include="AOSoundStream.h">
|
||||||
<Filter>SoundStreams</Filter>
|
<Filter>SoundStreams</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="DSoundStream.h">
|
|
||||||
<Filter>SoundStreams</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="NullSoundStream.h">
|
<ClInclude Include="NullSoundStream.h">
|
||||||
<Filter>SoundStreams</Filter>
|
<Filter>SoundStreams</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -32,7 +32,6 @@ if(PULSEAUDIO_FOUND)
|
||||||
endif(PULSEAUDIO_FOUND)
|
endif(PULSEAUDIO_FOUND)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(SRCS ${SRCS} DSoundStream.cpp)
|
|
||||||
set(SRCS ${SRCS} XAudio2Stream.cpp)
|
set(SRCS ${SRCS} XAudio2Stream.cpp)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
|
|
|
@ -1,170 +0,0 @@
|
||||||
// Copyright 2013 Dolphin Emulator Project
|
|
||||||
// Licensed under GPLv2
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <thread>
|
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
#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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,78 +0,0 @@
|
||||||
// Copyright 2013 Dolphin Emulator Project
|
|
||||||
// Licensed under GPLv2
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include "AudioCommon/SoundStream.h"
|
|
||||||
#include "Common/Event.h"
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <Windows.h>
|
|
||||||
#include <mmsystem.h>
|
|
||||||
#include <dsound.h>
|
|
||||||
|
|
||||||
#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
|
|
||||||
};
|
|
|
@ -17,7 +17,6 @@
|
||||||
#define BACKEND_ALSA "ALSA"
|
#define BACKEND_ALSA "ALSA"
|
||||||
#define BACKEND_AOSOUND "AOSound"
|
#define BACKEND_AOSOUND "AOSound"
|
||||||
#define BACKEND_COREAUDIO "CoreAudio"
|
#define BACKEND_COREAUDIO "CoreAudio"
|
||||||
#define BACKEND_DIRECTSOUND "DSound"
|
|
||||||
#define BACKEND_OPENAL "OpenAL"
|
#define BACKEND_OPENAL "OpenAL"
|
||||||
#define BACKEND_PULSEAUDIO "Pulse"
|
#define BACKEND_PULSEAUDIO "Pulse"
|
||||||
#define BACKEND_XAUDIO2 "XAudio2"
|
#define BACKEND_XAUDIO2 "XAudio2"
|
||||||
|
|
|
@ -1004,8 +1004,7 @@ bool CConfigMain::SupportsVolumeChanges(std::string backend)
|
||||||
//FIXME: this one should ask the backend whether it supports it.
|
//FIXME: this one should ask the backend whether it supports it.
|
||||||
// but getting the backend from string etc. is probably
|
// but getting the backend from string etc. is probably
|
||||||
// too much just to enable/disable a stupid slider...
|
// too much just to enable/disable a stupid slider...
|
||||||
return (backend == BACKEND_DIRECTSOUND ||
|
return (backend == BACKEND_COREAUDIO ||
|
||||||
backend == BACKEND_COREAUDIO ||
|
|
||||||
backend == BACKEND_OPENAL ||
|
backend == BACKEND_OPENAL ||
|
||||||
backend == BACKEND_XAUDIO2);
|
backend == BACKEND_XAUDIO2);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue