Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MorsGames
GitHub Repository: MorsGames/sm64plus
Path: blob/master/tools/sdk-tools/adpcm/vadpcm.h
7861 views
1
#ifndef VADPCM_H
2
#define VADPCM_H
3
4
#include <stdio.h>
5
6
typedef signed char s8;
7
typedef short s16;
8
typedef int s32;
9
typedef long long s64;
10
typedef unsigned char u8;
11
typedef unsigned short u16;
12
typedef unsigned int u32;
13
typedef unsigned long long u64;
14
typedef float f32;
15
typedef double f64;
16
17
#ifdef __sgi
18
# define BSWAP16(x)
19
# define BSWAP32(x)
20
# define BSWAP16_MANY(x, n)
21
#else
22
# define BSWAP16(x) x = __builtin_bswap16(x);
23
# define BSWAP32(x) x = __builtin_bswap32(x);
24
# define BSWAP16_MANY(x, n) { s32 _i; for (_i = 0; _i < n; _i++) BSWAP16((x)[_i]) }
25
#endif
26
27
#ifdef __sgi
28
# define MODE_READ "r"
29
# define MODE_WRITE "w"
30
#else
31
# define MODE_READ "rb"
32
# define MODE_WRITE "wb"
33
#endif
34
35
typedef struct {
36
u32 ckID;
37
u32 ckSize;
38
} ChunkHeader;
39
40
typedef struct {
41
u32 ckID;
42
u32 ckSize;
43
u32 formType;
44
} Chunk;
45
46
typedef struct {
47
s16 numChannels;
48
u16 numFramesH;
49
u16 numFramesL;
50
s16 sampleSize;
51
s16 sampleRate[5]; // 80-bit float
52
u16 compressionTypeH;
53
u16 compressionTypeL;
54
} CommonChunk;
55
56
typedef struct {
57
s16 MarkerID;
58
u16 positionH;
59
u16 positionL;
60
} Marker;
61
62
typedef struct {
63
s16 playMode;
64
s16 beginLoop;
65
s16 endLoop;
66
} Loop;
67
68
typedef struct {
69
s8 baseNote;
70
s8 detune;
71
s8 lowNote;
72
s8 highNote;
73
s8 lowVelocity;
74
s8 highVelocity;
75
s16 gain;
76
Loop sustainLoop;
77
Loop releaseLoop;
78
} InstrumentChunk;
79
80
typedef struct {
81
s32 offset;
82
s32 blockSize;
83
} SoundDataChunk;
84
85
typedef struct {
86
s16 version;
87
s16 order;
88
s16 nEntries;
89
} CodeChunk;
90
91
typedef struct
92
{
93
u32 start;
94
u32 end;
95
u32 count;
96
s16 state[16];
97
} ALADPCMloop;
98
99
// vpredictor.c
100
s32 readcodebook(FILE *fhandle, s32 ****table, s32 *order, s32 *npredictors);
101
s32 readaifccodebook(FILE *fhandle, s32 ****table, s16 *order, s16 *npredictors);
102
s32 inner_product(s32 length, s32 *v1, s32 *v2);
103
104
// quant.c
105
s16 qsample(f32 x, s32 scale);
106
void clamp(s32 fs, f32 *e, s32 *ie, s32 bits);
107
s32 clip(s32 ix, s32 llevel, s32 ulevel);
108
109
// vdecode.c
110
void vdecodeframe(FILE *ifile, s32 *outp, s32 order, s32 ***coefTable);
111
112
// vencode.c
113
void vencodeframe(FILE *ofile, s16 *inBuffer, s32 *state, s32 ***coefTable, s32 order, s32 npredictors, s32 nsam);
114
115
// util.c
116
u32 readbits(u32 nbits, FILE *ifile);
117
char *ReadPString(FILE *ifile);
118
s32 lookupMarker(u32 *sample, s16 loopPoint, Marker *markers, s32 nmarkers);
119
ALADPCMloop *readlooppoints(FILE *ifile, s16 *nloops);
120
121
// sampleio.c
122
void writeout(FILE *outfd, s32 size, s32 *l_out, s32 *r_out, s32 chans);
123
124
#endif
125
126