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 DGDS_SOUND_H
23 #define DGDS_SOUND_H
24 
25 #include "common/scummsys.h"
26 #include "audio/audiostream.h"
27 #include "audio/mixer.h"
28 
29 namespace Dgds {
30 
31 class ResourceManager;
32 class Decompressor;
33 class DgdsMidiPlayer;
34 class SciMusic;
35 class MusicEntry;
36 class AudioPlayer;
37 
38 struct Channel {
39  Audio::AudioStream *stream;
40  Audio::SoundHandle handle;
41  byte volume;
42 };
43 
44 struct SoundData {
45  SoundData() : _size(0), _data(nullptr), _flags(0) {}
46  uint32 _size;
47  const byte *_data;
48  uint16 _flags;
49 };
50 
51 class Sound {
52 public:
53  Sound(Audio::Mixer *mixer, ResourceManager *resource, Decompressor *decompressor);
54  ~Sound();
55 
56  void playAmigaSfx(const Common::String &filename, byte channel, byte volume);
57  bool loadMusic(const Common::String &filename);
58  void loadSFX(const Common::String &filename);
59 
60  void playMusic(int num);
61  void stopMusic();
62  void unloadMusic();
63 
64  void playSFX(int num);
65 
66  void playMusicOrSFX(int num);
67  void stopMusicOrSFX(int num);
68  void pauseMusicOrSFX(int num);
69  void unpauseMusicOrSFX(int num);
70 
71  void stopSfxForChannel(byte channel);
72  void stopSfxByNum(int num);
73  void stopAllSfx();
74 
75  bool playPCM(const byte *data, uint32 size);
76 
77  void muteSoundType(Audio::Mixer::SoundType soundType);
78  void unmuteSoundType(Audio::Mixer::SoundType soundType);
79 
80 private:
81  void loadSNGSoundData(const Common::String &filename, Common::Array<SoundData> &dataArray);
82  bool loadSXSoundData(const Common::String &filename, Common::Array<SoundData> &dataArray, Common::HashMap<uint16, uint16> &idMap);
83  void patchSoundData(const Common::String &filename, uint16 soundNumber, byte *data, uint32 size);
84 
85  void playPCSound(int num, const Common::Array<SoundData> &dataArray, Audio::Mixer::SoundType soundType);
86 
87  void processInitSound(uint32 obj, const SoundData &data, Audio::Mixer::SoundType soundType);
88  void processDisposeSound(uint32 obj);
89  void processStopSound(uint32 obj, bool sampleFinishedPlaying);
90  void processPlaySound(uint32 obj, bool playBed, bool restoring, const SoundData &data);
91  void initSoundResource(MusicEntry *newSound, const SoundData &data, Audio::Mixer::SoundType soundType);
92 
93  int mapSfxNum(int num) const;
94  int mapMusicNum(int num) const;
95 
96  struct Channel _channels[2];
97 
98  Common::Array<SoundData> _musicData;
100 
101  Common::Array<SoundData> _sfxData;
103 
104  Common::String _currentMusic;
105 
106  SciMusic *_music;
107 
108  Audio::Mixer *_mixer;
109  ResourceManager *_resource;
110  Decompressor *_decompressor;
111 
112  bool _isMusicMuted;
113  bool _isSfxMuted;
114 };
115 
116 enum {
117  DIGITAL_PCM = 1 << 0,
118  TRACK_ADLIB = 1 << 1,
119  TRACK_GM = 1 << 2,
120  TRACK_MT32 = 1 << 3,
121  TRACK_CMS = 1 << 4,
122  TRACK_PCSPK = 1 << 5,
123  TRACK_TANDY = 1 << 6,
124 };
125 
126 } // End of namespace Dgds
127 
128 #endif // DGDS_SOUND_H
Definition: str.h:59
Definition: music.h:77
Definition: array.h:52
Definition: ads.h:28
Definition: sound.h:51
Definition: music.h:178
Definition: sound.h:38
Definition: mixer.h:49
SoundType
Definition: mixer.h:73
Definition: mixer.h:70
Definition: audiostream.h:50
Definition: sound.h:44
Definition: decompress.h:67
Definition: resource.h:48