From 0af0929a88728151390a0ffb8e8e83807d3d1d26 Mon Sep 17 00:00:00 2001 From: skidau Date: Tue, 2 Nov 2010 00:16:49 +0000 Subject: [PATCH] Re-implemented the NullSound back-end. Allows Dolphin to be used on hosts with no sound hardware. Emulates strict DSP timing in the DSP HLE plugin. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6329 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/AudioCommon/AudioCommon.vcproj | 8 ++++ Source/Core/AudioCommon/Src/AudioCommon.cpp | 5 ++ .../Core/AudioCommon/Src/AudioCommonConfig.h | 1 + .../Core/AudioCommon/Src/NullSoundStream.cpp | 48 +++++++++++++++++++ Source/Core/AudioCommon/Src/NullSoundStream.h | 48 +++++++++++++++++++ Source/Core/AudioCommon/Src/SConscript | 1 + 6 files changed, 111 insertions(+) create mode 100644 Source/Core/AudioCommon/Src/NullSoundStream.cpp create mode 100644 Source/Core/AudioCommon/Src/NullSoundStream.h diff --git a/Source/Core/AudioCommon/AudioCommon.vcproj b/Source/Core/AudioCommon/AudioCommon.vcproj index c8f1ec1648..e158baea4f 100644 --- a/Source/Core/AudioCommon/AudioCommon.vcproj +++ b/Source/Core/AudioCommon/AudioCommon.vcproj @@ -413,6 +413,14 @@ + + + + diff --git a/Source/Core/AudioCommon/Src/AudioCommon.cpp b/Source/Core/AudioCommon/Src/AudioCommon.cpp index 774d499f1c..bef8b2e6f9 100644 --- a/Source/Core/AudioCommon/Src/AudioCommon.cpp +++ b/Source/Core/AudioCommon/Src/AudioCommon.cpp @@ -17,6 +17,7 @@ #include "AudioCommon.h" #include "Mixer.h" +#include "NullSoundStream.h" #include "DSoundStream.h" #include "AOSoundStream.h" #include "AlsaSoundStream.h" @@ -37,6 +38,8 @@ namespace AudioCommon std::string backend = ac_Config.sBackend; if (backend == BACKEND_OPENAL && OpenALStream::isValid()) soundStream = new OpenALStream(mixer); + else if (backend == BACKEND_NULLSOUND && NullSound::isValid()) + soundStream = new NullSound(mixer, g_dspInitialize.hWnd); else if (backend == BACKEND_DIRECTSOUND && DSound::isValid()) soundStream = new DSound(mixer, g_dspInitialize.hWnd); else if (backend == BACKEND_AOSOUND && AOSound::isValid()) @@ -91,6 +94,8 @@ namespace AudioCommon { std::vector backends; + if (NullSound::isValid()) + backends.push_back(BACKEND_NULLSOUND); if (DSound::isValid()) backends.push_back(BACKEND_DIRECTSOUND); if (OpenALStream::isValid()) diff --git a/Source/Core/AudioCommon/Src/AudioCommonConfig.h b/Source/Core/AudioCommon/Src/AudioCommonConfig.h index 9f1d1f2915..c42bf0b569 100644 --- a/Source/Core/AudioCommon/Src/AudioCommonConfig.h +++ b/Source/Core/AudioCommon/Src/AudioCommonConfig.h @@ -22,6 +22,7 @@ #include "IniFile.h" // Backend Types +#define BACKEND_NULLSOUND "No audio output" #define BACKEND_COREAUDIO "CoreAudio" #define BACKEND_DIRECTSOUND "DSound" #define BACKEND_AOSOUND "AOSound" diff --git a/Source/Core/AudioCommon/Src/NullSoundStream.cpp b/Source/Core/AudioCommon/Src/NullSoundStream.cpp new file mode 100644 index 0000000000..f058d701d5 --- /dev/null +++ b/Source/Core/AudioCommon/Src/NullSoundStream.cpp @@ -0,0 +1,48 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include "AudioCommon.h" +#include "NullSoundStream.h" + +void NullSound::SoundLoop() +{ +} + +bool NullSound::Start() +{ + return true; +} + +void NullSound::SetVolume(int volume) +{ +} + +void NullSound::Update() +{ + // This should equal AUDIO_DMA_PERIOD. TODO: Fix after DSP merge + int numBytesToRender = 32000 * 4 / 32; + m_mixer->Mix(realtimeBuffer, numBytesToRender / 4); +} + +void NullSound::Clear(bool mute) +{ + m_muted = mute; +} + +void NullSound::Stop() +{ +} diff --git a/Source/Core/AudioCommon/Src/NullSoundStream.h b/Source/Core/AudioCommon/Src/NullSoundStream.h new file mode 100644 index 0000000000..215ca10af8 --- /dev/null +++ b/Source/Core/AudioCommon/Src/NullSoundStream.h @@ -0,0 +1,48 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef _NULLSOUNDSTREAM_H_ +#define _NULLSOUNDSTREAM_H_ + +#include "SoundStream.h" +#include "Thread.h" + +#define BUF_SIZE (48000 * 4 / 32) + +class NullSound : public SoundStream +{ + // playback position + short realtimeBuffer[BUF_SIZE / sizeof(short)]; + +public: + NullSound(CMixer *mixer, void *hWnd = NULL) + : SoundStream(mixer) + {} + + virtual ~NullSound() {} + + 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 bool usesMixer() const { return true; } + virtual void Update(); +}; + +#endif //_NULLSOUNDSTREAM_H_ diff --git a/Source/Core/AudioCommon/Src/SConscript b/Source/Core/AudioCommon/Src/SConscript index 581ce358f9..9f8fd4a67d 100644 --- a/Source/Core/AudioCommon/Src/SConscript +++ b/Source/Core/AudioCommon/Src/SConscript @@ -8,6 +8,7 @@ files = [ 'WaveFile.cpp', 'Mixer.cpp', 'AudioCommon.cpp', + 'NullSoundStream.cpp', ] if sys.platform == 'darwin':