vadpcm.h
3.77 KB
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
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <libaudio.h>
#define VERSION 1
#define FRAMEBYTES 9
#define FRAMESIZE 16
#define VECTORSIZE 8
#define HEADERBITS 8
#define SAMPLEBITS 4
#define MAXSCALE 12
#define MAXCLIP 1
#define MAXITER 2
#define MINLOOPLENGTH 800
#define DEFAULT_NPREDICTORS 4
#define DEFAULT_ORDER 2
#define VSCALING 2048
#define IFF_ID_FORM 'FORM'
#define IFF_ID_AIFC 'AIFC'
#define IFF_ID_AIFF 'AIFF'
#define IFF_ID_COMM 'COMM'
#define IFF_ID_SSND 'SSND'
#define IFF_ID_INST 'INST'
#define IFF_ID_APPL 'APPL'
#define IFF_ID_MARK 'MARK'
#define CODE_NAME "VADPCMCODES"
#define LOOP_NAME "VADPCMLOOPS"
#define NoLooping 0
#define ForwardLooping 1
#define ForwardBackwardLooping 2
typedef struct {
unsigned long ckID;
long ckSize;
} ChunkHeader;
typedef struct {
unsigned long ckID;
long ckSize;
unsigned long formType;
} Chunk;
typedef struct {
short numChannels;
unsigned short numFramesH;
unsigned short numFramesL; /* To prevent 4 byte alignment */
short sampleSize;
char sampleRate[10];
unsigned short compressionTypeH;
unsigned short compressionTypeL; /* note: string follows */
} CommonChunk;
typedef short MarkerID;
typedef struct {
MarkerID id;
unsigned short positionH;
unsigned short positionL; /* note: pstring follows */
} Marker;
typedef struct {
short playMode;
MarkerID beginLoop;
MarkerID endLoop;
} Loop;
/* typedef struct {
long start;
long end;
long count;
short state[FRAMESIZE];
} Aloop;
*/
typedef struct {
char baseNote;
char detune;
char lowNote;
char highNote;
char lowVelocity;
char highVelocity;
short gain;
Loop sustainLoop;
Loop releaseLoop;
} InstrumentChunk;
typedef struct {
unsigned long offset;
unsigned long blockSize;
} SoundDataChunk;
typedef struct {
short version;
short order;
short nEntries;
} CodeChunk;
typedef struct {
unsigned long hi;
unsigned long lo;
} IEEE_DBL;
typedef struct {
unsigned long l1;
unsigned long l2;
unsigned short s1;
} SANE_EXT;
/* vpredictor.c */
int inner_product(int size, int *v1, int *v2);
int readaifccodebook(FILE *fhandle, int ****table, short *order, short *npredictors);
int readcodebook(FILE *fhandle, int ****table, int *order, int *npredictors);
/* vencode.c */
int vencodeframe(FILE *ofile, short *inBuffer, int *state, int ***coefTable, int order, int npredictors, int nsam);
/* vdecode.c */
void vdecodeframe(FILE *ifile, int *outp, int order, int ***coefTable);
/* vquant.c */
short qsample(float x, int scale);
void clamp(int fs, float *e, int *ie, int bits);
int clip(int ix, int l, int u);
/* In sampleio.c */
void writeout(FILE *outfd, int size, int *l_out, int *r_out, int chans);
/* In util.c */
uint readbits(uint nbits, FILE *ifile);
char *ReadPString(FILE *ifile);
int lookupMarker(unsigned long *sample, MarkerID loopPoint, Marker *markers, int nmarkers);
ALADPCMloop *readlooppoints(FILE *ifile, short *nloops);