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 ACCESS_SOUND_H
23 #define ACCESS_SOUND_H
24 
25 #include "common/scummsys.h"
26 #include "access/files.h"
27 #include "audio/midiplayer.h"
28 
29 #define MAX_SOUNDS 20
30 
31 namespace Audio {
32 class AudioStream;
33 class SoundHandle;
34 }
35 
36 namespace Access {
37 
38 class AccessEngine;
39 
40 class SoundManager {
41  struct SoundEntry {
42  Resource *_res;
43  int _priority;
44  int _fileNum;
45  int _subFileNum;
46 
47  SoundEntry() : _res(nullptr), _priority(0), _fileNum(0), _subFileNum(0) { }
48  SoundEntry(Resource *res, int priority, int fileNum = -1, int subFileNum = -1) :
49  _res(res), _priority(priority), _fileNum(fileNum), _subFileNum(subFileNum) { }
50 
51  bool matches(const FileIdent &ident) const { return _fileNum == ident._fileNum && _subFileNum == ident._subFile; }
52  };
53 
54  struct QueuedSound {
55  Audio::AudioStream *_stream;
56  int _soundId;
57 
58  QueuedSound() : _stream(nullptr), _soundId(-1) {}
59  QueuedSound(Audio::AudioStream *stream, int soundIdx) : _stream(stream), _soundId(soundIdx) {}
60  };
61 private:
62  AccessEngine *_vm;
63  Audio::Mixer *_mixer;
64  Audio::SoundHandle *_effectsHandle;
66  Common::Array<SoundEntry> _soundTable;
67 
68  void clearSounds();
69 
70  void playSound(Resource *res, int priority, bool loop, int soundIndex = -1);
71 
72  bool isSoundQueued(int soundId) const;
73 
74 public:
76  ~SoundManager();
77 
78  // replace the current table entry at idx with a new one
79  void loadSoundTable(int idx, int fileNum, int subfile, int priority = 1);
80 
81  // load and add a single sound resource to the table
82  int loadAndAddSound(int fileNum, int subfile, int priority = 1);
83  int loadAndAddSound(const FileIdent &ident, int priority = 1);
84 
85  bool hasLoadedSound(const FileIdent &ident) const;
86 
87  void playSound(int soundIndex, bool loop = false);
88  void playSoundByIdent(const FileIdent &ident, bool loop = false);
89  void checkSoundQueue();
90  bool isSFXPlaying();
91 
92  void loadSounds(const Common::Array<RoomInfo::SoundIdent> &sounds);
93  int loadRawSound(const Common::Path &path, int priority);
94  void syncVolume();
95 
96  void stopSound();
97  void freeSounds();
98  void freeSound(int idx);
99  bool hasSounds() const { return _soundTable.size() > 0 && _soundTable[0]._res; }
100 };
101 
102 class MusicManager : public Manager {
103 public:
104  MusicManager(AccessEngine *vm) : Manager(vm), _music(nullptr), _tempMusic(nullptr) {};
105  virtual ~MusicManager();
106 
107  bool isMusicLoaded() { return _music != nullptr; }
108  void freeMusic();
109  virtual void loadMusic(int fileNum, int subfile);
110  void loadMusic(FileIdent ident) { loadMusic(ident._fileNum, ident._subFile); };
111 
112  virtual void midiPlay() = 0;
113  virtual bool isPlaying() = 0;
114  virtual void midiRepeat() = 0;
115  virtual void stopSong() = 0;
116  virtual void newMusic(int musicId, int mode) = 0;
117  virtual void startMusicFade() = 0;
118  virtual void setLoop(bool loop) = 0;
119  virtual void syncVolume() = 0;
120 
121 protected:
122  Resource *_music;
123  Resource *_tempMusic;
124 
125 };
126 
128 private:
129  // MidiDriver_BASE interface implementation
130  void send(uint32 b) override;
131 
132 public:
134  ~MusicManagerMIDI() override;
135 
136  void midiPlay() override;
137  bool isPlaying() override { return MidiPlayer::isPlaying(); }
138  void midiRepeat() override;
139  void stopSong() override;
140  void newMusic(int musicId, int mode) override;
141  void startMusicFade() override;
142  void setLoop(bool loop) override;
143 
144  void syncVolume() override { MidiPlayer::syncVolume(); }
145 };
146 
147 #ifdef USE_VORBIS
148 
149 class MusicManagerOGG : public MusicManager {
150 private:
151  Audio::SoundHandle *_handle;
152 
153 public:
154  MusicManagerOGG(AccessEngine *vm);
155  ~MusicManagerOGG() override;
156 
157  void midiPlay() override;
158  bool isPlaying() override;
159  void midiRepeat() override;
160  void stopSong() override;
161  void newMusic(int musicId, int mode) override;
162  void startMusicFade() override;
163  void setLoop(bool loop) override;
164  void syncVolume() override;
165 
166  void loadMusic(int fileNum, int subfile) override;
167 };
168 
169 #endif
170 
171 } // End of namespace Access
172 
173 #endif /* ACCESS_SOUND_H*/
Definition: midiplayer.h:63
Definition: files.h:36
bool isPlaying() const
Definition: midiplayer.h:94
Definition: data.h:37
Definition: access.h:141
Definition: path.h:52
Definition: sound.h:102
Definition: files.h:55
Definition: mixer.h:49
Definition: mixer.h:70
Definition: sound.h:127
Definition: sound.h:40
Definition: audiostream.h:50
size_type size() const
Definition: array.h:316
Definition: access.h:62
Definition: system.h:38