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 
69  void stopSfxForChannel(byte channel);
70  void stopSfxByNum(int num);
71  void stopAllSfx();
72 
73  bool playPCM(const byte *data, uint32 size);
74 
75 private:
76  void loadSNGSoundData(const Common::String &filename, Common::Array<SoundData> &dataArray);
77  bool loadSXSoundData(const Common::String &filename, Common::Array<SoundData> &dataArray, Common::HashMap<uint16, uint16> &idMap);
78 
79  void playPCSound(int num, const Common::Array<SoundData> &dataArray, Audio::Mixer::SoundType soundType);
80 
81  void processInitSound(uint32 obj, const SoundData &data, Audio::Mixer::SoundType soundType);
82  void processDisposeSound(uint32 obj);
83  void processStopSound(uint32 obj, bool sampleFinishedPlaying);
84  void processPlaySound(uint32 obj, bool playBed, bool restoring, const SoundData &data);
85  void initSoundResource(MusicEntry *newSound, const SoundData &data, Audio::Mixer::SoundType soundType);
86 
87  int mapSfxNum(int num) const;
88  int mapMusicNum(int num) const;
89 
90  struct Channel _channels[2];
91 
92  Common::Array<SoundData> _musicData;
94 
95  Common::Array<SoundData> _sfxData;
97 
98  Common::String _currentMusic;
99 
100  SciMusic *_music;
101 
102  Audio::Mixer *_mixer;
103  ResourceManager *_resource;
104  Decompressor *_decompressor;
105 };
106 
107 enum {
108  DIGITAL_PCM = 1 << 0,
109  TRACK_ADLIB = 1 << 1,
110  TRACK_GM = 1 << 2,
111  TRACK_MT32 = 1 << 3,
112  TRACK_CMS = 1 << 4,
113  TRACK_PCSPK = 1 << 5,
114  TRACK_TANDY = 1 << 6,
115 };
116 
117 } // End of namespace Dgds
118 
119 #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:49