ScummVM API documentation
sound.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 ILLUSIONS_SOUND_H
23 #define ILLUSIONS_SOUND_H
24 
25 #include "illusions/graphics.h"
26 #include "audio/audiostream.h"
27 #include "audio/decoders/wave.h"
28 #include "audio/midiplayer.h"
29 #include "audio/mixer.h"
30 #include "common/array.h"
31 #include "common/list.h"
32 
33 namespace Illusions {
34 
35 class IllusionsEngine;
36 
37 class MusicPlayer {
38 public:
39  MusicPlayer();
40  ~MusicPlayer();
41  void play(uint32 musicId, bool looping, int16 volume, int16 pan);
42  void stop();
43  bool isPlaying();
44 protected:
45  Audio::SoundHandle _soundHandle;
46  uint32 _musicId;
47  uint _flags;
48 };
49 
50 class MidiPlayer : public Audio::MidiPlayer {
51 public:
52  MidiPlayer();
53  ~MidiPlayer() override;
54  bool play(uint32 musicId);
55  void stop() override;
56  bool isIdle() const { return _isIdle; }
57 protected:
58  bool _isIdle;
59  bool _isPlaying;
60  bool _isCurrentlyPlaying;
61  bool _isLooped;
62  uint32 _loopedMusicId;
63  uint32 _queuedMusicId;
64  uint32 _loadedMusicId;
65  byte *_data;
66  uint _dataSize;
67  bool _isGM;
68  void sysMidiPlay(uint32 musicId);
69  void sysMidiStop();
70  void send(uint32 b) override;
71  void sendToChannel(byte channel, uint32 b) override;
72  void endOfTrack() override;
73 };
74 
75 class VoicePlayer {
76 public:
77  VoicePlayer();
78  ~VoicePlayer();
79  bool cue(const char *voiceName);
80  void stopCueing();
81  void start(int16 volume, int16 pan);
82  void stop();
83  void pause();
84  void unpause();
85  bool isPlaying();
86  bool isEnabled();
87  bool isCued();
88 protected:
89  Audio::SoundHandle _soundHandle;
90  Common::String _voiceName;
91  uint _voiceStatus;
92  bool _wasPlaying;
93  bool _isPaused;
94 };
95 
96 class Sound {
97 public:
98  Sound(uint32 soundEffectId, uint32 soundGroupId, bool looping);
99  ~Sound();
100  void load();
101  void unload();
102  void play(int16 volume, int16 pan);
103  void stop();
104  bool isPlaying();
105  bool isLooping();
106 public:
107  uint32 _soundEffectId;
108  uint32 _soundGroupId;
109 protected:
111  Audio::SoundHandle _soundHandle;
112  bool _looping;
113 };
114 
116  bool _active;
117  uint _flags;
118  int16 _currVolume;
119  int16 _startVolume;
120  int16 _finalVolume;
121  int16 _startTime;
122  int16 _duration;
123  uint32 _notifyThreadId;
124  MidiMusicFader() : _active(false), _currVolume(255) {}
125 };
126 
127 class SoundMan {
128 public:
130  ~SoundMan();
131  void update();
132 
133  void playMusic(uint32 musicId, int16 type, int16 volume, int16 pan, uint32 notifyThreadId);
134  void stopMusic();
135 
136  void playMidiMusic(uint32 musicId);
137  void stopMidiMusic();
138  void fadeMidiMusic(int16 finalVolume, int16 duration, uint32 notifyThreadId);
139  void clearMidiMusicQueue();
140 
141  uint16 getMusicVolume();
142  uint16 getSfxVolume();
143  uint16 getSpeechVolume();
144 
145  void setMusicVolume(uint16 volume);
146  void setSfxVolume(uint16 volume);
147  void setSpeechVolume(uint16 volume);
148 
149  bool cueVoice(const char *voiceName);
150  void stopCueingVoice();
151  void startVoice(int16 volume, int16 pan);
152  void stopVoice();
153  void pauseVoice();
154  void unpauseVoice();
155  bool isVoicePlaying();
156  bool isVoiceEnabled();
157  bool isVoiceCued();
158 
159  void loadSound(uint32 soundEffectId, uint32 soundGroupId, bool looping);
160  void playSound(uint32 soundEffectId, int16 volume, int16 pan);
161  void stopSound(uint32 soundEffectId);
162  void stopLoopingSounds();
163  void unloadSounds(uint32 soundGroupId);
164 
165 protected:
168  IllusionsEngine *_vm;
169  uint32 _musicNotifyThreadId;
170  MusicPlayer *_musicPlayer;
171  MidiPlayer *_midiPlayer;
172  VoicePlayer *_voicePlayer;
173  SoundList _sounds;
174  Common::Array<uint32> _midiMusicQueue;
175  MidiMusicFader _midiMusicFader;
176  Sound *getSound(uint32 soundEffectId);
177  void updateMidi();
178  void updateMidiMusicFader();
179  uint16 calcAdjustedVolume(const Common::String &volumeConfigKey, uint16 volume);
180 };
181 
182 } // End of namespace Illusions
183 
184 #endif // ILLUSIONS_SOUND_H
Definition: midiplayer.h:63
Definition: sound.h:115
Definition: str.h:59
Definition: sound.h:96
Definition: actor.h:34
Definition: sound.h:50
Definition: mixer.h:49
Definition: sound.h:127
Definition: sound.h:75
Definition: sound.h:37
Definition: audiostream.h:109
Definition: list_intern.h:51
Definition: illusions.h:80