ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
soundse.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_SOUNDSE_H
23 #define SCUMM_SOUNDSE_H
24 
25 #include "common/scummsys.h"
26 #include "audio/audiostream.h"
27 #include "audio/mixer.h"
28 #include "scumm/file.h"
29 
30 namespace Common {
31 class SeekableSubReadStream;
32 }
33 
34 namespace Audio {
35 class WMACodec;
36 }
37 
38 namespace Scumm {
39 
40 class ScummEngine;
41 
42 enum SoundSEType {
43  kSoundSETypeMusic,
44  kSoundSETypeCDAudio,
45  kSoundSETypeSpeech,
46  kSoundSETypeSFX,
47  kSoundSETypeAmbience,
48  kSoundSETypeCommentary,
49  kSoundSETypePatch
50 };
51 
52 enum AudioCodec {
53  kXWBCodecPCM = 0,
54  kXWBCodecXMA = 1,
55  kXWBCodecADPCM = 2,
56  kXWBCodecWMA = 3,
57  kFSBCodecMP3 = 4
58 };
59 
60 struct AudioEntry {
61  uint64 offset;
62  uint32 length;
63  AudioCodec codec;
64  byte channels;
65  uint16 rate;
66  uint16 align;
67  byte bits;
68  Common::String name;
69  bool isPatched;
70 };
71 
72 class SoundSE {
73 
74 public:
75  SoundSE(ScummEngine *parent, Audio::Mixer *mixer);
76  ~SoundSE() = default;
77 
78  Audio::SeekableAudioStream *getAudioStreamFromIndex(int32 index, SoundSEType type);
79  Audio::SeekableAudioStream *getAudioStreamFromOffset(uint32 offset, SoundSEType type);
80 
81  int32 handleMISESpeech(const char *msgString,
82  const char *speechFilenameSubstitution,
83  uint16 roomNumber,
84  uint16 actorTalking,
85  uint16 numWaits);
86 
87  void setupMISEAudioParams(int32 scriptNum, int32 scriptOffset) {
88  _currentScriptSavedForSpeechMI = scriptNum;
89  _currentScriptOffsetSavedForSpeechMI = scriptOffset;
90  }
91 
92  void startAmbience(int32 musicTrack);
93  void stopAmbience();
94 
95 private:
96  enum XWBSegmentType {
97  kXWBSegmentBankData = 0,
98  kXWBSegmentEntryMetaData = 1,
99  kXWBSegmentSeekTables = 2,
100  kXWBSegmentEntryNames = 3,
101  kXWBSegmentEntryWaveData = 4
102  };
103 
104  // Used in MI1 + MI2
105  struct AudioEntryMI {
106  uint32 hash;
107  uint16 room;
108  uint16 script;
109  uint16 localScriptOffset;
110  uint16 messageIndex; // message index, used in messages split with wait()
111  uint16 isEgoTalking; // 1 if ego is talking, 0 otherwise
112  uint16 wait; // wait time in ms
113  Common::String textEnglish; // 256 bytes, English text
114  Common::String textFrench; // 256 bytes, French text
115  Common::String textItalian; // 256 bytes, Italian text
116  Common::String textGerman; // 256 bytes, German text
117  Common::String textSpanish; // 256 bytes, Spanish text
118  Common::String speechFile; // 32 bytes
119 
120  int32 hashFourCharString; // Hash calculated on a four char string, from disasm
121  };
122 
123  ScummEngine *_vm;
124  Audio::Mixer *_mixer;
125 
130 
131  OffsetToIndexMap _offsetToIndexDOTTAndFT;
132  NameToOffsetMap _nameToOffsetDOTTAndFT;
133  NameToIndexMap _nameToIndexMISpeech;
134  NameToIndexMap _nameToIndexMISpeechPatched;
135 
136  AudioIndex _musicEntries;
137  AudioIndex _speechEntries;
138  AudioIndex _sfxEntries;
139  AudioIndex _ambienceEntries;
140  AudioIndex _commentaryEntries;
141  AudioIndex _patchEntries;
142 
144  AudioIndexMI _audioEntriesMI;
145 
146  /* MI SE injected speech */
147  int32 _currentScriptSavedForSpeechMI = 0;
148  int32 _currentScriptOffsetSavedForSpeechMI = 0;
149 
150  Audio::SoundHandle _ambienceHandle;
151 
152  int32 getSoundIndexFromOffset(uint32 offset);
153  int32 getAppropriateSpeechCue(const char *msgString,
154  const char *speechFilenameSubstitution,
155  uint16 roomNumber,
156  uint16 actorTalking,
157  uint16 scriptNum,
158  uint16 scriptOffset,
159  uint16 numWaits);
160 
161  void initAudioMappingMI();
162  void initAudioMappingDOTTAndFT();
163  void initSoundFiles();
164 
165  // Index XWB audio files and XSB cue files - used in MI1SE and MI2SE
166  void indexXWBFile(SoundSEType type);
167  void indexSpeechXSBFile();
168 
169  // Index FSB audio files - used in DOTT and FT
170  void indexFSBFile(SoundSEType type);
171 
172  Common::String getAudioFilename(SoundSEType type);
173  Common::SeekableReadStream *getAudioFile(const Common::String &filename);
174  Common::SeekableReadStream *getAudioFile(SoundSEType type);
175  AudioIndex *getAudioEntries(SoundSEType type);
176  int32 getAmbienceTrack(int32 musicTrack);
177 
178  Audio::SeekableAudioStream *createSoundStream(Common::SeekableSubReadStream *stream, AudioEntry entry, DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::YES);
179 };
180 
181 #if 0
182 
185 class HeaderlessWMAStream : public Audio::SeekableAudioStream {
186 public:
187  HeaderlessWMAStream(Common::SeekableReadStream *stream,
188  AudioEntry entry,
189  DisposeAfterUse::Flag disposeAfterUse);
190  ~HeaderlessWMAStream() override;
191 
192  int readBuffer(int16 *buffer, const int numSamples) override;
193 
194  bool endOfData() const override { return _stream->eos(); }
195  bool isStereo() const override { return _entry.channels == 2; }
196  int getRate() const override { return _entry.rate; }
197  Audio::Timestamp getLength() const override {
198  return Audio::Timestamp(_entry.length / 10000, _entry.rate);
199  }
200  bool seek(const Audio::Timestamp &where) override;
201 
202 private:
203  Common::SeekableReadStream *_stream = nullptr;
204  AudioStream *_audioStream = nullptr;
205  AudioEntry _entry;
206  DisposeAfterUse::Flag _disposeAfterUse;
207  Audio::WMACodec *_wmaCodec = nullptr;
208 };
209 #endif
210 
211 } // End of namespace Scumm
212 
213 #endif
Definition: str.h:59
Definition: soundse.h:72
Definition: timestamp.h:83
Definition: stream.h:745
Definition: soundse.h:60
Definition: audiostream.h:212
Definition: scumm.h:504
Definition: mixer.h:49
Definition: mixer.h:59
Definition: substream.h:78
Definition: algorithm.h:29
Definition: wma.h:46
Definition: actor.h:30
Definition: system.h:38