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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef BLADERUNNER_AMBIENT_SOUNDS_H
24 #define BLADERUNNER_AMBIENT_SOUNDS_H
25 
26 #include "audio/audiostream.h"
27 #include "audio/mixer.h"
28 
29 #include "common/str.h"
30 
31 namespace BladeRunner {
32 
33 class BladeRunnerEngine;
34 class SaveFileReadStream;
35 class SaveFileWriteStream;
36 
37 class AmbientSounds {
38 	static const int kNonLoopingSounds                     = 25;
39 	static const int kLoopingSounds                        = 3;
40 	static const Audio::Mixer::SoundType kAmbientSoundType = Audio::Mixer::kPlainSoundType;
41 
42 	struct NonLoopingSound {
43 		bool           isActive;
44 		Common::String name;
45 		int32          hash;
46 		int            audioPlayerTrack;
47 		uint32         delayMin;          // milliseconds
48 		uint32         delayMax;          // milliseconds
49 		uint32         nextPlayTimeStart; // milliseconds
50 		uint32         nextPlayTimeDiff;  // milliseconds
51 		int            volumeMin;
52 		int            volumeMax;
53 		int            volume;
54 		int            panStartMin;
55 		int            panStartMax;
56 		int            panEndMin;
57 		int            panEndMax;
58 		int            priority;
59 		int32          soundType; // new - not stored in saved games
60 	};
61 
62 	struct LoopingSound {
63 		bool           isActive;
64 		Common::String name;
65 		int32          hash;
66 		int            audioPlayerTrack;
67 		int            volume;
68 		int            pan;
69 		int32          soundType; // new - not stored in saved games
70 	};
71 
72 	BladeRunnerEngine *_vm;
73 
74 	NonLoopingSound *_nonLoopingSounds;
75 	LoopingSound    *_loopingSounds;
76 	int              _ambientVolume;
77 
78 public:
79 	AmbientSounds(BladeRunnerEngine *vm);
80 	~AmbientSounds();
81 
82 	void addSound(
83 		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 	);
90 	void removeNonLoopingSound(int sfxId, bool stopPlaying);
91 	void removeAllNonLoopingSounds(bool stopPlaying);
92 
93 	void addSpeech(
94 		int actorId, int sentenceId,
95 		uint32 delayMinSeconds, uint32 delayMaxSeconds,
96 		int volumeMin, int volumeMax,
97 		int panStartMin, int panStartMax,
98 		int panEndMin, int panEndMax,
99 		int priority, int unk);
100 	void playSound(int sfxId, int volume, int panStart, int panEnd, int priority, Audio::Mixer::SoundType type = kAmbientSoundType);
101 	void playSpeech(int actorId, int sentenceId, int volume, int panStart, int panEnd, int priority);
102 
103 	void addLoopingSound(int sfxId, int volume, int pan, uint32 delaySeconds, Audio::Mixer::SoundType type = kAmbientSoundType);
104 	void adjustLoopingSound(int sfxId, int volume, int pan, uint32 delaySeconds);
105 	// it seems there is little confusion in original code about delay parameter,
106 	// sometimes it is used as boolean in same way as stopPlaying from non looping
107 	void removeLoopingSound(int sfxId, uint32 delaySeconds);
108 	void removeAllLoopingSounds(uint32 delaySeconds);
109 
110 	void tick();
111 
112 	void setVolume(int volume);
113 	int getVolume() const;
114 	void playSample();
115 
116 	void save(SaveFileWriteStream &f);
117 	void load(SaveFileReadStream &f);
118 
119 private:
120 	int findAvailableNonLoopingTrack() const;
121 	int findNonLoopingTrackByHash(int32 hash) const;
122 
123 	int findAvailableLoopingTrack() const;
124 	int findLoopingTrackByHash(int32 hash) const;
125 
126 	void addSoundByName(
127 		const Common::String &name,
128 		uint32 delayMinSeconds, uint32 delayMaxSeconds,
129 		int volumeMin, int volumeMax,
130 		int panStartMin, int panStartMax,
131 		int panEndMin, int panEndMax,
132 		int priority, int unk);
133 
134 	void removeNonLoopingSoundByIndex(int index, bool stopPlaying);
135 	void removeLoopingSoundByIndex(int index, uint32 delaySeconds);
136 };
137 
138 } // End of namespace BladeRunner
139 
140 #endif
141