afinternal.h
7.3 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
Audio File Library
Copyright (C) 1998-2000, Michael Pruett <michael@68k.org>
Copyright (C) 2000, Silicon Graphics, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307 USA.
*/
/*
afinternal.h
This file defines the internal structures for the Audio File Library.
*/
#ifndef AFINTERNAL_H
#define AFINTERNAL_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/types.h>
#include <stdio.h>
#include "audiofile.h"
#include "af_vfs.h"
#include "error.h"
typedef int bool;
#define AF_TRUE (1)
#define AF_FALSE (0)
typedef int status;
#define AF_SUCCEED (0)
#define AF_FAIL (-1)
struct _codec
{
AFframecount (*readFrames) (const AFfilehandle file, int track,
void *samples, const int count);
AFframecount (*writeFrames) (const AFfilehandle file, int track,
void *samples, const int count);
};
typedef struct _Compression
{
int type; /* symbolic constant */
char *name; /* human-readable name */
struct _codec *codec;
} _Compression;
typedef union AFPVu
{
long l;
double d;
void *v;
} AFPVu;
typedef struct _SuppMiscInfo
{
int type; /* AF_MISC_... */
int count; /* 0 = unlimited */
} _SuppMiscInfo;
typedef struct _InstParamInfo
{
int id;
int type;
char *name;
AFPVu defaultValue;
} _InstParamInfo;
typedef struct _MarkerSetup
{
int id;
char *name, *comment;
} _MarkerSetup;
typedef struct _Marker
{
short id;
unsigned long position;
char *name, *comment;
} _Marker;
typedef struct _Loop
{
int id;
int mode; /* AF_LOOP_MODE_... */
int count; /* how many times the loop is played */
int beginMarker, endMarker;
int trackid;
} _Loop;
typedef struct _PCMInfo
{
double slope, intercept, minClip, maxClip;
} _PCMInfo;
typedef struct _AudioFormat
{
double sampleRate; /* sampling rate in Hz */
int sampleFormat; /* AF_SAMPFMT_... */
int sampleWidth; /* sample width in bits */
int byteOrder; /* AF_BYTEORDER_... */
_PCMInfo pcm; /* parameters of PCM data */
int channelCount; /* number of channels */
int compressionType; /* AF_COMPRESSION_... */
void *compressionParams; /* NULL if no compression */
} _AudioFormat;
/* modules */
struct _AFmoduleinst;
struct _AFchunk;
typedef void (*_AFfnpmod) (struct _AFmoduleinst *i);
typedef void (*_AFfnpsimplemod) (struct _AFchunk *inc,
struct _AFchunk *outc, void *modspec);
typedef struct _AFmodule
{
char *name;
_AFfnpmod describe;
_AFfnpmod max_pull;
_AFfnpmod max_push;
_AFfnpmod run_pull;
_AFfnpmod reset1;
_AFfnpmod reset2;
_AFfnpmod run_push;
_AFfnpmod sync1;
_AFfnpmod sync2;
_AFfnpsimplemod run;
_AFfnpmod free;
} _AFmodule;
typedef struct _AFchunk
{
void *buf; /* chunk data */
AFframecount nframes; /* # of frames in chunk */
_AudioFormat f; /* format of data in chunk */
} _AFchunk;
typedef struct _AFmoduleinst
{
_AFchunk *inc, *outc;
void *modspec;
union
{
struct { struct _AFmoduleinst *source; } pull;
struct { struct _AFmoduleinst *sink; } push;
} u;
_AFmodule *mod;
bool free_on_close; /* AF_TRUE=don't free module until close */
bool valid; /* internal use only */
#ifdef AF_DEBUG /* these are set in _AFsetupmodules */
int margin; /* margin for printing of CHNK messages */
bool dump; /* whether to dump chunks */
#endif
} _AFmoduleinst;
/* information private to module routines */
typedef struct _AFmodulestate
{
bool modulesdirty;
int nmodules;
/* See comment at very end of arrangemodules(). */
bool mustuseatomicnvframes;
/* previous rates before user changed them */
double old_f_rate, old_v_rate;
_AFchunk *chunk;
_AFmoduleinst *module;
/* array of pointers to buffers, one for each module */
void **buffer;
/* These modules have extended lifetimes. */
/* file read / write */
_AFmoduleinst filemodinst;
/* file module's rebuffer */
_AFmoduleinst filemod_rebufferinst;
/* rate conversion */
_AFmoduleinst rateconvertinst;
/* old rates */
double rateconvert_inrate, rateconvert_outrate;
/* rate conversion's rebuffer */
_AFmoduleinst rateconvert_rebufferinst;
} _AFmodulestate;
typedef struct _Track
{
int id; /* usually AF_DEFAULT_TRACKID */
_AudioFormat f, v; /* file and virtual audio formats */
double *channelMatrix;
int markerCount;
_Marker *markers;
bool hasAESData; /* Is AES nonaudio data present? */
unsigned char aesData[24]; /* AES nonaudio data */
AFframecount totalfframes; /* frameCount */
AFframecount nextfframe; /* currentFrame */
AFframecount frames2ignore;
AFfileoffset fpos_first_frame; /* dataStart */
AFfileoffset fpos_next_frame;
AFfileoffset fpos_after_data;
AFframecount totalvframes;
AFframecount nextvframe;
AFfileoffset data_size; /* trackBytes */
_AFmodulestate ms;
double taper, dynamic_range;
bool ratecvt_filter_params_set;
bool filemodhappy;
} _Track;
typedef struct _TrackSetup
{
int id;
_AudioFormat f;
bool rateSet, sampleFormatSet, sampleWidthSet, byteOrderSet,
channelCountSet, compressionSet, aesDataSet, markersSet,
dataOffsetSet, frameCountSet;
int markerCount;
_MarkerSetup *markers;
off_t dataOffset;
off_t frameCount;
} _TrackSetup;
typedef struct _LoopSetup
{
int id;
} _LoopSetup;
typedef struct _InstrumentSetup
{
int id;
int loopCount;
_LoopSetup *loops;
bool loopSet;
} _InstrumentSetup;
typedef struct _Instrument
{
int id;
int loopCount;
_Loop *loops;
AFPVu *values;
} _Instrument;
typedef struct _Miscellaneous
{
int id;
int type;
int size;
void *buffer;
AFfileoffset position; /* offset within the miscellaneous chunk */
} _Miscellaneous;
typedef struct _MiscellaneousSetup
{
int id;
int type;
int size;
} _MiscellaneousSetup;
typedef struct _AFfilesetup
{
int valid;
int fileFormat;
bool trackSet, instrumentSet, miscellaneousSet;
int trackCount;
_TrackSetup *tracks;
int instrumentCount;
_InstrumentSetup *instruments;
int miscellaneousCount;
_MiscellaneousSetup *miscellaneous;
} _AFfilesetup;
typedef struct _AFfilehandle
{
int valid; /* _AF_VALID_FILEHANDLE */
int access; /* _AF_READ_ACCESS or _AF_WRITE_ACCESS */
bool seekok;
AFvirtualfile *fh;
int fileFormat;
int trackCount;
_Track *tracks;
int instrumentCount;
_Instrument *instruments;
int miscellaneousCount;
_Miscellaneous *miscellaneous;
void *formatSpecific; /* format-specific data */
} _AFfilehandle;
enum
{
AIFC_VERSION_1 = 0xa2805140
};
enum
{
_AF_VALID_FILEHANDLE = 38212,
_AF_VALID_FILESETUP = 38213
};
enum
{
_AF_READ_ACCESS = 1,
_AF_WRITE_ACCESS = 2
};
/* The following are tokens for compression parameters in PV lists. */
enum
{
_AF_SAMPLES_PER_BLOCK = 700, /* type: long */
_AF_BLOCK_SIZE = 701, /* type: long */
_AF_MS_ADPCM_NUM_COEFFICIENTS = 800, /* type: long */
_AF_MS_ADPCM_COEFFICIENTS = 801 /* type: array of int16_t[2] */
};
/* NeXT/Sun sampling rate */
#define _AF_SRATE_CODEC (8012.8210513)
#endif