BACKENDS: Added an abstract MixerManager class

This commit is contained in:
Cameron Cawley 2019-11-30 15:10:52 +00:00 committed by Eugene Sandulenko
parent 7745ffdac1
commit 697d1a8672
7 changed files with 79 additions and 33 deletions

67
backends/mixer/mixer.h Normal file
View File

@ -0,0 +1,67 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* 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; either version 2
* of the License, or (at your option) any later version.
*
* 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef BACKENDS_MIXER_ABSTRACT_H
#define BACKENDS_MIXER_ABSTRACT_H
#include "audio/mixer_intern.h"
/**
* Abstract class for mixer manager. Subclasses
* implement the real functionality.
*/
class MixerManager {
public:
MixerManager() : _mixer(0), _audioSuspended(false) {}
virtual ~MixerManager() { delete _mixer; }
/**
* Initialize and setups the mixer
*/
virtual void init() = 0;
/**
* Get the audio mixer implementation
*/
Audio::Mixer *getMixer() { return (Audio::Mixer *)_mixer; }
// Used by LinuxMoto Port
/**
* Pauses the audio system
*/
virtual void suspendAudio() = 0;
/**
* Resumes the audio system
*/
virtual int resumeAudio() = 0;
protected:
/** The mixer implementation */
Audio::MixerImpl *_mixer;
/** State of the audio system */
bool _audioSuspended;
};
#endif

View File

@ -38,21 +38,12 @@
#define SAMPLES_PER_SEC 44100
#endif
SdlMixerManager::SdlMixerManager()
:
_mixer(0),
_audioSuspended(false) {
}
SdlMixerManager::~SdlMixerManager() {
_mixer->setReady(false);
SDL_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
delete _mixer;
}
void SdlMixerManager::init() {

View File

@ -24,7 +24,7 @@
#define BACKENDS_MIXER_SDL_H
#include "backends/platform/sdl/sdl-sys.h"
#include "audio/mixer_intern.h"
#include "backends/mixer/mixer.h"
/**
* SDL mixer manager. It wraps the actual implementation
@ -32,9 +32,8 @@
* the SDL audio subsystem and the callback for the
* audio mixer implementation.
*/
class SdlMixerManager {
class SdlMixerManager : public MixerManager {
public:
SdlMixerManager();
virtual ~SdlMixerManager();
/**
@ -42,11 +41,6 @@ public:
*/
virtual void init();
/**
* Get the audio mixer implementation
*/
Audio::Mixer *getMixer() { return (Audio::Mixer *)_mixer; }
// Used by Event recorder
/**
@ -60,18 +54,12 @@ public:
virtual int resumeAudio();
protected:
/** The mixer implementation */
Audio::MixerImpl *_mixer;
/**
* The obtained audio specification after opening the
* audio system.
*/
SDL_AudioSpec _obtained;
/** State of the audio system */
bool _audioSuspended;
/**
* Returns the desired audio specification
*/

View File

@ -546,7 +546,7 @@ Audio::Mixer *OSystem_SDL::getMixer() {
return getMixerManager()->getMixer();
}
SdlMixerManager *OSystem_SDL::getMixerManager() {
MixerManager *OSystem_SDL::getMixerManager() {
assert(_mixerManager);
#ifdef ENABLE_EVENTRECORDER

View File

@ -53,7 +53,7 @@ public:
* that returns Audio::Mixer. The Mixer Manager is a SDL wrapper class
* for the Audio::Mixer. Used by other managers.
*/
virtual SdlMixerManager *getMixerManager();
virtual MixerManager *getMixerManager();
virtual bool hasFeature(Feature f) override;
@ -111,7 +111,7 @@ protected:
* Mixer manager that configures and setups SDL for
* the wrapped Audio::Mixer, the true mixer.
*/
SdlMixerManager *_mixerManager;
MixerManager *_mixerManager;
/**
* The event source we use for obtaining SDL events.

View File

@ -31,7 +31,7 @@ DECLARE_SINGLETON(GUI::EventRecorder);
#include "common/debug-channels.h"
#include "backends/timer/sdl/sdl-timer.h"
#include "backends/mixer/sdl/sdl-mixer.h"
#include "backends/mixer/mixer.h"
#include "common/config-manager.h"
#include "common/md5.h"
#include "gui/gui-manager.h"
@ -349,7 +349,7 @@ bool EventRecorder::checkGameHash(const ADGameDescription *gameDesc) {
return true;
}
void EventRecorder::registerMixerManager(SdlMixerManager *mixerManager) {
void EventRecorder::registerMixerManager(MixerManager *mixerManager) {
_realMixerManager = mixerManager;
}
@ -362,7 +362,7 @@ void EventRecorder::switchMixer() {
}
}
SdlMixerManager *EventRecorder::getMixerManager() {
MixerManager *EventRecorder::getMixerManager() {
if (_recordMode == kPassthrough) {
return _realMixerManager;
} else {

View File

@ -36,7 +36,7 @@
#include "common/mutex.h"
#include "common/array.h"
#include "common/memstream.h"
#include "backends/mixer/sdl/sdl-mixer.h"
#include "backends/mixer/mixer.h"
#include "common/hashmap.h"
#include "common/hash-str.h"
#include "backends/timer/sdl/sdl-timer.h"
@ -142,10 +142,10 @@ public:
_needRedraw = redraw;
}
void registerMixerManager(SdlMixerManager *mixerManager);
void registerMixerManager(MixerManager *mixerManager);
void registerTimerManager(DefaultTimerManager *timerManager);
SdlMixerManager *getMixerManager();
MixerManager *getMixerManager();
DefaultTimerManager *getTimerManager();
void deleteRecord(const Common::String& fileName);
@ -187,7 +187,7 @@ private:
Common::String _name;
Common::SaveFileManager *_realSaveManager;
SdlMixerManager *_realMixerManager;
MixerManager *_realMixerManager;
DefaultTimerManager *_timerManager;
RecorderSaveFileManager _fakeSaveManager;
NullSdlMixerManager *_fakeMixerManager;