ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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  int16 _midiQueuePos, _midiQueue[0x100];
73  int16 _soundQueuePos;
74 
75  struct {
76  int16 sound;
77  int32 offset;
78  int16 channel;
79  int16 flags;
80  int16 freq;
81  int16 pan;
82  int16 vol;
83  } _soundQueue[10];
84 
85  Common::String _sfxFilename;
86  byte _sfxFileEncByte;
87  SoundMode _soundMode;
88  MP3OffsetTable *_offsetTable; // For compressed audio
89  int _numSoundEffects; // For compressed audio
90  int64 _cachedSfxLocationInPak = -1; // For sfx files in pak files
91  int32 _cachedSfxLengthInPak = 0; // For sfx files in pak files
92 
93  uint32 _queuedSfxOffset, _queuedTalkieOffset, _queuedSfxLen, _queuedTalkieLen;
94  byte _queuedSoundMode, _queuedSfxChannel;
95  bool _mouthSyncMode;
96  bool _endOfMouthSync;
97  uint16 _mouthSyncTimes[64];
98  uint _curSoundPos;
99 
100  int16 _currentMusic; // used by HE games
101 
102  SoundCD *_soundCD = nullptr;
103  SoundSE *_soundSE = nullptr;
104  bool _useRemasteredAudio = false;
105  bool _enableAmbienceSounds = false;
106 
107 public:
108  Audio::SoundHandle *_talkChannelHandle; // Handle of mixer channel actor is talking on
109 
110  bool _soundsPaused;
111  byte _digiSndMode;
112  uint _lastSound;
113  uint32 _speechTimerMod;
114 
115  MidiDriverFlags _musicType;
116 
117 public:
118  Sound(ScummEngine *parent, Audio::Mixer *mixer, bool useReplacementAudioTracks);
119  ~Sound() override;
120  virtual void startSound(int sound, int heOffset = 0, int heChannel = 0, int heFlags = 0, int heFreq = 0, int hePan = 0, int heVol = 0);
121  virtual void addSoundToQueue(int sound, int heOffset = 0, int heChannel = 0, int heFlags = 0, int heFreq = 0, int hePan = 0, int heVol = 0);
122  void processSound();
123  virtual void modifySound(int sound, int offset, int frequencyShift, int pan, int volume, int flags) {};
124 
125  void triggerSound(int soundID);
126  void startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle *handle = NULL);
127  void stopTalkSound();
128  bool isMouthSyncOff(uint pos);
129  virtual int isSoundRunning(int sound) const;
130  virtual bool isSoundInUse(int sound) const;
131  virtual void stopSound(int sound);
132  virtual void stopAllSounds();
133  void soundKludge(int *list, int num);
134  void talkSound(uint32 offset, uint32 length, int mode, int channel = 0);
135  virtual void setupSound();
136  virtual void pauseSounds(bool pause);
137  bool isSfxFileCompressed();
138  bool hasSfxFile() const;
139  ScummFile *restoreDiMUSESpeechFile(const char *fileName);
140  void extractSyncsFromDiMUSEMarker(const char *marker);
141  void incrementSpeechTimer();
142  void resetSpeechTimer();
143  void startSpeechTimer();
144  void stopSpeechTimer();
145  bool speechIsPlaying(); // Used within MIDI iMUSE
146 
147  void saveLoadWithSerializer(Common::Serializer &ser) override;
148  void restoreAfterLoad();
149 
150  bool isAudioDisabled();
151 
152  void updateMusicTimer();
153 
154  bool shouldInjectMISEAudio() const;
155  void startRemasteredSpeech(const char *msgString, uint16 roomNumber, uint16 actorTalking, uint16 numWaits);
156 
157  // TODO: Duplicate this in Sound as well?
158  bool isRolandLoom() const {
159  return _soundCD->isRolandLoom();
160  }
161 
162  // CD audio wrapper methods
163  int pollCD() const {
164  return _soundCD->pollCD();
165  }
166  void updateCD() {
167  _soundCD->updateCD();
168  }
169  void stopCD() {
170  _soundCD->stopCD();
171  _soundCD->stopCDTimer();
172  }
173  void playCDTrack(int track, int numLoops, int startFrame, int duration) {
174  _soundCD->playCDTrack(track, numLoops, startFrame, duration);
175  }
176  int getCurrentCDSound() const {
177  return _soundCD->getCurrentCDSound();
178  }
179  void restoreCDAudioAfterLoad(AudioCDManager::Status &info) {
180  _soundCD->restoreCDAudioAfterLoad(info);
181  }
182  void setupMISEAudioParams(int32 scriptNum, int32 scriptOffset) {
183  _soundSE->setupMISEAudioParams(scriptNum, scriptOffset);
184  }
185 
186 protected:
187  void setupSfxFile();
188  bool isSfxFinished() const;
189  void processSfxQueues();
190 
191  bool isSoundInQueue(int sound) const;
192 
193  virtual void processSoundQueues();
194 };
195 
196 
197 } // End of namespace Scumm
198 
199 #endif
Definition: audiocd.h:40
Definition: str.h:59
Definition: soundse.h:72
MidiDriverFlags
Definition: mididrv.h:81
Definition: sound.h:59
Definition: serializer.h:79
Definition: scumm.h:504
Definition: mixer.h:49
Definition: mixer.h:59
Definition: algorithm.h:29
Definition: soundcd.h:40
Definition: serializer.h:308
Definition: actor.h:30
Definition: system.h:38