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 "audio/mt32gm.h"
26 #include "common/array.h"
27 #include "common/memstream.h"
28 #include "common/mutex.h"
29 #include "common/queue.h"
30 #include "native_sound_timer.h"
31 
32 namespace Audio {
33 class Mixer;
34 }
35 
36 namespace MADS {
37 
38 #define CALLBACKS_PER_SECOND 60
39 
40 class SoundDriver {
41 protected:
42  Audio::Mixer *_mixer;
43  Common::Array<byte> _soundData;
44  Common::Mutex _driverMutex;
45 
50  return Common::MemoryReadStream(&_soundData[offset], _soundData.size() - offset);
51  }
52 
53  explicit SoundDriver(Audio::Mixer *mixer) : _mixer(mixer) {}
54 
55 public:
63  SoundDriver(Audio::Mixer *mixer, const Common::Path &filename,
64  int dataOffset, int dataSize);
65  virtual ~SoundDriver() {}
66 
73  virtual int command(int commandId, int param) = 0;
74 
78  virtual int stop() = 0;
79 
83  virtual int poll() = 0;
84 
88  virtual void noise() = 0;
89 
93  virtual void setVolume(int volume) = 0;
94 };
95 
96 class SoundManager {
97 protected:
98  struct QueuedCommand {
99  int _commandId;
100  int _param;
101  };
102 
103  // Number of microseconds between driver updates (60 Hz frequency)
104  static const uint32 UPDATE_DELTA;
105 
106  enum DriverType { SOUND_ADLIB, SOUND_MT32, SOUND_GM, SOUND_PCSPEAKER, SOUND_PAS };
107  Audio::Mixer *_mixer;
108  DriverType _driverType;
109  MidiDriver_MT32GM *_midiDriver;
110  uint32 _driverCallbackDelta;
111  uint32 _updateDeltaRemainder;
112 
113  bool &_soundFlag;
114  SoundDriver *_driver = nullptr;
115  bool _newSoundsPaused = false;
116  Common::Queue<QueuedCommand> _queuedCommands;
117  int _masterVolume = 255;
118 
119  NativeSoundTimer _hostTimer;
120 
121 protected:
126  virtual void loadDriver(int sectionNum) = 0;
127 
128 public:
129  SoundManager(Audio::Mixer *mixer, bool &soundFlag,
130  bool supportsGeneralMidi = false);
131  virtual ~SoundManager();
132 
136  virtual void validate() = 0;
137 
141  void init(int sectionNumber);
142 
146  bool isLoaded() const {
147  return _driver != nullptr;
148  }
149 
153  bool isDriverActive();
154 
158  bool usesPCSpeaker() const {
159  return _driverType == SOUND_PCSPEAKER;
160  }
161 
165  void closeDriver();
166 
170  void removeDriver();
171 
175  void pauseNewCommands();
176 
180  virtual void startQueuedCommands();
181 
185  void setVolume(int volume);
186 
188 
193  int command(int commandId, int param = 0);
194 
198  void stop();
199 
204  void noise();
205 
207 
208  void onTimer();
209  static void timerCallback(void *data);
210 };
211 
212 } // namespace MADS
213 
214 #endif
Definition: mt32gm.h:111
bool isLoaded() const
Definition: sound_manager.h:146
Definition: path.h:52
Definition: sound_manager.h:98
Common::MemoryReadStream getDataStream(int offset) const
Definition: sound_manager.h:49
Definition: queue.h:42
Definition: mixer.h:70
Definition: native_sound_timer.h:33
Definition: sound_manager.h:96
Definition: mutex.h:67
bool usesPCSpeaker() const
Definition: sound_manager.h:158
size_type size() const
Definition: array.h:316
Definition: memstream.h:43
Definition: sound_manager.h:40
Definition: anim_timer.h:27
Definition: system.h:39