ScummVM API documentation
ambient_sounds.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 BLADERUNNER_AMBIENT_SOUNDS_H
23 #define BLADERUNNER_AMBIENT_SOUNDS_H
24 
25 #include "bladerunner/bladerunner.h" // For BLADERUNNER_ORIGINAL_SETTINGS symbol
26 
27 #include "audio/audiostream.h"
28 #include "audio/mixer.h"
29 
30 #include "common/str.h"
31 
32 namespace BladeRunner {
33 
34 class BladeRunnerEngine;
35 class SaveFileReadStream;
36 class SaveFileWriteStream;
37 
39  static const int kNonLoopingSounds = 25;
40  static const int kLoopingSounds = 3;
41  static const Audio::Mixer::SoundType kAmbientSoundType = Audio::Mixer::kPlainSoundType;
42 
43  struct NonLoopingSound {
44  bool isActive;
45  Common::String name;
46  int32 hash;
47  int audioPlayerTrack;
48  uint32 delayMin; // milliseconds
49  uint32 delayMax; // milliseconds
50  uint32 nextPlayTimeStart; // milliseconds
51  uint32 nextPlayTimeDiff; // milliseconds
52  int volumeMin; // should be in [0, 100]
53  int volumeMax; // should be in [0, 100]
54  int volume; // should be in [0, 100] (calculated as a random value within [volumeMin, volumeMax]
55  int panStartMin; // should be in [-100, 100]
56  int panStartMax; // should be in [-100, 100]
57  int panEndMin; // should be in [-100, 100], with "-101" being a special value for skipping pan (balance) adjustment
58  int panEndMax; // should be in [-100, 100], with "-101" being a special value for skipping pan (balance) adjustment
59  int priority; // should be in [0, 100]
60  int32 soundType; // new - not stored in saved games
61  };
62 
63  struct LoopingSound {
64  bool isActive;
65  Common::String name;
66  int32 hash;
67  int audioPlayerTrack;
68  int volume; // should be in [0, 100]
69  int pan; // should be in [-100, 100]
70  int32 soundType; // new - not stored in saved games
71  };
72 
73  BladeRunnerEngine *_vm;
74 
75  NonLoopingSound *_nonLoopingSounds;
76  LoopingSound *_loopingSounds;
77  int _ambientVolumeFactorOriginalEngine; // should be in [0, 100]
78 
79 public:
81  ~AmbientSounds();
82 
83  void addSound(int sfxId,
84  uint32 delayMinSeconds, uint32 delayMaxSeconds,
85  int volumeMin, int volumeMax,
86  int panStartMin, int panStartMax,
87  int panEndMin, int panEndMax,
88  int priority, int unk);
89  void removeNonLoopingSound(int sfxId, bool stopPlaying);
90  void removeAllNonLoopingSounds(bool stopPlaying);
91 
92  void addSpeech(int actorId, int sentenceId,
93  uint32 delayMinSeconds, uint32 delayMaxSeconds,
94  int volumeMin, int volumeMax,
95  int panStartMin, int panStartMax,
96  int panEndMin, int panEndMax,
97  int priority, int unk);
98  void playSound(int sfxId, int volume, int panStart, int panEnd, int priority, Audio::Mixer::SoundType type = kAmbientSoundType);
99  void playSpeech(int actorId, int sentenceId, int volume, int panStart, int panEnd, int priority);
100 
101  void addLoopingSound(int sfxId, int volume, int pan, uint32 delaySeconds, Audio::Mixer::SoundType type = kAmbientSoundType);
102  void adjustLoopingSound(int sfxId, int volume, int pan, uint32 delaySeconds);
103  // it seems there is little confusion in original code about delay parameter,
104  // sometimes it is used as boolean in same way as stopPlaying from non looping
105  void removeLoopingSound(int sfxId, uint32 delaySeconds);
106  void removeAllLoopingSounds(uint32 delaySeconds);
107 
108  void tick();
109 
110  void setVolume(int volume);
111  int getVolume() const;
112  void playSample();
113 
114  void save(SaveFileWriteStream &f);
115  void load(SaveFileReadStream &f);
116 
117 private:
118  int findAvailableNonLoopingTrack() const;
119  int findNonLoopingTrackByHash(int32 hash) const;
120 
121  int findAvailableLoopingTrack() const;
122  int findLoopingTrackByHash(int32 hash) const;
123 
124  void addSoundByName(const Common::String &name,
125  uint32 delayMinSeconds, uint32 delayMaxSeconds,
126  int volumeMin, int volumeMax,
127  int panStartMin, int panStartMax,
128  int panEndMin, int panEndMax,
129  int priority, int unk);
130 
131  void removeNonLoopingSoundByIndex(int index, bool stopPlaying);
132  void removeLoopingSoundByIndex(int index, uint32 delaySeconds);
133 };
134 
135 } // End of namespace BladeRunner
136 
137 #endif
Definition: savefile.h:88
Definition: str.h:59
Definition: actor.h:31
Definition: savefile.h:113
Definition: ambient_sounds.h:38
SoundType
Definition: mixer.h:62
Definition: bladerunner.h:113
Definition: mixer.h:63