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 PARALLACTION_MUSIC_H
23#define PARALLACTION_MUSIC_H
24
25#include "common/util.h"
26#include "common/mutex.h"
27
28#include "audio/mixer.h"
29#include "audio/audiostream.h"
31
32#define PATH_LEN 200
33
34class MidiParser;
35class MidiDriver;
36
37namespace Parallaction {
38
39class Parallaction_ns;
40class MidiPlayer;
41class Parallaction_br;
42class MidiPlayer_MSC;
43
44MidiDriver *createAdLibDriver();
45
47public:
48 virtual void execute(int command, const char *parm = 0) = 0;
49 virtual ~SoundManImpl() { }
50};
51
52class SoundMan {
53 SoundManImpl *_impl;
54public:
55 SoundMan(SoundManImpl *impl) : _impl(impl) { }
56 virtual ~SoundMan() { delete _impl; }
57 void execute(int command, int32 parm) {
58 char n[12];
59 Common::sprintf_s(n, "%i", parm);
60 execute(command, n);
61 }
62 void execute(int command, const char *parm = 0) {
63 if (_impl) {
64 _impl->execute(command, parm);
65 }
66 }
67};
68
69enum {
70 // soundMan commands
71 SC_PLAYMUSIC,
72 SC_STOPMUSIC,
73 SC_SETMUSICTYPE,
74 SC_SETMUSICFILE,
75 SC_PLAYSFX,
76 SC_STOPSFX,
77 SC_SETSFXCHANNEL,
78 SC_SETSFXLOOPING,
79 SC_SETSFXVOLUME,
80 SC_SETSFXRATE,
81 SC_PAUSE
82};
83
84struct Channel {
85 Audio::AudioStream *stream;
86 Audio::SoundHandle handle;
87 uint32 volume;
88};
89
90
91
92class SoundMan_ns : public SoundManImpl {
93public:
94 enum {
95 MUSIC_ANY,
96 MUSIC_CHARACTER,
97 MUSIC_LOCATION
98 };
99
100protected:
101 Parallaction_ns *_vm;
102 Audio::Mixer *_mixer;
103 char _musicFile[PATH_LEN];
104
105 bool _sfxLooping;
106 int _sfxVolume;
107 int _sfxRate;
108 uint _sfxChannel;
109
110 int _musicType;
111
112public:
114 ~SoundMan_ns() override {}
115
116 virtual void playSfx(const char *filename, uint channel, bool looping, int volume = -1) { }
117 virtual void stopSfx(uint channel) { }
118
119 void setMusicFile(const char *filename);
120 virtual void playMusic() = 0;
121 virtual void stopMusic() = 0;
122 virtual void playCharacterMusic(const char *character) = 0;
123 virtual void playLocationMusic(const char *location) = 0;
124 virtual void pause(bool p) { }
125 void execute(int command, const char *parm) override;
126
127 void setMusicVolume(int value);
128};
129
131
132 MidiPlayer *_midiPlayer;
133 bool _playing;
134
135 bool isLocationSilent(const char *locationName);
136 bool locationHasOwnSoftMusic(const char *locationName);
137
138
139public:
141 ~DosSoundMan_ns() override;
142 void playMusic() override;
143 void stopMusic() override;
144
145 void playCharacterMusic(const char *character) override;
146 void playLocationMusic(const char *location) override;
147
148 void pause(bool p) override;
149};
150
151#define NUM_SFX_CHANNELS 4
152
154
155 Audio::AudioStream *_musicStream;
156 Audio::SoundHandle _musicHandle;
157
158 uint32 beepSoundBufferSize;
159 int8 *beepSoundBuffer;
160
161 Channel _channels[NUM_SFX_CHANNELS];
162
163 Audio::AudioStream *loadChannelData(const char *filename, Channel *ch, bool looping);
164
165public:
167 ~AmigaSoundMan_ns() override;
168 void playMusic() override;
169 void stopMusic() override;
170
171 void playSfx(const char *filename, uint channel, bool looping, int volume) override;
172 void stopSfx(uint channel) override;
173
174 void playCharacterMusic(const char *character) override;
175 void playLocationMusic(const char *location) override;
176};
177
179public:
180 void execute(int command, const char *parm) override { }
181};
182
183class SoundMan_br : public SoundManImpl {
184protected:
185 Parallaction_br *_vm;
186 Audio::Mixer *_mixer;
187
188 Common::String _musicFile;
189
190 bool _sfxLooping;
191 int _sfxVolume;
192 int _sfxRate;
193 uint _sfxChannel;
194
195 bool _musicEnabled;
196 bool _sfxEnabled;
197
198 Channel _channels[NUM_SFX_CHANNELS];
199
200 virtual void playMusic() = 0;
201 virtual void stopMusic() = 0;
202 virtual void pause(bool p) = 0;
203
204public:
206 ~SoundMan_br() override;
207
208 virtual void playSfx(const char *filename, uint channel, bool looping, int volume = -1) { }
209 void stopSfx(uint channel);
210 void stopAllSfx();
211
212 void execute(int command, const char *parm) override;
213 void setMusicFile(const char *parm);
214
215 void enableSfx(bool enable);
216 void enableMusic(bool enable);
217 bool isSfxEnabled() const;
218 bool isMusicEnabled() const;
219};
220
222
223 MidiPlayer_MSC *_midiPlayer;
224
225 Audio::AudioStream *loadChannelData(const char *filename, Channel *ch, bool looping);
226
227public:
229 ~DosSoundMan_br() override;
230
231 void playMusic() override;
232 void stopMusic() override;
233 void pause(bool p) override;
234
235 void playSfx(const char *filename, uint channel, bool looping, int volume) override;
236};
237
239
240 Audio::AudioStream *_musicStream;
241 Audio::SoundHandle _musicHandle;
242
243 Audio::AudioStream *loadChannelData(const char *filename, Channel *ch, bool looping);
244
245public:
247 ~AmigaSoundMan_br() override;
248
249 void playMusic() override;
250 void stopMusic() override;
251 void pause(bool p) override;
252
253 void playSfx(const char *filename, uint channel, bool looping, int volume) override;
254};
255
256} // namespace Parallaction
257
258#endif
Definition: audiostream.h:50
Definition: mixer.h:70
Definition: mixer.h:49
Definition: str.h:59
Definition: mididrv.h:313
Definition: midiparser.h:354
Definition: sound.h:238
Definition: sound.h:153
Definition: sound.h:221
Definition: sound.h:130
Definition: sound.h:178
Definition: parallaction.h:588
Definition: parallaction.h:474
Definition: sound.h:183
Definition: sound.h:92
Definition: sound.h:52
Definition: sound.h:46
int sprintf_s(char *dst, size_t size, MSVC_PRINTF const char *format,...) GCC_PRINTF(3
Definition: debug.h:8
Definition: sound.h:84