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 CHEWY_SOUND_H
23 #define CHEWY_SOUND_H
24 
25 #include "audio/mixer.h"
26 #include "chewy/atds.h"
27 #include "chewy/chewy.h"
28 
29 namespace Chewy {
30 
31 class SoundResource;
32 
33 #define MAX_SOUND_EFFECTS 14
34 
35 class Sound {
36 private:
37  static const int TMF_NUM_INSTRUMENTS = 31;
38  static const uint8 TMF_MOD_SONG_NAME[20];
39  static const uint8 TMF_MOD_INSTRUMENT_NAME[22];
40  static const uint16 TMF_MOD_PERIODS[36];
41 
42 public:
43  Sound(Audio::Mixer *mixer);
44  virtual ~Sound();
45 
46  void playSound(int num, uint channel = 0, uint16 loops = 1, uint16 volume = 63, uint16 balance = 63);
47  void playSound(uint8 *data, uint32 size, uint channel = 0, uint16 loops = 1, uint16 volume = 63, uint16 balance = 63, DisposeAfterUse::Flag dispose = DisposeAfterUse::YES);
48  void pauseSound(uint channel);
49  void resumeSound(uint channel);
50  void stopSound(uint channel = 0);
51  void stopAllSounds();
52  bool isSoundActive(uint channel) const;
53  void setUserSoundVolume(uint volume);
54  int getUserSoundVolume() const;
55  // Sets the volume of the sound effect curently active on the specified
56  // channel. Does not affect the next sound effect played on the channel.
57  void setSoundChannelVolume(uint channel, uint volume);
58  // Sets the balance of the sound effect curently active on the specified
59  // channel. Does not affect the next sound effect played on the channel.
60  void setSoundChannelBalance(uint channel, int8 balance);
61 
62  void playMusic(int16 num, bool loop = false);
63  void playMusic(uint8 *data, uint32 size, uint8 volume = 63);
64  void pauseMusic();
65  void resumeMusic();
66  void stopMusic();
67  bool isMusicActive() const;
68  void setUserMusicVolume(uint volume);
69  int getUserMusicVolume() const;
70  // Sets the volume of the currently active music track. Does not affect the
71  // next music track played.
72  void setActiveMusicVolume(uint8 volume);
73  void playRoomMusic(int16 roomNum);
74 
75  void playSpeech(int num, bool waitForFinish, uint16 balance = 63);
76  void pauseSpeech();
77  void resumeSpeech();
78  void stopSpeech();
79  bool isSpeechActive() const;
80  // Sets the balance of the currently playing speech sample. Does not affect
81  // the next speech sample played.
82  void setSpeechBalance(uint16 balance = 63);
83 
84  void stopAll();
85 
89  void waitForSpeechToFinish();
90 
91  bool soundEnabled() const;
92  void toggleSound(bool enable);
93 
94  bool musicEnabled() const;
95  void toggleMusic(bool enable);
96 
97  bool speechEnabled() const;
98  void toggleSpeech(bool enable);
99 
100  bool subtitlesEnabled() const;
101  void toggleSubtitles(bool enable);
102 
103  void syncSoundSettings();
104 
105 private:
106  // Converts volume from the scale used by the game data (0 - 63) to the
107  // ScummVM mixer channel scale (0 - 255).
108  uint8 convertVolume(uint16 volume);
109  // Converts balance from the scale used by the game data (0 - 127) to the
110  // ScummVM mixer channel scale (-127 - 127).
111  int8 convertBalance(uint16 balance);
112 
113  Audio::Mixer *_mixer;
114  Audio::SoundHandle _soundHandle[MAX_SOUND_EFFECTS];
115  Audio::SoundHandle _musicHandle;
116  Audio::SoundHandle _speechHandle;
117  int16 _curMusic = -1;
118  // Volume settings in the in-game options screen.
119  int _userSoundVolume = -1, _userMusicVolume = -1;
120 
121  SoundResource *_speechRes;
122  SoundResource *_soundRes;
123 };
124 
125 } // End of namespace Chewy
126 
127 #endif
Definition: mixer.h:49
Definition: mixer.h:59
Definition: sound.h:35
void waitForSpeechToFinish()
Definition: ani_dat.h:25
Definition: resource.h:187