-
Notifications
You must be signed in to change notification settings - Fork 20
/
paf.h
131 lines (112 loc) · 3.13 KB
/
paf.h
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
/*
* Heart of Darkness engine rewrite
* Copyright (C) 2009-2011 Gregory Montoir (cyx@users.sourceforge.net)
*/
#ifndef PAF_PLAYER_H__
#define PAF_PLAYER_H__
#include "intern.h"
#include "defs.h"
#include "fileio.h"
struct PafHeader {
uint32_t preloadFrameBlocksCount;
uint32_t *frameBlocksCountTable;
uint32_t *framesOffsetTable;
uint32_t *frameBlocksOffsetTable;
int32_t framesCount;
int32_t frameBlocksCount;
uint32_t startOffset;
uint32_t readBufferSize;
int32_t maxVideoFrameBlocksCount;
int32_t maxAudioFrameBlocksCount;
int32_t frameDuration;
};
// names taken from the PSX filenames
enum {
kPafAnimation_intro = 0,
kPafAnimation_cine14l = 1,
kPafAnimation_rapt = 2,
kPafAnimation_glisse = 3,
kPafAnimation_meeting = 4,
kPafAnimation_island = 5,
kPafAnimation_islefall = 6,
kPafAnimation_vicious = 7,
kPafAnimation_together = 8,
kPafAnimation_power = 9,
kPafAnimation_back = 10,
kPafAnimation_dogfree1 = 11,
kPafAnimation_dogfree2 = 12,
kPafAnimation_meteor = 13,
kPafAnimation_cookie = 14,
kPafAnimation_plot = 15,
kPafAnimation_puzzle = 16,
kPafAnimation_lstpiece = 17,
kPafAnimation_dogfall = 18,
kPafAnimation_lastfall = 19,
kPafAnimation_end = 20,
kPafAnimation_cinema = 21,
kPafAnimation_CanyonAndyFallingCannon = 22, // kPafAnimation_ghct
kPafAnimation_CanyonAndyFalling = 23, // kPafAnimation_chute
kPafAnimation_IslandAndyFalling = 24 // kPafAnimation_chute_i
};
struct FileSystem;
struct PafAudioQueue {
int16_t *buffer; // stereo samples
int offset, size;
PafAudioQueue *next;
};
struct PafCallback {
void (*frameProc)(void *userdata, int num, const uint8_t *frame);
void (*endProc)(void *userdata);
void *userdata;
};
struct PafPlayer {
enum {
kMaxVideosCount = 50,
kBufferBlockSize = 2048,
kVideoWidth = 256,
kVideoHeight = 192,
kPageBufferSize = 256 * 256,
kAudioSamples = 2205,
kAudioStrideSize = 4922 // 256 * sizeof(int16_t) + 2205 * 2
};
bool _skipCutscenes;
FileSystem *_fs;
File _file;
int _videoNum;
uint32_t _videoOffset;
PafHeader _pafHdr;
int _currentPageBuffer;
uint8_t *_pageBuffers[4];
uint8_t _paletteBuffer[256 * 3];
bool _paletteChanged;
uint8_t _bufferBlock[kBufferBlockSize];
uint8_t *_demuxVideoFrameBlocks;
uint8_t *_demuxAudioFrameBlocks;
uint32_t _audioBufferOffsetRd;
uint32_t _audioBufferOffsetWr;
PafAudioQueue *_audioQueue, *_audioQueueTail;
uint32_t _flushAudioSize;
uint32_t _playedMask;
PafCallback _pafCb;
int _volume;
int _frameMs;
PafPlayer(FileSystem *fs);
~PafPlayer();
void setVolume(int volume);
void preload(int num);
void play(int num);
void unload(int num = -1);
bool readPafHeader();
uint32_t *readPafHeaderTable(int count);
void decodeVideoFrame(const uint8_t *src);
uint8_t *getVideoPageOffset(uint16_t val);
void decodeVideoFrameOp0(const uint8_t *base, const uint8_t *src, uint8_t code);
void decodeVideoFrameOp1(const uint8_t *src);
void decodeVideoFrameOp2(const uint8_t *src);
void decodeVideoFrameOp4(const uint8_t *src);
void decodeAudioFrame(const uint8_t *src, uint32_t offset, uint32_t size);
void mix(int16_t *buf, int samples);
void mainLoop();
void setCallback(const PafCallback *pafCb);
};
#endif // PAF_PLAYER_H__