summaryrefslogtreecommitdiff
path: root/psxdev/xadecode.h
blob: 560ae73ba6c2cf90b308ba487a80642744ffe4a7 (plain)
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
/*
	author: unknown, probably bitmaster?
	slightly modified by dbalster
*/

#include "generic.h"

#ifndef XADECODE_H
#define XADECODE_H

#define USE_FXD 1

#define kNumOfSamples   224
#define kNumOfSGs       18

#define XAFile			0
#define XAChannel		1
#define XAType			2
#define XAFlags			3
/* bits in XAFlags byte */
#define XAFStereo		1<<0
#define XAFHalfHz		1<<2

#define XAAUDIO		0x64
#define XAVIDEO		0x48
#define XABREAK		0xE4
#define XACURRENT	0x100	/* for application use only! */
#define XANONE		0x200	/* for application use only! */
#define XAAV		0x400	/* for application use only! */

#ifndef max
#define max(a,b) (a<b?b:a)
#define min(a,b) (a>b?b:a)
#endif

#define FXD_FxdToPCM(dt)			(max(min((short)((dt)>>16), 32767), -32768))
#define DblToPCM(dt)				(short)(max(min((dt), 32767), -32768))

#define WHP_READ68_AUTO(fp, dt)		WHP_Read68(dt, sizeof(*(dt)), 1, fp)
#define WHP_WRITE68_AUTO(fp, dt)	WHP_Write68(dt, sizeof(*(dt)), 1, fp)

#define WHP_CNV_SHORT68(dt, ndt)	WHP_CnvEndianShort((dt), (ndt))
#define WHP_CNV_LONG68(dt, ndt)		WHP_CnvEndianLong((dt), (ndt))

#if USE_FXD
#define FXD_FxdToPcm16(dt)			(max(min((dt)/2, 32767), -32768))
#define FXD_Pcm16ToFxd(dt)			((long)dt*2)
#endif

#define XAWAVBUFSIZE (kNumOfSamples*kNumOfSGs*2)

typedef char SoundGroup[128];

typedef struct SoundSector {
	char            sectorFiller[8];
	SoundGroup      SoundGroups[kNumOfSGs];
} PACKED SoundSector;

typedef unsigned long DWORD;
typedef unsigned short WORD;

#if USE_FXD
typedef long FXD;
#endif

#ifdef __cplusplus
extern "C" {
#endif

long decodeSoundSect(SoundSector *ssct, char *wav);
long decodeSoundSect1(SoundSector *ssct, char *wav);
long convXaToWave(char *adp, char *wav, int cn, int fn_s, int fn_e);
void initXaDecode(void);
void switchXaDecode(int channel);
void saveXaDecode(int channel);
void reinitXaDecode(int channel);
signed char getSoundData(char *buf, long unit, long sample);
signed char getFilter(char *buf, long unit);
signed char getRange(char *buf, long unit);
char xachannel(SoundSector *ss);
unsigned char xatype(SoundSector *ss);
char xafileno(SoundSector *ss);
char xastereo(SoundSector *ss);
char xahalfhz(SoundSector *ss);

#if USE_FXD
FXD FXD_FixMul(FXD a, FXD b);
#endif

#ifdef __cplusplus
}
#endif

#endif