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 TITANIC_SOUND_MANAGER_H
23#define TITANIC_SOUND_MANAGER_H
24
25#include "titanic/core/list.h"
26#include "titanic/support/simple_file.h"
27#include "titanic/sound/audio_buffer.h"
28#include "titanic/sound/proximity.h"
29#include "titanic/sound/qmixer.h"
30#include "titanic/sound/wave_file.h"
31#include "titanic/true_talk/dialogue_file.h"
32
33namespace Titanic {
34
35enum VolumeMode {
36 VOL_NORMAL = -1, VOL_QUIET = -2, VOL_VERY_QUIET = -3, VOL_MUTE = -4
37};
38
43protected:
44 uint _handleCtr;
45 // Old volume levels, deprecated in favor of setting the volumes
46 // directly in the ScummVM mixer
47 double _musicPercent;
48 double _speechPercent;
49 double _masterPercent;
50 double _parrotPercent;
51public:
53 virtual ~CSoundManager() {}
54
60 virtual CWaveFile *loadSound(const CString &name) { return nullptr; }
61
67 virtual CWaveFile *loadSpeech(CDialogueFile *dialogueFile, int speechId) { return 0; }
68
77 virtual CWaveFile *loadMusic(const CString &name) { return nullptr; }
78
84 virtual CWaveFile *loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse) { return nullptr; }
85
89 virtual int playSound(CWaveFile &waveFile, CProximity &prox) = 0;
90
94 virtual void stopSound(int handle) = 0;
95
99 virtual void stopChannel(int channel) = 0;
100
101 virtual void proc9(int handle) {}
102
106 virtual void stopAllChannels() = 0;
107
114 virtual void setVolume(int handle, uint volume, uint seconds) = 0;
115
124 virtual void setVectorPosition(int handle, double x, double y, double z, uint panRate) {}
125
134 virtual void setPolarPosition(int handle, double range, double azimuth, double elevation, uint panRate) {}
135
139 virtual bool isActive(int handle) = 0;
140
144 virtual bool isActive(const CWaveFile *waveFile) { return false; }
145
149 virtual void waveMixPump() = 0;
150
154 virtual uint getLatency() const { return 0; }
155
159 virtual void setMusicPercent(double percent) = 0;
160
164 virtual void setSpeechPercent(double percent) = 0;
165
169 virtual void setMasterPercent(double percent) = 0;
170
174 virtual void setParrotPercent(double percent) = 0;
175
179 virtual void preLoad() { stopAllChannels(); }
180
184 void load(SimpleFile *file) {}
185
189 virtual void postLoad() {}
190
194 virtual void preSave() {}
195
199 void save(SimpleFile *file) const {}
200
204 virtual void postSave() {}
205
209 virtual void setListenerPosition(double posX, double posY, double posZ,
210 double directionX, double directionY, double directionZ, bool stopSounds) {}
211
215 double getMusicVolume() const { return _musicPercent; }
216
220 double getSpeechVolume() const { return _speechPercent; }
221
225 double getParrotVolume() const { return _parrotPercent; }
226
230 uint getModeVolume(VolumeMode mode);
231};
232
234public:
235 CWaveFile *_waveFile;
236 int _iChannel;
237 CEndTalkerFn _endFn;
238 TTtalker *_talker;
239public:
240 QSoundManagerSound() : ListItem(), _waveFile(nullptr),
241 _iChannel(0), _endFn(nullptr), _talker(nullptr) {}
242 QSoundManagerSound(CWaveFile *waveFile, int iChannel, CEndTalkerFn endFn, TTtalker *talker) :
243 ListItem(), _waveFile(waveFile), _iChannel(iChannel), _endFn(endFn), _talker(talker) {}
244};
245
246class QSoundManagerSounds : public List<QSoundManagerSound> {
247public:
251 void add(CWaveFile *waveFile, int iChannel, CEndTalkerFn endFn, TTtalker *talker);
252
256 void flushChannel(int iChannel);
257
261 void flushChannel(CWaveFile *waveFile, int iChannel);
262
266 bool contains(const CWaveFile *waveFile) const;
267};
268
273class QSoundManager : public CSoundManager, public QMixer {
274 struct Slot {
275 CWaveFile *_waveFile;
276 bool _isTimed;
277 uint _ticks;
278 int _channel;
279 int _handle;
280 PositioningMode _positioningMode;
281
282 Slot() : _waveFile(0), _isTimed(0), _ticks(0), _channel(-1),
283 _handle(0), _positioningMode(POSMODE_NONE) {}
284 void clear();
285 };
286private:
287 QSoundManagerSounds _sounds;
288 Common::Array<Slot> _slots;
289 uint _channelsVolume[16];
290 int _channelsMode[16];
291private:
297 void updateVolume(int channel, uint panRate);
298
302 void updateVolumes();
303
307 static void soundFinished(int iChannel, CWaveFile *waveFile, void *soundManager);
308
312 int findFreeSlot();
313
317 void setChannelVolume(int iChannel, uint volume, uint mode);
318
322 int resetChannel(int iChannel);
323public:
324 int _field18;
325 int _field1C;
326
327public:
329 ~QSoundManager() override;
330
336 CWaveFile *loadSound(const CString &name) override;
337
343 CWaveFile *loadSpeech(CDialogueFile *dialogueFile, int speechId) override;
344
353 CWaveFile *loadMusic(const CString &name) override;
354
360 CWaveFile *loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse) override;
361
365 int playSound(CWaveFile &waveFile, CProximity &prox) override;
366
370 void stopSound(int handle) override;
371
375 void stopChannel(int channel) override;
376
380 virtual void setCanFree(int handle);
381
385 void stopAllChannels() override;
386
393 void setVolume(int handle, uint volume, uint seconds) override;
394
403 void setVectorPosition(int handle, double x, double y, double z, uint panRate) override;
404
413 void setPolarPosition(int handle, double range, double azimuth, double elevation, uint panRate) override;
414
418 bool isActive(int handle) override;
419
423 bool isActive(const CWaveFile *waveFile) override;
424
428 void waveMixPump() override;
429
433 uint getLatency() const override;
434
438 void setMusicPercent(double percent) override;
439
443 void setSpeechPercent(double percent) override;
444
448 void setMasterPercent(double percent) override;
449
453 void setParrotPercent(double percent) override;
454
458 void setListenerPosition(double posX, double posY, double posZ,
459 double directionX, double directionY, double directionZ, bool stopSounds) override;
460
464 virtual int playWave(CWaveFile *waveFile, int iChannel, uint flags, CProximity &prox);
465
470};
471
472} // End of namespace Titanic
473
474#endif /* TITANIC_QSOUND_MANAGER_H */
Definition: mixer.h:70
Definition: mixer.h:49
Definition: audio_buffer.h:32
Definition: dialogue_file.h:51
Definition: proximity.h:36
Definition: sound_manager.h:42
void save(SimpleFile *file) const
Definition: sound_manager.h:199
virtual bool isActive(const CWaveFile *waveFile)
Definition: sound_manager.h:144
virtual CWaveFile * loadSound(const CString &name)
Definition: sound_manager.h:60
virtual void setMasterPercent(double percent)=0
void load(SimpleFile *file)
Definition: sound_manager.h:184
virtual void setPolarPosition(int handle, double range, double azimuth, double elevation, uint panRate)
Definition: sound_manager.h:134
double getSpeechVolume() const
Definition: sound_manager.h:220
virtual void stopSound(int handle)=0
virtual void postLoad()
Definition: sound_manager.h:189
virtual uint getLatency() const
Definition: sound_manager.h:154
virtual void setListenerPosition(double posX, double posY, double posZ, double directionX, double directionY, double directionZ, bool stopSounds)
Definition: sound_manager.h:209
uint getModeVolume(VolumeMode mode)
double getParrotVolume() const
Definition: sound_manager.h:225
virtual void setVolume(int handle, uint volume, uint seconds)=0
virtual void setSpeechPercent(double percent)=0
virtual void setMusicPercent(double percent)=0
virtual void preLoad()
Definition: sound_manager.h:179
virtual void postSave()
Definition: sound_manager.h:204
virtual void setVectorPosition(int handle, double x, double y, double z, uint panRate)
Definition: sound_manager.h:124
virtual void stopAllChannels()=0
double getMusicVolume() const
Definition: sound_manager.h:215
virtual void waveMixPump()=0
virtual void setParrotPercent(double percent)=0
virtual void stopChannel(int channel)=0
virtual CWaveFile * loadSpeech(CDialogueFile *dialogueFile, int speechId)
Definition: sound_manager.h:67
virtual void preSave()
Definition: sound_manager.h:194
virtual CWaveFile * loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse)
Definition: sound_manager.h:84
virtual CWaveFile * loadMusic(const CString &name)
Definition: sound_manager.h:77
virtual bool isActive(int handle)=0
virtual int playSound(CWaveFile &waveFile, CProximity &prox)=0
Definition: string.h:40
Definition: wave_file.h:35
Definition: list.h:71
Definition: list.h:35
Definition: qmixer.h:173
Definition: sound_manager.h:273
bool isActive(int handle) override
virtual int playWave(CWaveFile *waveFile, int iChannel, uint flags, CProximity &prox)
void waveMixPump() override
int playSound(CWaveFile &waveFile, CProximity &prox) override
void stopChannel(int channel) override
CWaveFile * loadSound(const CString &name) override
CWaveFile * loadMusic(const CString &name) override
CWaveFile * loadMusic(CAudioBuffer *buffer, DisposeAfterUse::Flag disposeAfterUse) override
void stopSound(int handle) override
uint getLatency() const override
CWaveFile * loadSpeech(CDialogueFile *dialogueFile, int speechId) override
void setSpeechPercent(double percent) override
void setMusicPercent(double percent) override
void setVectorPosition(int handle, double x, double y, double z, uint panRate) override
bool isActive(const CWaveFile *waveFile) override
void setPolarPosition(int handle, double range, double azimuth, double elevation, uint panRate) override
void setVolume(int handle, uint volume, uint seconds) override
void setParrotPercent(double percent) override
void stopAllChannels() override
virtual void setCanFree(int handle)
void soundFreed(Audio::SoundHandle &handle)
void setListenerPosition(double posX, double posY, double posZ, double directionX, double directionY, double directionZ, bool stopSounds) override
void setMasterPercent(double percent) override
Definition: sound_manager.h:233
Definition: sound_manager.h:246
void flushChannel(CWaveFile *waveFile, int iChannel)
bool contains(const CWaveFile *waveFile) const
void add(CWaveFile *waveFile, int iChannel, CEndTalkerFn endFn, TTtalker *talker)
void flushChannel(int iChannel)
Definition: simple_file.h:49
Definition: tt_talker.h:33