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 KYRA_SOUND_H
23 #define KYRA_SOUND_H
24 
25 #include "kyra/kyra_v1.h"
26 
27 #include "common/scummsys.h"
28 #include "common/str.h"
29 
30 #include "audio/mixer.h"
31 
32 namespace Audio {
33 class AudioStream;
34 class SeekableAudioStream;
35 } // End of namespace Audio
36 
37 namespace Kyra {
38 
39 // Helper structs to format the data passed to the various initAudioResourceInfo() implementations
41  SoundResourceInfo_PC(const char *const *files, int numFiles) : fileList(files), fileListSize(numFiles) {}
42  const char *const *fileList;
43  uint fileListSize;
44 };
45 
47  SoundResourceInfo_Towns(const char *const *files, int numFiles, const int32 *cdaTbl, int cdaTblSize) : fileList(files), fileListSize(numFiles), cdaTable(cdaTbl), cdaTableSize(cdaTblSize) {}
48  const char *const *fileList;
49  uint fileListSize;
50  const int32 *cdaTable;
51  uint cdaTableSize;
52 };
53 
55  SoundResourceInfo_PC98(const char *fileNamePattern) : pattern(fileNamePattern) {}
56  const char *pattern;
57 };
58 
60  SoundResourceInfo_TownsPC98V2(const char *const *files, int numFiles, const char *fileNamePattern, const uint16 *cdaTbl, int cdaTblSize) : fileList(files), fileListSize(numFiles), pattern(fileNamePattern), cdaTable(cdaTbl), cdaTableSize(cdaTblSize) {}
61  const char *const *fileList;
62  uint fileListSize;
63  const char *pattern;
64  const uint16 *cdaTable;
65  uint cdaTableSize;
66 };
67 
69  SoundResourceInfo_TownsEoB(const char *const *filelist, uint numfiles, const uint8 *pcmdata, uint pcmdataSize, int pcmvolume) : fileList(filelist), numFiles(numfiles), pcmData(pcmdata), pcmDataSize(pcmdataSize), pcmVolume(pcmvolume) {}
70  const uint8 *pcmData;
71  uint pcmDataSize;
72  int pcmVolume;
73  const char *const *fileList;
74  uint numFiles;
75 };
76 
77 
79  SoundResourceInfo_AmigaEoB(const char *const *files, int numFiles, const char *const *soundmap, int numSounds) : fileList(files), fileListSize(numFiles), soundList(soundmap), soundListSize(numSounds) {}
80  const char *const *fileList;
81  uint fileListSize;
82  const char *const *soundList;
83  uint soundListSize;
84 };
85 
91 class Sound {
92 public:
93  Sound(KyraEngine_v1 *vm, Audio::Mixer *mixer);
94  virtual ~Sound();
95 
96  enum kType {
97  kAdLib,
98  kMidiMT32,
99  kMidiGM,
100  kTowns,
101  kPC98,
102  kPCSpkr,
103  kPCjr,
104  kAmiga,
105  kSegaCD,
106  kMac
107  };
108 
109  virtual kType getMusicType() const = 0;
110  virtual kType getSfxType() const;
111 
112  // This is obviously not a real implementation. The original allows disabling digital sfx (or simply not having a suitable sound card),
113  // thus falling back to the music driver's sfx. We never supported this, since we don't even have a setting for it in the launcher.
114  // Currently, the only purpose of this function is fixing KyraEngine_HoF::o2_playFireflyScore() (bug #10877: "Sound issues in the Legend of Kyrandia 2").
115  virtual bool useDigitalSfx() const { return true; }
116 
122  virtual bool init() = 0;
123 
127  virtual void process() {}
128 
132  virtual void updateVolumeSettings() {}
133 
141  virtual void initAudioResourceInfo(int set, void *info) = 0;
142 
148  virtual void selectAudioResourceSet(int set) = 0;
149 
156  virtual bool hasSoundFile(uint file) const = 0;
157 
162  virtual void loadSoundFile(uint file) = 0;
163 
168  virtual void loadSoundFile(const Common::Path &file) = 0;
169 
173  virtual void unloadSoundFile(const Common::String &file) {}
174 
179  virtual void loadSfxFile(const Common::Path &file) {}
180 
186  virtual void playTrack(uint8 track) = 0;
187 
191  virtual void haltTrack() = 0;
192 
198  virtual void playSoundEffect(uint16 track, uint8 volume = 0xFF) = 0;
199 
203  virtual void stopAllSoundEffects() {}
204 
210  virtual bool isPlaying() const;
211 
221  virtual void beginFadeOut() = 0;
222  virtual void beginFadeOut(int) { beginFadeOut(); }
223 
227  virtual void pause(bool paused) {}
228 
229  virtual void enableMusic(int enable) { _musicEnabled = enable; }
230  int musicEnabled() const { return _musicEnabled; }
231  void enableSFX(bool enable) { _sfxEnabled = enable; }
232  bool sfxEnabled() const { return _sfxEnabled; }
233 
240  bool isVoicePresent(const char *file) const;
241 
255  virtual int32 voicePlay(const char *file, Audio::SoundHandle *handle = 0, uint8 volume = 255, uint8 priority = 255, bool isSfx = false);
256 
257  Audio::SeekableAudioStream *getVoiceStream(const char *file) const;
258 
259  bool playVoiceStream(Audio::AudioStream *stream, Audio::SoundHandle *handle = 0, uint8 volume = 255, uint8 priority = 255, bool isSfx = false);
260 
266  bool voiceIsPlaying(const Audio::SoundHandle *handle = 0) const;
267 
273  bool allVoiceChannelsPlaying() const;
274 
280  uint32 voicePlayedTime(const Audio::SoundHandle &handle) const {
281  return _mixer->getSoundElapsedTime(handle);
282  }
283 
287  void voiceStop(const Audio::SoundHandle *handle = 0);
288 
292  virtual int checkTrigger() { return 0; }
293 
297  virtual void resetTrigger() {}
298 protected:
299  enum {
300  kNumChannelHandles = 4
301  };
302 
303  struct SoundChannel {
304  SoundChannel() : handle(), priority(0) {}
305  Audio::SoundHandle handle;
306  int priority;
307  };
308 
309  SoundChannel _soundChannels[kNumChannelHandles];
310 
311  int _musicEnabled;
312  bool _sfxEnabled;
313 
314  KyraEngine_v1 *_vm;
315  Audio::Mixer *_mixer;
316 
317 private:
318  struct SpeechCodecs {
319  const char *fileext;
320  Audio::SeekableAudioStream *(*streamFunc)(
322  DisposeAfterUse::Flag disposeAfterUse);
323  };
324 
325  static const SpeechCodecs _supportedCodecs[];
326 };
327 
328 class MixedSoundDriver : public Sound {
329 public:
330  MixedSoundDriver(KyraEngine_v1 *vm, Audio::Mixer *mixer, Sound *music, Sound *sfx);
331  ~MixedSoundDriver() override;
332 
333  kType getMusicType() const override;
334  kType getSfxType() const override;
335 
336  bool init() override;
337  void process() override;
338 
339  void updateVolumeSettings() override;
340 
341  void initAudioResourceInfo(int set, void *info) override;
342  void selectAudioResourceSet(int set) override;
343  bool hasSoundFile(uint file) const override;
344  void loadSoundFile(uint file) override;
345  void loadSoundFile(const Common::Path &file) override;
346 
347  void loadSfxFile(const Common::Path &file) override;
348 
349  void playTrack(uint8 track) override;
350  void haltTrack() override;
351  bool isPlaying() const override;
352 
353  void playSoundEffect(uint16 track, uint8 volume = 0xFF) override;
354 
355  void stopAllSoundEffects() override;
356 
357  void beginFadeOut() override;
358  void pause(bool paused) override;
359 private:
360  Sound *_music, *_sfx;
361 };
362 
363 } // End of namespace Kyra
364 
365 #endif
virtual void resetTrigger()
Definition: sound.h:297
Definition: str.h:59
Definition: sound.h:40
virtual int checkTrigger()
Definition: sound.h:292
Definition: sound.h:68
Definition: sound.h:303
Definition: kyra_v1.h:126
virtual void pause(bool paused)
Definition: sound.h:227
virtual void updateVolumeSettings()
Definition: sound.h:132
Definition: path.h:52
Definition: sound.h:328
Definition: stream.h:745
Definition: sound.h:78
virtual void process()
Definition: sound.h:127
Definition: audiostream.h:212
Definition: sound.h:91
Definition: mixer.h:49
Definition: mixer.h:59
Definition: audiostream.h:50
Definition: sound.h:54
virtual void unloadSoundFile(const Common::String &file)
Definition: sound.h:173
uint32 voicePlayedTime(const Audio::SoundHandle &handle) const
Definition: sound.h:280
Definition: detection.h:27
virtual void loadSfxFile(const Common::Path &file)
Definition: sound.h:179
Definition: system.h:37
virtual void stopAllSoundEffects()
Definition: sound.h:203
Definition: sound.h:46