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  bool _paused;
46 
51  return Common::MemoryReadStream(&_soundData[offset], _soundData.size() - offset);
52  }
53 
54  explicit SoundDriver(Audio::Mixer *mixer) : _mixer(mixer), _paused(false) {}
55 
56 public:
64  SoundDriver(Audio::Mixer *mixer, const Common::Path &filename,
65  int dataOffset, int dataSize);
66  virtual ~SoundDriver() {}
67 
74  virtual int command(int commandId, int param) = 0;
75 
79  virtual int stop() = 0;
80 
84  virtual void pause(bool paused);
85 
89  virtual int poll() = 0;
90 
94  virtual void noise() = 0;
95 
96  // TODO Remove
97  virtual void setVolume(int volume) { };
98 
102  virtual void stopAllNotes() { }
103 };
104 
106 protected:
107  struct QueuedCommand {
108  int _commandId;
109  int _param;
110  };
111 
112  // Number of microseconds between driver updates (60 Hz frequency)
113  static const uint32 UPDATE_DELTA;
114 
115  enum DriverType { SOUND_ADLIB, SOUND_MT32, SOUND_GM, SOUND_PCSPEAKER, SOUND_PAS };
116  Audio::Mixer *_mixer;
117  DriverType _driverType;
118  MidiDriver_MT32GM *_midiDriver;
119  uint32 _driverCallbackDelta;
120  uint32 _updateDeltaRemainder;
121 
122  bool &_soundFlag;
123  SoundDriver *_driver = nullptr;
124  bool _newSoundsPaused = false;
125  Common::Queue<QueuedCommand> _queuedCommands;
126 
127  NativeSoundTimer _hostTimer;
128 
129 protected:
134  virtual void loadDriver(int sectionNum) = 0;
135 
136 public:
137  SoundManager(Audio::Mixer *mixer, bool &soundFlag,
138  bool supportsGeneralMidi = false);
139  virtual ~SoundManager();
140 
144  virtual void validate() = 0;
145 
149  void init(int sectionNumber);
150 
154  bool isLoaded() const {
155  return _driver != nullptr;
156  }
157 
163  bool isReady();
164 
168  bool isDriverActive();
169 
173  bool usesPCSpeaker() const {
174  return _driverType == SOUND_PCSPEAKER;
175  }
176 
180  void closeDriver();
181 
185  void removeDriver();
186 
190  void pauseNewCommands();
191 
195  virtual void startQueuedCommands();
196 
200  void syncSoundSettings();
201 
203 
208  int command(int commandId, int param = 0);
209 
213  void stop();
214 
218  void pause(bool pause);
219 
224  void noise();
225 
227 
228  void onTimer();
229  static void timerCallback(void *data);
230 };
231 
232 } // namespace MADS
233 
234 #endif
Definition: mt32gm.h:111
virtual void stopAllNotes()
Definition: sound_manager.h:102
bool isLoaded() const
Definition: sound_manager.h:154
Definition: path.h:52
Definition: sound_manager.h:107
Common::MemoryReadStream getDataStream(int offset) const
Definition: sound_manager.h:50
Definition: queue.h:42
Definition: mixer.h:70
Definition: native_sound_timer.h:33
Definition: sound_manager.h:105
Definition: mutex.h:67
bool usesPCSpeaker() const
Definition: sound_manager.h:173
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