ScummVM API documentation
sound_manager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MADS_CORE_SOUND_MANAGER_H
23 #define MADS_CORE_SOUND_MANAGER_H
24 
25 #include "common/array.h"
26 #include "common/memstream.h"
27 #include "common/mutex.h"
28 #include "common/queue.h"
29 
30 namespace Audio {
31 class Mixer;
32 }
33 
34 namespace OPL {
35 class OPL;
36 }
37 
38 namespace MADS {
39 
40 #define CALLBACKS_PER_SECOND 60
41 
42 class SoundDriver {
43 protected:
44  Audio::Mixer *_mixer;
45  OPL::OPL *_opl;
46  Common::Array<byte> _soundData;
47  Common::Mutex _driverMutex;
48 
53  return Common::MemoryReadStream(&_soundData[offset], _soundData.size() - offset);
54  }
55 
56 public:
57  SoundDriver(Audio::Mixer *mixer, OPL::OPL *opl, const Common::Path &filename,
58  int dataOffset, int dataSize);
59  virtual ~SoundDriver();
60 
67  virtual int command(int commandId, int param) = 0;
68 
72  virtual int stop() = 0;
73 
77  virtual int poll() = 0;
78 
82  virtual void noise() = 0;
83 
87  virtual void setVolume(int volume) = 0;
88 };
89 
90 class SoundManager {
91 protected:
92  Audio::Mixer *_mixer;
93  bool &_soundFlag;
94  OPL::OPL *_opl = nullptr;
95  SoundDriver *_driver = nullptr;
96  bool _pollSoundEnabled = false;
97  bool _soundPollFlag = false;
98  bool _newSoundsPaused = false;
99  Common::Queue<int> _queuedCommands;
100  int _masterVolume = 255;
101 
102 protected:
107  virtual void loadDriver(int sectionNum) = 0;
108 
109 public:
110  SoundManager(Audio::Mixer *mixer, bool &soundFlag);
111  virtual ~SoundManager();
112 
113  virtual void validate() = 0;
114 
115  bool _preferRoland;
116 
120  void init(int sectionNumber);
121 
125  bool isLoaded() const {
126  return _driver != nullptr;
127  }
128 
132  void closeDriver();
133 
137  void removeDriver();
138 
143  void setEnabled(bool flag);
144 
148  void pauseNewCommands();
149 
153  void startQueuedCommands();
154 
158  void setVolume(int volume);
159 
161 
166  int command(int commandId, int param = 0);
167 
171  void stop();
172 
177  void noise();
178 
180 };
181 
182 } // namespace MADS
183 
184 #endif
bool isLoaded() const
Definition: sound_manager.h:125
Definition: path.h:52
Common::MemoryReadStream getDataStream(int offset) const
Definition: sound_manager.h:52
Definition: mixer.h:70
Definition: sound_manager.h:90
Definition: mutex.h:67
size_type size() const
Definition: array.h:316
Definition: memstream.h:43
Definition: sound_manager.h:42
Definition: fmopl.h:35
Definition: mps_installer.h:31
Definition: system.h:38
Definition: fmopl.h:116