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 QUEEN_SOUND_H
23 #define QUEEN_SOUND_H
24 
25 #include "audio/mixer.h"
26 
27 namespace Audio {
28 class AudioStream;
29 }
30 
31 namespace Common {
32 class File;
33 }
34 
35 namespace Queen {
36 
37 struct SongData {
38  int16 tuneList[5];
39  int16 volume;
40  int16 tempo;
41  int16 reverb;
42  int16 overrideCmd;
43  int16 ignore;
44 };
45 
46 struct TuneData {
47  int16 tuneNum[9];
48  int16 sfx[2];
49  int16 mode;
50  int16 delay;
51 };
52 
53 class MidiMusic;
54 class QueenEngine;
55 
56 class Sound {
57 public:
58  Sound(Audio::Mixer *mixer, QueenEngine *vm);
59  virtual ~Sound() {}
60 
64  static Sound *makeSoundInstance(Audio::Mixer *mixer, QueenEngine *vm, uint8 compression);
65 
66  virtual void playSfx(uint16 sfx) {}
67  virtual void playSong(int16 songNum) {}
68  virtual void playSpeech(const char *base) {}
69 
70  virtual void stopSfx() {}
71  virtual void stopSong() {}
72  virtual void stopSpeech() {}
73 
74  virtual bool isSpeechActive() const { return false; }
75  virtual bool isSfxActive() const { return false; }
76 
77  virtual void updateMusic() {}
78 
79  virtual void setVolume(int vol);
80  virtual int getVolume() { return _musicVolume; }
81 
82  void playLastSong() { playSong(_lastOverride); }
83 
84  bool sfxOn() const { return _sfxToggle; }
85  void sfxToggle(bool val) { _sfxToggle = val; }
86  void toggleSfx() { _sfxToggle = !_sfxToggle; }
87 
88  bool speechOn() const { return _speechToggle; }
89  void speechToggle(bool val) { _speechToggle = val; }
90  void toggleSpeech() { _speechToggle = !_speechToggle; }
91 
92  bool musicOn() const { return _musicToggle; }
93  void musicToggle(bool val) { _musicToggle = val; }
94  void toggleMusic() { _musicToggle = !_musicToggle; }
95 
96  bool speechSfxExists() const { return _speechSfxExists; }
97 
98  int16 lastOverride() const { return _lastOverride; }
99 
100  void saveState(byte *&ptr);
101  void loadState(uint32 ver, byte *&ptr);
102 
103  static const SongData _songDemo[];
104  static const SongData _song[];
105  static const TuneData _tuneDemo[];
106  static const TuneData _tune[];
107  static const char *const _sfxName[];
108  static const int16 _jungleList[];
109 
110 protected:
111 
112  Audio::Mixer *_mixer;
113  QueenEngine *_vm;
114 
115  bool _sfxToggle;
116  bool _speechToggle;
117  bool _musicToggle;
118  bool _speechSfxExists;
119 
120  int16 _lastOverride;
121  int _musicVolume;
122 };
123 
124 class PCSound : public Sound {
125 public:
126  PCSound(Audio::Mixer *mixer, QueenEngine *vm);
127  ~PCSound() override;
128 
129  void playSfx(uint16 sfx) override;
130  void playSpeech(const char *base) override;
131  void playSong(int16 songNum) override;
132 
133  void stopSfx() override { _mixer->stopHandle(_sfxHandle); }
134  void stopSong() override;
135  void stopSpeech() override { _mixer->stopHandle(_speechHandle); }
136 
137  bool isSpeechActive() const override { return _mixer->isSoundHandleActive(_speechHandle); }
138  bool isSfxActive() const override { return _mixer->isSoundHandleActive(_sfxHandle); }
139 
140  void setVolume(int vol) override;
141 
142 protected:
143  void playSound(const char *base, bool isSpeech);
144 
145  virtual void playSoundData(Common::File *f, uint32 size, Audio::SoundHandle *soundHandle) = 0;
146 
147  Audio::SoundHandle _sfxHandle;
148  Audio::SoundHandle _speechHandle;
149  MidiMusic *_music;
150 };
151 
152 class AmigaSound : public Sound {
153 public:
154  AmigaSound(Audio::Mixer *mixer, QueenEngine *vm);
155 
156  void playSfx(uint16 sfx) override;
157  void playSong(int16 song) override;
158 
159  void stopSfx() override;
160  void stopSong() override;
161 
162  bool isSfxActive() const override { return _mixer->isSoundHandleActive(_sfxHandle); }
163 
164  void updateMusic() override;
165 
166 protected:
167 
168  void playSound(const char *base);
169  Audio::AudioStream *loadModule(const char *base, int song);
170  void playModule(const char *base, int song);
171  void playPattern(const char *base, int pattern);
172  bool playSpecialSfx(int16 sfx);
173 
174  int16 _fanfareRestore;
175  int _fanfareCount, _fluteCount;
176  Audio::SoundHandle _modHandle;
177  Audio::SoundHandle _patHandle;
178  Audio::SoundHandle _sfxHandle;
179 };
180 
181 } // End of namespace Queen
182 
183 #endif
Definition: sound.h:37
Definition: queen.h:62
Definition: sound.h:124
Definition: mixer.h:49
Definition: mixer.h:59
Definition: bankman.h:28
Definition: file.h:47
Definition: algorithm.h:29
Definition: audiostream.h:50
Definition: sound.h:46
Definition: sound.h:152
Definition: sound.h:56
Definition: system.h:38
Definition: music.h:38