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