File: smush_player.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (268 lines) | stat: -rw-r--r-- 7,522 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#if !defined(SCUMM_SMUSH_PLAYER_H) && defined(ENABLE_SCUMM_7_8)
#define SCUMM_SMUSH_PLAYER_H

#include "common/util.h"

namespace Audio {
class SoundHandle;
class QueuingAudioStream;
}

namespace Scumm {

#define SMUSH_MAX_TRACKS 4
#define SMUSH_FADE_SIZE  0xC00

#define IS_SFX       0x00
#define IS_BKG_MUSIC 0x40
#define IS_SPEECH    0x80

#define CHN_BKGMUS 1
#define CHN_SPEECH 2
#define CHN_OTHER  3

#define GRP_MASTER 0xFF01
#define GRP_SFX    0xFF02
#define GRP_BKGMUS 0xFF03
#define GRP_SPEECH 0xFF04

#define TRK_STATE_INACTIVE 0
#define TRK_STATE_PLAYING  1
#define TRK_STATE_FADING   2
#define TRK_STATE_ENDING   3

#define TRK_TYPE_MASK 0xC0

#define SAUD_OP_INIT          1
#define SAUD_OP_UPDATE_HEADER 2
#define SAUD_OP_SET_PARAM     3
#define SAUD_OP_INCR_PARAM    4
#define SAUD_OP_SET_OFFSET    6
#define SAUD_OP_SET_LENGTH    7
#define SAUD_OP_COMPARE_GT    8
#define SAUD_OP_COMPARE_LT    9
#define SAUD_OP_COMPARE_EQ    10
#define SAUD_OP_COMPARE_NE    11

#define SAUD_VALUEID_ALL_VOLS 0xFF
#define SAUD_VALUEID_TRK_VOL  0xFE
#define SAUD_VALUEID_TRK_PAN  0xFD

#define TRK_USERID_SPEECH 1
#define TRK_USERID_MUSIC  2
#define TRK_USERID_SFX    3

#define SMUSH_CODEC_RLE          1
#define SMUSH_CODEC_RLE_ALT      3
#define SMUSH_CODEC_UNCOMPRESSED 20
#define SMUSH_CODEC_DELTA_BLOCKS 37
#define SMUSH_CODEC_DELTA_GLYPHS 47

class ScummEngine_v7;
class SmushFont;
class SmushMixer;
class StringResource;
class SmushDeltaBlocksDecoder;
class SmushDeltaGlyphsDecoder;
class IMuseDigital;
class Insane;

class SmushPlayer {
	friend class Insane;
private:
	struct SmushAudioDispatch {
		uint8 *headerPtr;
		uint8 *dataBuf;
		int32 dataSize;
		int32 audioRemaining;
		int32 currentOffset;
		int sampleRate;
		int state;
		int fadeSampleRate;
		int fadeVolume;
		int32 fadeRemaining;
		int volumeStep;
		int32 elapsedAudio;
		int32 audioLength;
	};

	struct SmushAudioTrack {
		uint8 *blockPtr;
		uint8 *fadeBuf;
		uint8 *dataBuf;
		uint8 *subChunkPtr;
		int32 blockSize;
		byte volume;
		byte pan;
		int16 state;
		int16 flags;
		int groupId;
		int parsedChunks;
		int32 dataSize;
		int32 availableSize;
		int32 audioRemaining;
		int32 sdatSize;
	};

	ScummEngine_v7 *_vm;
	IMuseDigital *_imuseDigital;
	Insane *_insane;
	int32 _nbframes;
	int16 _deltaPal[0x300];
	int32 _shiftedDeltaPal[0x300];
	byte _pal[0x300];
	SmushFont *_sf[5];
	StringResource *_strings;
	SmushDeltaBlocksDecoder *_deltaBlocksCodec;
	SmushDeltaGlyphsDecoder *_deltaGlyphsCodec;
	Common::SeekableReadStream *_base;
	uint32 _baseSize;
	byte *_frameBuffer;
	byte *_specialBuffer;

	Common::String _seekFile;
	uint32 _startFrame;
	uint32 _startTime;
	int32 _seekPos;
	uint32 _seekFrame;

	bool _skipNext;
	uint32 _frame;

	Audio::SoundHandle *_IACTchannel;
	Audio::QueuingAudioStream *_IACTstream;

	Audio::SoundHandle *_compressedFileSoundHandle;
	bool _compressedFileMode;
	byte _IACToutput[4096];
	int32 _IACTpos;
	bool _storeFrame;
	int _speed;
	bool _endOfFile;

