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 SCUMM_SOUND_H
23 #define SCUMM_SOUND_H
24 
25 #include "common/scummsys.h"
26 #include "common/serializer.h"
27 #include "common/str.h"
28 #include "audio/mididrv.h"
29 #include "scumm/file.h"
30 #include "scumm/soundcd.h"
31 #include "scumm/soundse.h"
32 
33 #define DIGI_SND_MODE_EMPTY 0
34 #define DIGI_SND_MODE_SFX 1
35 #define DIGI_SND_MODE_TALKIE 2
36 
37 namespace Common {
38 class SeekableSubReadStream;
39 }
40 
41 namespace Audio {
42 class Mixer;
43 class SoundHandle;
44 class SeekableAudioStream;
45 }
46 
47 namespace Scumm {
48 
49 class ScummEngine;
50 
51 struct MP3OffsetTable;
52 
53 enum {
54  kTalkSoundID = 10000
55 };
56 
57 // TODO: Consider splitting Sound into even more subclasses.
58 // E.g. for v1-v4, v5, v6+, ...
59 class Sound : public Common::Serializable {
60 public:
61  enum SoundMode {
62  kVOCMode,
63  kMP3Mode,
64  kVorbisMode,
65  kFLACMode
66  };
67 
68 protected:
69  ScummEngine *_vm;
70  Audio::Mixer *_mixer;
71 
72  Common::Mutex _speechTimerMutex;
73 
74  int16 _midiQueuePos, _midiQueue[0x100];
75  int16 _soundQueuePos;
76 
77  struct {
78  int16 sound;
79  int32 offset;
80  int16 channel;
81  int16 flags;
82  int16 freq;
83  int16 pan;
84  int16 vol;
85  } _soundQueue[10];
86 
87  Common::String _sfxFilename;
88  byte _sfxFileEncByte;
89  SoundMode _soundMode;
90  MP3OffsetTable *_offsetTable; // For compressed audio
91  int _numSoundEffects; // For compressed audio
92  int64 _cachedSfxLocationInPak = -1; // For sfx files in pak files
93  int32 _cachedSfxLengthInPak = 0; // For sfx files in pak files
94 
95  uint32 _queuedSfxOffset, _queuedTalkieOffset, _queuedSfxLen, _queuedTalkieLen;
96  byte _queuedSoundMode, _queuedSfxChannel;
97  bool _mouthSyncMode;
98  bool _endOfMouthSync;
99  uint16 _mouthSyncTimes[64];
100  uint _curSoundPos;
101 
102  int16 _currentMusic; // used by HE games
103 
104  SoundCD *_soundCD = nullptr;
105  SoundSE *_soundSE = nullptr;
106  bool _useRemasteredAudio = false;
107  bool _enableAmbienceSounds = false;
108 
109 public:
110  Audio::SoundHandle *_talkChannelHandle; // Handle of mixer channel actor is talking on
111 
112  bool _soundsPaused;
113  byte _digiSndMode;
114  uint _lastSound;
115  uint32 _speechTimerMod;
116 
117  MidiDriverFlags _musicType;
118 
119 public:
120  Sound(ScummEngine *parent, Audio::Mixer *mixer, bool useReplacementAudioTracks);
121  ~Sound() override;
122  virtual void startSound(int sound, int heOffset = 0, int heChannel = 0, int heFlags = 0, int heFreq = 0, int hePan = 0, int heVol = 0);
123  virtual void addSoundToQueue(int sound, int heOffset = 0, int heChannel = 0, int heFlags = 0, int heFreq = 0, int hePan = 0, int heVol = 0);
124  void processSound();
125  virtual void modifySound(int sound, int offset, int frequencyShift, int pan, int volume, int flags) {};
126 
127  void triggerSound(int soundID);
128  void startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle *handle = NULL);
129  void stopTalkSound();
130  bool isMouthSyncOff(uint pos);
131  virtual int isSoundRunning(int sound) const;
132  virtual bool isSoundInUse(int sound) const;
133  virtual void stopSound(int sound);
134  virtual void stopAllSounds();
135  void soundKludge(int *list, int num);
136  void talkSound(uint32 offset, uint32 length, int mode, int channel = 0);
137  virtual void setupSound();
138  virtual void pauseSounds(bool pause);
139  bool isSfxFileCompressed();
140  bool hasSfxFile() const;
141  ScummFile *restoreDiMUSESpeechFile(const char *fileName);
142  void extractSyncsFromDiMUSEMarker(const char *marker);
143  void incrementSpeechTimer();
144  void resetSpeechTimer();
145  void startSpeechTimer();
146  void stopSpeechTimer();
147  bool speechIsPlaying(); // Used within MIDI iMUSE
148 
149  void saveLoadWithSerializer(Common::Serializer &ser) override;
150  void restoreAfterLoad();
151 
152  bool isAudioDisabled();
153 
154  void updateMusicTimer();
155 
156  bool shouldInjectMISEAudio() const;
157  void startRemasteredSpeech(const char *msgString, uint16 roomNumber, uint16 actorTalking, uint16 numWaits);
158 
159  // TODO: Duplicate this in Sound as well?
160  bool isRolandLoom() const {
161  return _soundCD->isRolandLoom();
162  }
163 
164  // CD audio wrapper methods
165  int pollCD() const {
166  return _soundCD->pollCD();
167  }
168  void updateCD() {
169  _soundCD->updateCD();
170  }
171  void stopCD() {
172  _soundCD->stopCD();
173  _soundCD->stopCDTimer();
174  }
175  void playCDTrack(int track, int numLoops, int startFrame, int duration) {
176  _soundCD->playCDTrack(track, numLoops, startFrame, duration);
177  }
178  int getCurrentCDSound() const {
179  return _soundCD->getCurrentCDSound();
180  }
181  void restoreCDAudioAfterLoad(AudioCDManager::Status &info) {
182  _soundCD->restoreCDAudioAfterLoad(info);
183  }
184  void setupMISEAudioParams(int32 scriptNum, int32 scriptOffset) {
185  _soundSE->setupMISEAudioParams(scriptNum, scriptOffset);
186  }
187 
188 protected:
189  void setupSfxFile();
190  bool isSfxFinished() const;
191  void processSfxQueues();
192 
193  bool isSoundInQueue(int sound) const;
194 
195  virtual void processSoundQueues();
196 };
197 
198 
199 } // End of namespace Scumm
200 
201 #endif
Definition: audiocd.h:40
Definition: str.h:59
Definition: soundse.h:72
MidiDriverFlags
Definition: mididrv.h:83
Definition: sound.h:59
Definition: serializer.h:79
Definition: scumm.h:508
Definition: mixer.h:49
Definition: mixer.h:70
Definition: algorithm.h:29
Definition: mutex.h:67
Definition: soundcd.h:40
Definition: serializer.h:308
Definition: actor.h:30
Definition: system.h:38