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 ASYLUM_SYSTEM_SOUND_H
23 #define ASYLUM_SYSTEM_SOUND_H
24 
25 #include "common/array.h"
26 #include "common/rect.h"
27 
28 #include "audio/mixer.h"
29 
30 #include "asylum/system/config.h"
31 
32 #include "asylum/shared.h"
33 
34 namespace Asylum {
35 
36 class AsylumEngine;
37 
38 struct ResourceEntry;
39 
40 struct SoundItem {
41  ResourceId resourceId;
42  int32 field_4;
43  int32 field_8;
44  int32 field_C;
45 
46  SoundItem() {
47  resourceId = kResourceNone;
48  field_4 = 0;
49  field_8 = 0;
50  field_C = 0;
51  }
52 };
53 
55  ResourceId resourceId;
56  uint32 frameIndex;
57  int32 index;
58  int32 field_C;
59  int32 field_10;
60  int32 field_14;
61 
62  FrameSoundItem() {
63  resourceId = kResourceNone;
64  frameIndex = 0;
65  index = 0;
66  field_C = 0;
67  field_10 = 0;
68  field_14 = 0;
69  }
70 };
71 
73  int32 field_0;
74  int32 flags;
75  ResourceId resourceId;
76  int32 delta;
77  int32 attenuation;
78  int32 nextTick;
79  int32 flagNum[6];
80  Common::Point point;
81 
83  field_0 = 0;
84  flags = 0;
85  resourceId = kResourceNone;
86  delta = 0;
87  attenuation = 0;
88  nextTick = 0;
89  memset(&flagNum, 0, sizeof(flagNum));
90  }
91 };
92 
94  ResourceId resourceId;
95  Audio::SoundHandle handle;
96 
97  SoundQueueItem() {
98  resourceId = kResourceNone;
99  }
100 };
101 
102 class Sound {
103 public:
104  Sound(AsylumEngine *engine, Audio::Mixer *mixer);
105  ~Sound();
106 
108  // Playing sounds & music
110 
119  void playSound(ResourceId resourceId, bool looping = false, int32 volume = Config.sfxVolume, int32 panning = 0);
120 
127  void playMusic(ResourceId resourceId, int32 volume = Config.musicVolume);
128 
135  void changeMusic(int32 index, int32 musicStatusExt);
136 
144  bool isPlaying(ResourceId resourceId);
145 
147  // Volume & panning
149 
156  void setVolume(ResourceId resourceId, int32 volume);
157 
163  void setMusicVolume(int32 volume);
164 
170  int32 getMusicVolume() { return _musicVolume; }
171 
178  void setPanning(ResourceId resourceId, int32 panning);
179 
189  int32 calculateVolumeAdjustement(const Common::Point &point, int32 attenuation, int32 delta);
190 
198  int32 getAdjustedVolume(int32 volume) const;
199 
207  int32 calculatePanningAtPoint(const Common::Point &point);
208 
210  // Stopping sounds
212 
218  void stop(ResourceId resourceId);
219 
225  void stopAll(ResourceId resourceId);
226 
230  void stopAll();
231 
235  void stopMusic();
236 
238  // Conversion functions
240 
246  static void convertVolumeFrom(int32 &vol);
247 
253  static void convertVolumeTo(int32 &vol);
254 
255 private:
256  AsylumEngine *_vm;
257 
258  Audio::Mixer *_mixer;
259 
260  Audio::SoundHandle _musicHandle;
261  int32 _musicVolume;
262 
263  Common::Array<SoundQueueItem> _soundQueue;
264 
266  // Sound queue
268 
276  SoundQueueItem *getItem(ResourceId resourceId);
277 
285  SoundQueueItem *getPlayingItem(ResourceId resourceId);
286 
294  SoundQueueItem *addToQueue(ResourceId resourceId);
295 
299  void cleanupQueue();
300 
302  // Helper functions
304 
310  bool isValidSoundResource(ResourceId resourceId);
311 
323  void playSoundData(Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte *soundData, uint32 soundDataLength, bool loop = false, int32 vol = 0, int32 pan = 0);
324 
326  // Conversion functions
328 
334  static void convertPan(int32 &pan);
335 };
336 
337 } // end of namespace Asylum
338 
339 #endif // ASYLUM_SYSTEM_SOUND_H
Definition: array.h:52
Definition: asylum.h:53
Definition: sound.h:93
Definition: mixer.h:49
SoundType
Definition: mixer.h:62
Definition: mixer.h:59
Definition: rect.h:45
Definition: asylum.h:70
Definition: sound.h:102
Definition: sound.h:40
int32 getMusicVolume()
Definition: sound.h:170
Definition: sound.h:72
Definition: sound.h:54