From d9285a2babea7d86933585b9bb8e23b0f045ce26 Mon Sep 17 00:00:00 2001 From: bgk Date: Sun, 20 Feb 2011 09:25:07 +0000 Subject: [PATCH] SDL: Allow vbam to run on systems without an audio device. Thanks to jcranmer for the patch. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@980 a31d4220-a93d-0410-bf67-fe4944624d44 --- debian/control | 2 +- src/common/SoundSDL.cpp | 18 ++++++++++++++++-- src/common/SoundSDL.h | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/debian/control b/debian/control index df5268a7..443f388a 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: vbam Section: otherosfs Priority: optional Maintainer: Fernando Tarlá Cardoso Lemos -Build-Depends: debhelper (>= 7), cmake, nasm [i386 amd64], libsdl1.2-dev, libgl-dev, libgtkmm-2.4-dev, libgtkglextmm-x11-1.2-dev, libglademm-2.4-dev, libsfml-dev +Build-Depends: debhelper (>= 7), cmake, nasm [i386 amd64], libsdl1.2-dev, libgl-dev, libgtkmm-2.4-dev, libgtkglextmm-x11-1.2-dev, libsfml-dev Standards-Version: 3.8.1 Homepage: http://www.vbam.com diff --git a/src/common/SoundSDL.cpp b/src/common/SoundSDL.cpp index 8733ca5c..3afbde09 100644 --- a/src/common/SoundSDL.cpp +++ b/src/common/SoundSDL.cpp @@ -24,7 +24,8 @@ extern bool speedup; const float SoundSDL::_delay = 0.1f; SoundSDL::SoundSDL(): - _rbuf(0) + _rbuf(0), + _initialized(false) { } @@ -36,7 +37,7 @@ void SoundSDL::soundCallback(void *data, u8 *stream, int len) void SoundSDL::read(u16 * stream, int length) { - if (length <= 0 || !emulating) + if (!_initialized || length <= 0 || !emulating) return; SDL_mutexP(_mutex); @@ -49,6 +50,9 @@ void SoundSDL::read(u16 * stream, int length) void SoundSDL::write(u16 * finalWave, int length) { + if (!_initialized) + return; + if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING) SDL_PauseAudio(0); @@ -104,12 +108,16 @@ bool SoundSDL::init(long sampleRate) _cond = SDL_CreateCond(); _mutex = SDL_CreateMutex(); + _initialized = true; return true; } SoundSDL::~SoundSDL() { + if (!_initialized) + return; + SDL_mutexP(_mutex); int iSave = emulating; emulating = 0; @@ -129,11 +137,17 @@ SoundSDL::~SoundSDL() void SoundSDL::pause() { + if (!_initialized) + return; + SDL_PauseAudio(1); } void SoundSDL::resume() { + if (!_initialized) + return; + SDL_PauseAudio(0); } diff --git a/src/common/SoundSDL.h b/src/common/SoundSDL.h index 34c2b729..3d94c123 100644 --- a/src/common/SoundSDL.h +++ b/src/common/SoundSDL.h @@ -41,6 +41,8 @@ private: SDL_cond * _cond; SDL_mutex * _mutex; + bool _initialized; + // Defines what delay in seconds we keep in the sound buffer static const float _delay;