	byte *_dst;
	bool _updateNeeded;
	bool _warpNeeded;
	int _palDirtyMin, _palDirtyMax;
	int _warpX, _warpY;
	int _warpButtons;
	bool _insanity;
	bool _middleAudio;
	bool _skipPalette;
	int _iactTable[4];

	SmushAudioTrack _smushTracks[SMUSH_MAX_TRACKS];
	SmushAudioDispatch _smushDispatch[SMUSH_MAX_TRACKS];

	int _smushMaxFrames[SMUSH_MAX_TRACKS];
	int _smushTrackIds[SMUSH_MAX_TRACKS];
	int _smushTrackIdxs[SMUSH_MAX_TRACKS];
	uint8 _smushAudioTable[256];
	int _smushNumTracks;
	int _smushTrackFlags[SMUSH_MAX_TRACKS];
	int _smushTrackVols[SMUSH_MAX_TRACKS];

	int _smushAudioSampleRate;
	int _gainReductionLowerBound;
	int _gainReductionFactor;
	int _gainReductionMultiplier;

	bool _smushTracksNeedInit;
	bool _smushAudioInitialized;
	bool _smushAudioCallbackEnabled;

public:
	SmushPlayer(ScummEngine_v7 *scumm, IMuseDigital *_imuseDigital, Insane *insane);
	~SmushPlayer();

	void pause();
	void unpause();

	void play(const char *filename, int32 speed, int32 offset = 0, int32 startFrame = 0);
	void release();
	void warpMouse(int x, int y, int buttons);
	int setChanFlag(int id, int flagVal);
	void setGroupVolume(int groupId, int volValue);
	void processDispatches(int16 feedSize);
	bool isAudioCallbackEnabled();
	byte *getVideoPalette();
	void setCurVideoFlags(int16 flags);


protected:
	int _width, _height;

	int _origPitch, _origNumStrips;
	bool _paused;
	uint32 _pauseStartTime;
	uint32 _pauseTime;
	int16 _curVideoFlags = 0;

	void insanity(bool);
	void setPalette(const byte *palette);
	void setPaletteValue(int n, byte r, byte g, byte b);
	void setDirtyColors(int min, int max);
	void seekSan(const char *file, int32 pos, int32 contFrame);
	const char *getString(int id);

private:
	SmushFont *getFont(int font);
	void parseNextFrame();
	void init(int32 spped);
	void setupAnim(const char *file);
	void updateScreen();
	void tryCmpFile(const char *filename);

	bool readString(const char *file);
	void decodeFrameObject(int codec, const uint8 *src, int left, int top, int width, int height);
	void handleAnimHeader(int32 subSize, Common::SeekableReadStream &);
	void handleFrame(int32 frameSize, Common::SeekableReadStream &);
	void handleNewPalette(int32 subSize, Common::SeekableReadStream &);
	void handleZlibFrameObject(int32 subSize, Common::SeekableReadStream &b);
	void handleFrameObject(int32 subSize, Common::SeekableReadStream &);
	void handleSAUDChunk(uint8 *srcBuf, uint32 size, int groupId, int vol, int pan, int16 flags, int trkId, int index, int maxFrames);
	void handleStore(int32 subSize, Common::SeekableReadStream &);
	void handleFetch(int32 subSize, Common::SeekableReadStream &);
	void handleIACT(int32 subSize, Common::SeekableReadStream &);
	void handleTextResource(uint32 subType, int32 subSize, Common::SeekableReadStream &);
	void handleDeltaPalette(int32 subSize, Common::SeekableReadStream &);
	void readPalette(byte *, Common::SeekableReadStream &);

	void initAudio(int samplerate, int32 maxChunkSize);
	void terminateAudio();
	int isChanActive(int flagId);
	int addAudioTrack(int32 trackBlockSize, int32 maxBlockSize);
	void resetAudioTracks();
	void setGainReductionParams(int16 gainReductionLowerBound, int16 gainReductionMultiplier);
	void fillAudioTrackInfo(uint8 *srcBuf, uint16 *flagsAccumulator, uint32 size, int groupId, int vol, int pan, int16 flags, int trkId, int index, int maxFrames);
	bool processAudioCodes(int idx, int32 &tmpFeedSize, int &mixVolume);
	void feedAudio(uint8 *srcBuf, int groupId, int volume, int pan, int16 flags);
	void sendAudioToDiMUSE(uint8 *mixBuf, int32 mixStartingPoint, int32 mixFeedSize, int32 mixInFrameCount, int volume, int pan);

	void timerCallback();
};

} // End of namespace Scumm

#endif