ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
smush_player.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 #if !defined(SCUMM_SMUSH_PLAYER_H) && defined(ENABLE_SCUMM_7_8)
23 #define SCUMM_SMUSH_PLAYER_H
24 
25 #include "common/util.h"
26 
27 namespace Audio {
28 class SoundHandle;
29 class QueuingAudioStream;
30 }
31 
32 namespace Scumm {
33 
34 #define SMUSH_MAX_TRACKS 4
35 #define SMUSH_FADE_SIZE 0xC00
36 
37 #define IS_SFX 0x00
38 #define IS_BKG_MUSIC 0x40
39 #define IS_SPEECH 0x80
40 
41 #define CHN_BKGMUS 1
42 #define CHN_SPEECH 2
43 #define CHN_OTHER 3
44 
45 #define GRP_MASTER 0xFF01
46 #define GRP_SFX 0xFF02
47 #define GRP_BKGMUS 0xFF03
48 #define GRP_SPEECH 0xFF04
49 
50 #define TRK_STATE_INACTIVE 0
51 #define TRK_STATE_PLAYING 1
52 #define TRK_STATE_FADING 2
53 #define TRK_STATE_ENDING 3
54 
55 #define TRK_TYPE_MASK 0xC0
56 
57 #define SAUD_OP_INIT 1
58 #define SAUD_OP_UPDATE_HEADER 2
59 #define SAUD_OP_SET_PARAM 3
60 #define SAUD_OP_INCR_PARAM 4
61 #define SAUD_OP_SET_OFFSET 6
62 #define SAUD_OP_SET_LENGTH 7
63 #define SAUD_OP_COMPARE_GT 8
64 #define SAUD_OP_COMPARE_LT 9
65 #define SAUD_OP_COMPARE_EQ 10
66 #define SAUD_OP_COMPARE_NE 11
67 
68 #define SAUD_VALUEID_ALL_VOLS 0xFF
69 #define SAUD_VALUEID_TRK_VOL 0xFE
70 #define SAUD_VALUEID_TRK_PAN 0xFD
71 
72 #define TRK_USERID_SPEECH 1
73 #define TRK_USERID_MUSIC 2
74 #define TRK_USERID_SFX 3
75 
76 #define SMUSH_CODEC_RLE 1
77 #define SMUSH_CODEC_RLE_ALT 3
78 #define SMUSH_CODEC_UNCOMPRESSED 20
79 #define SMUSH_CODEC_DELTA_BLOCKS 37
80 #define SMUSH_CODEC_DELTA_GLYPHS 47
81 
82 class ScummEngine_v7;
83 class SmushFont;
84 class SmushMixer;
85 class StringResource;
86 class SmushDeltaBlocksDecoder;
87 class SmushDeltaGlyphsDecoder;
88 class IMuseDigital;
89 class Insane;
90 
91 class SmushPlayer {
92  friend class Insane;
93 private:
94  struct SmushAudioDispatch {
95  uint8 *headerPtr;
96  uint8 *dataBuf;
97  int32 dataSize;
98  int32 audioRemaining;
99  int32 currentOffset;
100  int sampleRate;
101  int state;
102  int fadeSampleRate;
103  int fadeVolume;
104  int32 fadeRemaining;
105  int volumeStep;
106  int32 elapsedAudio;
107  int32 audioLength;
108  };
109 
110  struct SmushAudioTrack {
111  uint8 *blockPtr;
112  uint8 *fadeBuf;
113  uint8 *dataBuf;
114  uint8 *subChunkPtr;
115  int32 blockSize;
116  byte volume;
117  byte pan;
118  int16 state;
119  int16 flags;
120  int groupId;
121  int parsedChunks;
122  int32 dataSize;
123  int32 availableSize;
124  int32 audioRemaining;
125  int32 sdatSize;
126  };
127 
128  ScummEngine_v7 *_vm;
129  IMuseDigital *_imuseDigital;
130  Insane *_insane;
131  int32 _nbframes;
132  int16 _deltaPal[0x300];
133  int32 _shiftedDeltaPal[0x300];
134  byte _pal[0x300];
135  SmushFont *_sf[5];
136  StringResource *_strings;
137  SmushDeltaBlocksDecoder *_deltaBlocksCodec;
138  SmushDeltaGlyphsDecoder *_deltaGlyphsCodec;
140  uint32 _baseSize;
141  byte *_frameBuffer;
142  byte *_specialBuffer;
143 
144  Common::String _seekFile;
145  uint32 _startFrame;
146  uint32 _startTime;
147  int32 _seekPos;
148  uint32 _seekFrame;
149 
150  bool _skipNext;
151  uint32 _frame;
152 
153  Audio::SoundHandle *_IACTchannel;
154  Audio::QueuingAudioStream *_IACTstream;
155 
156  Audio::SoundHandle *_compressedFileSoundHandle;
157  bool _compressedFileMode;
158  byte _IACToutput[4096];
159  int32 _IACTpos;
160  bool _storeFrame;
161  int _speed;
162  bool _endOfFile;
163 
164  byte *_dst;
165  bool _updateNeeded;
166  bool _warpNeeded;
167  int _palDirtyMin, _palDirtyMax;
168  int _warpX, _warpY;
169  int _warpButtons;
170  bool _insanity;
171  bool _middleAudio;
172  bool _skipPalette;
173  int _iactTable[4];
174 
175  SmushAudioTrack _smushTracks[SMUSH_MAX_TRACKS];
176  SmushAudioDispatch _smushDispatch[SMUSH_MAX_TRACKS];
177 
178  int _smushMaxFrames[SMUSH_MAX_TRACKS];
179  int _smushTrackIds[SMUSH_MAX_TRACKS];
180  int _smushTrackIdxs[SMUSH_MAX_TRACKS];
181  uint8 _smushAudioTable[256];
182  int _smushNumTracks;
183  int _smushTrackFlags[SMUSH_MAX_TRACKS];
184  int _smushTrackVols[SMUSH_MAX_TRACKS];
185 
186  int _smushAudioSampleRate;
187  int _gainReductionLowerBound;
188  int _gainReductionFactor;
189  int _gainReductionMultiplier;
190 
191  bool _smushTracksNeedInit;
192  bool _smushAudioInitialized;
193  bool _smushAudioCallbackEnabled;
194 
195 public:
196  SmushPlayer(ScummEngine_v7 *scumm, IMuseDigital *_imuseDigital, Insane *insane);
197  ~SmushPlayer();
198 
199  void pause();
200  void unpause();
201 
202  void play(const char *filename, int32 speed, int32 offset = 0, int32 startFrame = 0);
203  void release();
204  void warpMouse(int x, int y, int buttons);
205  int setChanFlag(int id, int flagVal);
206  void setGroupVolume(int groupId, int volValue);
207  void processDispatches(int16 feedSize);
208  bool isAudioCallbackEnabled();
209  byte *getVideoPalette();
210  void setCurVideoFlags(int16 flags);
211 
212 
213 protected:
214  int _width, _height;
215 
216  int _origPitch, _origNumStrips;
217  bool _paused;
218  uint32 _pauseStartTime;
219  uint32 _pauseTime;
220  int16 _curVideoFlags = 0;
221 
222  void insanity(bool);
223  void setPalette(const byte *palette);
224  void setPaletteValue(int n, byte r, byte g, byte b);
225  void setDirtyColors(int min, int max);
226  void seekSan(const char *file, int32 pos, int32 contFrame);
227  const char *getString(int id);
228 
229 private:
230  SmushFont *getFont(int font);
231  void parseNextFrame();
232  void init(int32 spped);
233  void setupAnim(const char *file);
234  void updateScreen();
235  void tryCmpFile(const char *filename);
236 
237  bool readString(const char *file);
238  void decodeFrameObject(int codec, const uint8 *src, int left, int top, int width, int height);
239  void handleAnimHeader(int32 subSize, Common::SeekableReadStream &);
240  void handleFrame(int32 frameSize, Common::SeekableReadStream &);
241  void handleNewPalette(int32 subSize, Common::SeekableReadStream &);
242  void handleZlibFrameObject(int32 subSize, Common::SeekableReadStream &b);
243  void handleFrameObject(int32 subSize, Common::SeekableReadStream &);
244  void handleSAUDChunk(uint8 *srcBuf, uint32 size, int groupId, int vol, int pan, int16 flags, int trkId, int index, int maxFrames);
245  void handleStore(int32 subSize, Common::SeekableReadStream &);
246  void handleFetch(int32 subSize, Common::SeekableReadStream &);
247  void handleIACT(int32 subSize, Common::SeekableReadStream &);
248  void handleTextResource(uint32 subType, int32 subSize, Common::SeekableReadStream &);
249  void handleDeltaPalette(int32 subSize, Common::SeekableReadStream &);
250  void readPalette(byte *, Common::SeekableReadStream &);
251 
252  void initAudio(int samplerate, int32 maxChunkSize);
253  void terminateAudio();
254  int isChanActive(int flagId);
255  int addAudioTrack(int32 trackBlockSize, int32 maxBlockSize);
256  void resetAudioTracks();
257  void setGainReductionParams(int16 gainReductionLowerBound, int16 gainReductionMultiplier);
258  void fillAudioTrackInfo(uint8 *srcBuf, uint16 *flagsAccumulator, uint32 size, int groupId, int vol, int pan, int16 flags, int trkId, int index, int maxFrames);
259  bool processAudioCodes(int idx, int32 &tmpFeedSize, int &mixVolume);
260  void feedAudio(uint8 *srcBuf, int groupId, int volume, int pan, int16 flags);
261  void sendAudioToDiMUSE(uint8 *mixBuf, int32 mixStartingPoint, int32 mixFeedSize, int32 mixInFrameCount, int volume, int pan);
262 
263  void timerCallback();
264 };
265 
266 } // End of namespace Scumm
267 
268 #endif
Definition: str.h:59
Definition: stream.h:745
Definition: mixer.h:49
Definition: audiostream.h:370
Definition: actor.h:30
Definition: system.h:38