ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
84  void playPCSound(int num, const Common::Array<SoundData> &dataArray, Audio::Mixer::SoundType soundType);
85 
86  void processInitSound(uint32 obj, const SoundData &data, Audio::Mixer::SoundType soundType);
87  void processDisposeSound(uint32 obj);
88  void processStopSound(uint32 obj, bool sampleFinishedPlaying);
89  void processPlaySound(uint32 obj, bool playBed, bool restoring, const SoundData &data);
90  void initSoundResource(MusicEntry *newSound, const SoundData &data, Audio::Mixer::SoundType soundType);
91 
92  int mapSfxNum(int num) const;
93  int mapMusicNum(int num) const;
94 
95  struct Channel _channels[2];
96 
97  Common::Array<SoundData> _musicData;
99 
100  Common::Array<SoundData> _sfxData;
102 
103  Common::String _currentMusic;
104 
105  SciMusic *_music;
106 
107  Audio::Mixer *_mixer;
108  ResourceManager *_resource;
109  Decompressor *_decompressor;
110 
111  bool _isMusicMuted;
112  bool _isSfxMuted;
113 };
114 
115 enum {
116  DIGITAL_PCM = 1 << 0,
117  TRACK_ADLIB = 1 << 1,
118  TRACK_GM = 1 << 2,
119  TRACK_MT32 = 1 << 3,
120  TRACK_CMS = 1 << 4,
121  TRACK_PCSPK = 1 << 5,
122  TRACK_TANDY = 1 << 6,
123 };
124 
125 } // End of namespace Dgds
126 
127 #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:62
Definition: mixer.h:59
Definition: audiostream.h:50
Definition: sound.h:44
Definition: decompress.h:67
Definition: resource.h:48