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 "backends/audiocd/audiocd.h"
30 #include "scumm/file.h"
31 
32 // The number of "ticks" (1/10th of a second) into the Overture that the
33 // LucasFilm logo should appear. This corresponds to a timer value of 204.
34 // The default value is selected to work well with the Ozawa recording.
35 
36 #define DEFAULT_LOOM_OVERTURE_TRANSITION 1160
37 
38 #define DIGI_SND_MODE_EMPTY 0
39 #define DIGI_SND_MODE_SFX 1
40 #define DIGI_SND_MODE_TALKIE 2
41 
42 namespace Audio {
43 class Mixer;
44 class SoundHandle;
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 
91  uint32 _queuedSfxOffset, _queuedTalkieOffset, _queuedSfxLen, _queuedTalkieLen;
92  byte _queuedSoundMode, _queuedSfxChannel;
93  bool _mouthSyncMode;
94  bool _endOfMouthSync;
95  uint16 _mouthSyncTimes[64];
96  uint _curSoundPos;
97 
98  int16 _currentCDSound;
99  int16 _currentMusic;
100 
101  Audio::SoundHandle *_loomSteamCDAudioHandle;
102  bool _isLoomSteam;
103  AudioCDManager::Status _loomSteamCD;
104  bool _useReplacementAudioTracks;
105  int _musicTimer;
106  int _loomOvertureTransition;
107  uint32 _replacementTrackStartTime;
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 _cdMusicTimerMod;
116  uint32 _cdMusicTimer;
117  uint32 _speechTimerMod;
118 
119  MidiDriverFlags _musicType;
120 
121 public:
122  Sound(ScummEngine *parent, Audio::Mixer *mixer, bool useReplacementAudioTracks);
123  ~Sound() override;
124  virtual void startSound(int sound, int heOffset = 0, int heChannel = 0, int heFlags = 0, int heFreq = 0, int hePan = 0, int heVol = 0);
125  virtual void addSoundToQueue(int sound, int heOffset = 0, int heChannel = 0, int heFlags = 0, int heFreq = 0, int hePan = 0, int heVol = 0);
126  void processSound();
127  virtual void modifySound(int sound, int offset, int frequencyShift, int pan, int volume, int flags) {};
128 
129  void triggerSound(int soundID);
130  void startTalkSound(uint32 offset, uint32 b, int mode, Audio::SoundHandle *handle = NULL);
131  void stopTalkSound();
132  bool isMouthSyncOff(uint pos);
133  virtual int isSoundRunning(int sound) const;
134  virtual bool isSoundInUse(int sound) const;
135  virtual void stopSound(int sound);
136  virtual void stopAllSounds();
137  void soundKludge(int *list, int num);
138  void talkSound(uint32 offset, uint32 length, int mode, int channel = 0);
139  virtual void setupSound();
140  virtual void pauseSounds(bool pause);
141  bool isSfxFileCompressed();
142  bool hasSfxFile() const;
143  ScummFile *restoreDiMUSESpeechFile(const char *fileName);
144  void extractSyncsFromDiMUSEMarker(const char *marker);
145  void incrementSpeechTimer();
146  void resetSpeechTimer();
147  void startSpeechTimer();
148  void stopSpeechTimer();
149  bool speechIsPlaying(); // Used within MIDI iMUSE
150 
151  void startCDTimer();
152  void stopCDTimer();
153 
154  void playCDTrack(int track, int numLoops, int startFrame, int duration);
155  void playCDTrackInternal(int track, int numLoops, int startFrame, int duration);
156  void stopCD();
157  int pollCD() const;
158  void updateCD();
159  AudioCDManager::Status getCDStatus();
160  int getCurrentCDSound() const { return _currentCDSound; }
161  int getCDTrackIdFromSoundId(int soundId, int &loops, int &start);
162  bool isRolandLoom() const;
163  bool useReplacementAudio() const { return _useReplacementAudioTracks; }
164  void updateMusicTimer();
165  int getMusicTimer() const { return _musicTimer; }
166  int getCDMusicTimer() const { return _cdMusicTimer; }
167 
168  void saveLoadWithSerializer(Common::Serializer &ser) override;
169  void restoreAfterLoad();
170 
171  bool isAudioDisabled();
172 
173 protected:
174  void setupSfxFile();
175  bool isSfxFinished() const;
176  void processSfxQueues();
177 
178  bool isSoundInQueue(int sound) const;
179 
180  virtual void processSoundQueues();
181 
182  int getReplacementAudioTrack(int soundID);
183 };
184 
185 
186 } // End of namespace Scumm
187 
188 #endif
Definition: audiocd.h:40
Definition: str.h:59
MidiDriverFlags
Definition: mididrv.h:81
Definition: sound.h:59
Definition: serializer.h:79
Definition: scumm.h:518
Definition: mixer.h:49
Definition: mixer.h:59
Definition: serializer.h:308
Definition: file.h:63
Definition: actor.h:30
Definition: system.h:38