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 NEVERHOOD_SOUND_H
23 #define NEVERHOOD_SOUND_H
24 
25 #include "audio/audiostream.h"
26 #include "common/array.h"
27 #include "neverhood/resourceman.h"
28 
29 namespace Common {
30 class SeekableReadStream;
31 }
32 
33 namespace Audio {
34 class SoundHandle;
35 }
36 
37 namespace Neverhood {
38 
39 class NeverhoodEngine;
40 class AudioResourceManSoundItem;
41 class AudioResourceManMusicItem;
42 
44 public:
46  ~SoundResource();
47  bool isPlaying();
48  void load(uint32 fileHash);
49  void unload();
50  void play(uint32 fileHash);
51  void play();
52  void playLooping();
53  void stop();
54  void setVolume(int16 volume);
55  void setPan(int16 pan);
56 protected:
57  NeverhoodEngine *_vm;
58  int16 _soundIndex;
59  AudioResourceManSoundItem *getSoundItem();
60 };
61 
63 public:
65  bool isPlaying();
66  void load(uint32 fileHash);
67  void unload();
68  void play(int16 fadeVolumeStep);
69  void stop(int16 fadeVolumeStep);
70  void setVolume(int16 volume);
71 protected:
72  NeverhoodEngine *_vm;
73  int16 _musicIndex;
74  AudioResourceManMusicItem *getMusicItem();
75 };
76 
77 class MusicItem {
78 public:
79  MusicItem(NeverhoodEngine *vm, uint32 groupNameHash, uint32 musicFileHash);
80  ~MusicItem();
81  void startMusic(int16 countdown, int16 fadeVolumeStep);
82  void stopMusic(int16 countdown, int16 fadeVolumeStep);
83  void update();
84  uint32 getGroupNameHash() const { return _groupNameHash; }
85  uint32 getFileHash() const { return _fileHash; }
86 protected:
87  NeverhoodEngine *_vm;
88  uint32 _groupNameHash;
89  uint32 _fileHash;
90  bool _play;
91  bool _stop;
92  int16 _fadeVolumeStep;
93  int16 _countdown;
94  MusicResource *_musicResource;
95 };
96 
97 class SoundItem {
98 public:
99  SoundItem(NeverhoodEngine *vm, uint32 groupNameHash, uint32 soundFileHash,
100  bool playOnceAfterRandomCountdown, int16 minCountdown, int16 maxCountdown,
101  bool playOnceAfterCountdown, int16 initialCountdown, bool playLooping, int16 currCountdown);
102  ~SoundItem();
103  void setSoundParams(bool playOnceAfterRandomCountdown, int16 minCountdown, int16 maxCountdown,
104  int16 firstMinCountdown, int16 firstMaxCountdown);
105  void playSoundLooping();
106  void stopSound();
107  void setVolume(int volume);
108  void update();
109  void setPlayOnceAfterCountdown(bool playOnceAfterCountdown) { _playOnceAfterCountdown = playOnceAfterCountdown; }
110  uint32 getGroupNameHash() const { return _groupNameHash; }
111  uint32 getFileHash() const { return _fileHash; }
112  int16 getCurrCountdown() const { return _currCountdown; }
113 protected:
114  NeverhoodEngine *_vm;
115  uint32 _groupNameHash;
116  uint32 _fileHash;
117  bool _playOnceAfterRandomCountdown;
118  int16 _minCountdown;
119  int16 _maxCountdown;
120  bool _playOnceAfterCountdown;
121  int16 _initialCountdown;
122  bool _playLooping;
123  int16 _currCountdown;
124  SoundResource *_soundResource;
125 };
126 
127 class SoundMan {
128 public:
130  ~SoundMan();
131 
132  void stopAllMusic();
133  void stopAllSounds();
134 
135  // Music
136  void addMusic(uint32 groupNameHash, uint32 musicFileHash);
137  void deleteMusic(uint32 musicFileHash);
138  void startMusic(uint32 musicFileHash, int16 countdown, int16 fadeVolumeStep);
139  void stopMusic(uint32 musicFileHash, int16 countdown, int16 fadeVolumeStep);
140 
141  // Sound
142  void addSound(uint32 groupNameHash, uint32 soundFileHash);
143  void addSoundList(uint32 groupNameHash, const uint32 *soundFileHashList);
144  void deleteSound(uint32 soundFileHash);
145  void setSoundParams(uint32 soundFileHash, bool playOnceAfterRandomCountdown,
146  int16 minCountdown, int16 maxCountdown, int16 firstMinCountdown, int16 firstMaxCountdown);
147  void setSoundListParams(const uint32 *soundFileHashList, bool playOnceAfterRandomCountdown,
148  int16 minCountdown, int16 maxCountdown, int16 firstMinCountdown, int16 firstMaxCountdown);
149  void playSoundLooping(uint32 soundFileHash);
150  void stopSound(uint32 soundFileHash);
151  void setSoundVolume(uint32 soundFileHash, int volume);
152 
153  // Misc
154  void update();
155  void deleteGroup(uint32 groupNameHash);
156  void deleteMusicGroup(uint32 groupNameHash);
157  void deleteSoundGroup(uint32 groupNameHash);
158  void playTwoSounds(uint32 groupNameHash, uint32 soundFileHash1, uint32 soundFileHash2, int16 initialCountdown);
159  void playSoundThree(uint32 groupNameHash, uint32 soundFileHash);
160  void setTwoSoundsPlayFlag(bool playOnceAfterCountdown);
161  void setSoundThreePlayFlag(bool playOnceAfterCountdown);
162 
163 protected:
164  NeverhoodEngine *_vm;
165 
166  // TODO Find out what these special sounds are used for (door sounds?)
167  int _soundIndex1, _soundIndex2;
168  int16 _initialCountdown;
169  bool _playOnceAfterCountdown;
170 
171  int _soundIndex3;
172  int16 _initialCountdown3;
173  bool _playOnceAfterCountdown3;
174 
175  Common::Array<MusicItem*> _musicItems;
176  Common::Array<SoundItem*> _soundItems;
177 
178  MusicItem *getMusicItemByHash(uint32 musicFileHash);
179  SoundItem *getSoundItemByHash(uint32 soundFileHash);
180  int16 addMusicItem(MusicItem *musicItem);
181  int16 addSoundItem(SoundItem *soundItem);
182  void deleteSoundByIndex(int index);
183 
184 };
185 
187 public:
188  NeverhoodAudioStream(int rate, byte shiftValue, bool isLooping, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream);
189  ~NeverhoodAudioStream() override;
190  int readBuffer(int16 *buffer, const int numSamples) override;
191  bool isStereo() const override { return _isStereo; }
192  bool endOfData() const override { return _endOfData; }
193  int getRate() const override { return _rate; }
194 private:
195  const int _rate;
196  const bool _isLooping;
197  const bool _isStereo;
198  const byte _shiftValue;
199  const bool _isCompressed;
200  int16 _prevValue;
202  bool _endOfData;
203  byte *_buffer;
204  enum {
205  kSampleBufferLength = 2048
206  };
207  int fillBuffer(int maxSamples);
208 };
209 
210 // TODO Rename these
211 
213 public:
214  AudioResourceManSoundItem(NeverhoodEngine *vm, uint32 fileHash);
216  void loadSound();
217  void unloadSound();
218  void setVolume(int16 volume);
219  void setPan(int16 pan);
220  void playSound(bool looping);
221  void stopSound();
222  bool isPlaying();
223 protected:
224  NeverhoodEngine *_vm;
225  uint32 _fileHash;
226  ResourceHandle _resourceHandle;
227  const byte *_data;
228  bool _isLoaded;
229  bool _isPlaying;
230  int16 _volume;
231  int16 _panning;
232  Audio::SoundHandle *_soundHandle;
233 };
234 
236 public:
237  AudioResourceManMusicItem(NeverhoodEngine *vm, uint32 fileHash);
239  void playMusic(int16 fadeVolumeStep);
240  void stopMusic(int16 fadeVolumeStep);
241  void unloadMusic();
242  void setVolume(int16 volume);
243  void restart();
244  void update();
245  bool isPlaying() const { return _isPlaying; }
246  bool canRestart() const { return _canRestart; }
247  bool isTerminated() const { return _terminate; }
248  uint32 getFileHash() const { return _fileHash; }
249 protected:
250  NeverhoodEngine *_vm;
251  uint32 _fileHash;
252  bool _isPlaying;
253  bool _canRestart;
254  bool _terminate;
255  int16 _volume;
256  int16 _panning;
257  bool _start;
258  bool _isFadingIn;
259  bool _isFadingOut;
260  int16 _fadeVolume;
261  int16 _fadeVolumeStep;
262  Audio::SoundHandle *_soundHandle;
263 };
264 
266 public:
268  ~AudioResourceMan();
269 
270  void stopAllMusic();
271  void stopAllSounds();
272 
273  int16 addSound(uint32 fileHash);
274  void removeSound(int16 soundIndex);
275 
276  int16 loadMusic(uint32 fileHash);
277  void updateMusic();
278 
279  AudioResourceManSoundItem *getSoundItem(int16 index);
280  AudioResourceManMusicItem *getMusicItem(int16 index);
281 
282 protected:
283  NeverhoodEngine *_vm;
284 
287 
288  int16 addSoundItem(AudioResourceManSoundItem *soundItem);
289 
290 };
291 
292 } // End of namespace Neverhood
293 
294 #endif /* NEVERHOOD_SOUND_H */
Definition: background.h:30
Definition: resourceman.h:64
Definition: sound.h:77
Definition: neverhood.h:60
Definition: array.h:52
Definition: stream.h:745
Definition: sound.h:97
Definition: sound.h:186
Definition: mixer.h:49
bool endOfData() const override
Definition: sound.h:192
Definition: algorithm.h:29
Definition: sound.h:62
Definition: audiostream.h:50
Definition: sound.h:43
int getRate() const override
Definition: sound.h:193
Definition: sound.h:265
Definition: system.h:38
bool isStereo() const override
Definition: sound.h:191
Definition: sound.h:127