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 PELROCK_SOUND_H
23 #define PELROCK_SOUND_H
24 
25 #include "audio/mixer.h"
26 #include "common/file.h"
27 #include "common/scummsys.h"
28 #include "common/str.h"
29 
30 namespace Pelrock {
31 
32 struct SonidoFile {
33  Common::String filename;
34  uint32 offset;
35  uint32 size;
36  byte *data;
37 };
38 
39 extern const char *SOUND_FILENAMES[];
40 
41 enum SoundFormat {
42  SOUND_FORMAT_RAWPCM,
43  SOUND_FORMAT_MILES,
44  SOUND_FORMAT_MILES2,
45  SOUND_FORMAT_RIFF,
46  SOUND_FORMAT_INVALID
47 };
48 
49 struct SoundData {
50  SoundFormat format;
51  int sampleRate;
52  byte *data;
53  uint32 size;
54 };
55 
56 const int kMaxChannels = 15;
57 const int kAmbientSoundSlotBase = 4; // Room sound indices 4-7 are ambient sounds
58 
59 class SoundManager {
60 public:
61  SoundManager(Audio::Mixer *mixer);
62  ~SoundManager();
63  void playSound(byte index, int channel = -1, int loopCount = 1);
64  void playSound(const char *filename, int channel, int loopCount = 1);
65  void playSound(byte *soundData, uint32 size, int channel);
66  void stopAllSounds();
67  void stopSound(int channel);
68 
69  void setVolumeSfx(int volume);
70  void setVolumeMusic(int volume);
71  void setVolumeMaster(int volume);
72  int getVolumeSfx() const;
73  int getVolumeMusic() const;
74  int getVolumeMaster() const;
75 
76  bool isPlaying() const;
77  bool isPlaying(int channel) const;
78  bool isSoundIndexPlaying(byte index) const;
79  void loadSoundIndex();
80 
81  bool isMusicPlaying();
82  void playMusicTrack(int trackNumber, bool loop = true);
83  void stopMusic();
84  void pauseMusic();
85 
89  int tickAmbientSound(uint32 frameCount);
90 
91  void playClick();
92  void playClonk();
93 
94  bool isPaused() const { return _isPaused; }
95  byte getCurrentMusicTrack() const { return _currentMusicTrack; }
96 
97 private:
98  int playSound(SonidoFile sound, int channel = -1, int loopCount = 1);
99  SoundFormat detectFormat(byte *data, uint32 size);
100  int getSampleRate(byte *data, SoundFormat format);
101  int findFreeChannel();
102 
103 private:
104  Audio::Mixer *_mixer;
105  int _currentVolume;
106  Audio::SoundHandle _musicHandle;
107  Audio::SoundHandle _sfxHandles[kMaxChannels];
108  byte _sfxSoundIndex[kMaxChannels]; // tracks which sound index is on each channel (0xFF = none)
110  bool _isPaused = false;
111  byte _currentMusicTrack = 0;
112 
113 
114  uint32 _cdTrackStart = 0;
115  uint32 _cdTrackDuration = 0;
116  uint32 _cdPlayStartTime = 0; // time at the moment of calling play()
117 
118 };
119 
120 } // End of namespace Pelrock
121 
122 #endif // PELROCK_SOUND_H
Definition: str.h:59
Definition: actions.h:27
Definition: mixer.h:49
Definition: mixer.h:70
Definition: hashmap.h:85
Definition: sound.h:59
Definition: sound.h:49
Definition: sound.h:32