Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1905 serge 1
/*
2
	frame: Central data structures and opmitization hooks.
3
 
4
	copyright 2007 by the mpg123 project - free software under the terms of the LGPL 2.1
5
	see COPYING and AUTHORS files in distribution or http://mpg123.org
6
	initially written by Thomas Orgis
7
*/
8
 
9
#ifndef MPG123_FRAME_H
10
#define MPG123_FRAME_H
11
 
12
#include 
13
#include "config.h"
14
#include "mpg123.h"
15
#include "optimize.h"
16
#include "id3.h"
17
#include "icy.h"
18
#include "reader.h"
19
#ifdef FRAME_INDEX
20
#include "index.h"
21
#endif
22
#include "synths.h"
23
 
24
#ifdef OPT_DITHER
25
#include "dither.h"
26
int frame_dither_init(mpg123_handle *fr);
27
#endif
28
 
29
/* max = 1728 */
30
#define MAXFRAMESIZE 3456
31
 
32
struct al_table
33
{
34
  short bits;
35
  short d;
36
};
37
 
38
/* the output buffer, used to be pcm_sample, pcm_point and audiobufsize */
39
struct outbuffer
40
{
41
	unsigned char *data;
42
	unsigned char *p; /* read pointer  */
43
	size_t fill; /* fill from read pointer */
44
	size_t size; /* that's actually more like a safe size, after we have more than that, flush it */
45
};
46
 
47
struct audioformat
48
{
49
	int encoding;
50
	int encsize; /* Size of one sample in bytes, plain int should be fine here... */
51
	int channels;
52
	long rate;
53
};
54
 
55
void invalidate_format(struct audioformat *af);
56
 
57
struct mpg123_pars_struct
58
{
59
	int verbose;    /* verbose level */
60
	long flags; /* combination of above */
61
#ifndef NO_NTOM
62
	long force_rate;
63
#endif
64
	int down_sample;
65
	int rva; /* (which) rva to do: 0: nothing, 1: radio/mix/track 2: album/audiophile */
66
	long halfspeed;
67
	long doublespeed;
68
#ifndef WIN32
69
	long timeout;
70
#endif
71
#define NUM_CHANNELS 2
72
	char audio_caps[NUM_CHANNELS][MPG123_RATES+1][MPG123_ENCODINGS];
73
/*	long start_frame; */ /* frame offset to begin with */
74
/*	long frame_number;*/ /* number of frames to decode */
75
#ifndef NO_ICY
76
	long icy_interval;
77
#endif
78
	double outscale;
79
	long resync_limit;
80
	long index_size; /* Long, because: negative values have a meaning. */
81
	long preframes;
82
};
83
 
84
 
85
 
86
/* There is a lot to condense here... many ints can be merged as flags; though the main space is still consumed by buffers. */
87
struct mpg123_handle_struct
88
{
89
	int fresh; /* to be moved into flags */
90
	int new_format;
91
	real hybrid_block[2][2][SBLIMIT*SSLIMIT];
92
	int hybrid_blc[2];
93
	/* the scratch vars for the decoders, sometimes real, sometimes short... sometimes int/long */
94
	short *short_buffs[2][2];
95
	real *real_buffs[2][2];
96
	unsigned char *rawbuffs;
97
	int rawbuffss;
98
#ifdef OPT_I486
99
	int i486bo[2];
100
#endif
101
	int bo; /* Just have it always here. */
102
#ifdef OPT_DITHER
103
	int ditherindex;
104
	float *dithernoise;
105
#endif
106
	unsigned char* rawdecwin; /* the block with all decwins */
107
	int rawdecwins; /* size of rawdecwin memory */
108
	real *decwin; /* _the_ decode table */
109
#ifdef OPT_MMXORSSE
110
	/* I am not really sure that I need both of them... used in assembler */
111
	float *decwin_mmx;
112
	float *decwins;
113
#endif
114
	int have_eq_settings;
115
	real equalizer[2][32];
116
 
117
	/* for halfspeed mode */
118
	unsigned char ssave[34];
119
	int halfphase;
120
#ifndef NO_8BIT
121
	/* a raw buffer and a pointer into the middle for signed short conversion, only allocated on demand */
122
	unsigned char *conv16to8_buf;
123
	unsigned char *conv16to8;
124
#endif
125
	/* There's some possible memory saving for stuff that is not _really_ dynamic. */
126
 
127
	/* layer3 */
128
	int longLimit[9][23];
129
	int shortLimit[9][14];
130
	real gainpow2[256+118+4]; /* not really dynamic, just different for mmx */
131
 
132
	/* layer2 */
133
	real muls[27][64];	/* also used by layer 1 */
134
 
135
#ifndef NO_NTOM
136
	/* decode_ntom */
137
	unsigned long ntom_val[2];
138
	unsigned long ntom_step;
139
#endif
140
	/* special i486 fun */
141
#ifdef OPT_I486
142
	int *int_buffs[2][2];
143
#endif
144
	/* special altivec... */
145
#ifdef OPT_ALTIVEC
146
	real *areal_buffs[4][4];
147
#endif
148
	struct synth_s synths;
149
	struct
150
	{
151
#ifdef OPT_MULTI
152
 
153
#ifndef NO_LAYER3
154
#if (defined OPT_3DNOW || defined OPT_3DNOWEXT)
155
		void (*dct36)(real *,real *,real *,real *,real *);
156
#endif
157
#endif
158
 
159
#endif
160
		enum optdec type;
161
		enum optcla class;
162
	} cpu_opts;
163
 
164
	int verbose;    /* 0: nothing, 1: just print chosen decoder, 2: be verbose */
165
 
166
	const struct al_table *alloc;
167
	/* The runtime-chosen decoding, based on input and output format. */
168
	func_synth synth;
169
	func_synth_stereo synth_stereo;
170
	func_synth_mono synth_mono;
171
	/* Yes, this function is runtime-switched, too. */
172
	void (*make_decode_tables)(mpg123_handle *fr); /* That is the volume control. */
173
 
174
	int stereo; /* I _think_ 1 for mono and 2 for stereo */
175
	int jsbound;
176
#define SINGLE_STEREO -1
177
#define SINGLE_LEFT    0
178
#define SINGLE_RIGHT   1
179
#define SINGLE_MIX     3
180
	int single;
181
	int II_sblimit;
182
	int down_sample_sblimit;
183
	int lsf; /* 0: MPEG 1.0; 1: MPEG 2.0/2.5 -- both used as bool and array index! */
184
	/* Many flags in disguise as integers... wasting bytes. */
185
	int mpeg25;
186
	int down_sample;
187
	int header_change;
188
	int lay;
189
	int (*do_layer)(mpg123_handle *);
190
	int error_protection;
191
	int bitrate_index;
192
	int sampling_frequency;
193
	int padding;
194
	int extension;
195
	int mode;
196
	int mode_ext;
197
	int copyright;
198
	int original;
199
	int emphasis;
200
	int framesize; /* computed framesize */
201
	int freesize;  /* free format frame size */
202
	enum mpg123_vbr vbr; /* 1 if variable bitrate was detected */
203
	off_t num; /* frame offset ... */
204
	off_t playnum; /* playback offset... includes repetitions, reset at seeks */
205
	off_t audio_start; /* The byte offset in the file where audio data begins. */
206
	char accurate; /* Flag to see if we trust the frame number. */
207
	char silent_resync; /* Do not complain for the next n resyncs. */
208
	unsigned char* xing_toc; /* The seek TOC from Xing header. */
209
	int freeformat;
210
	long freeformat_framesize;
211
 
212
	/* bitstream info; bsi */
213
	int bitindex;
214
	unsigned char *wordpointer;
215
	/* temporary storage for getbits stuff */
216
	unsigned long ultmp;
217
	unsigned char uctmp;
218
 
219
	/* rva data, used in common.c, set in id3.c */
220
 
221
	double maxoutburst; /* The maximum amplitude in current sample represenation. */
222
	double lastscale;
223
	struct
224
	{
225
		int level[2];
226
		float gain[2];
227
		float peak[2];
228
	} rva;
229
 
230
	/* input data */
231
	off_t track_frames;
232
	off_t track_samples;
233
	double mean_framesize;
234
	off_t mean_frames;
235
	int fsizeold;
236
	int ssize;
237
	unsigned int bitreservoir;
238
	unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */
239
	unsigned char *bsbuf;
240
	unsigned char *bsbufold;
241
	int bsnum;
242
	unsigned long oldhead;
243
	unsigned long firsthead;
244
	int abr_rate;
245
#ifdef FRAME_INDEX
246
	struct frame_index index;
247
#endif
248
 
249
	/* output data */
250
	struct outbuffer buffer;
251
	struct audioformat af;
252
	int own_buffer;
253
	size_t outblock; /* number of bytes that this frame produces (upper bound) */
254
	int to_decode;   /* this frame holds data to be decoded */
255
	int to_ignore;   /* the same, somehow */
256
	off_t firstframe;  /* start decoding from here */
257
	off_t lastframe;   /* last frame to decode (for gapless or num_frames limit) */
258
	off_t ignoreframe; /* frames to decode but discard before firstframe */
259
#ifdef GAPLESS
260
	off_t firstoff; /* number of samples to ignore from firstframe */
261
	off_t lastoff;  /* number of samples to use from lastframe */
262
	off_t begin_s;  /* overall begin offset in samples */
263
	off_t begin_os;
264
	off_t end_s;    /* overall end offset in samples */
265
	off_t end_os;
266
#endif
267
	unsigned int crc; /* Well, I need a safe 16bit type, actually. But wider doesn't hurt. */
268
	struct reader *rd; /* pointer to the reading functions */
269
	struct reader_data rdat; /* reader data and state info */
270
	struct mpg123_pars_struct p;
271
	int err;
272
	int decoder_change;
273
	int delayed_change;
274
	long clip;
275
	/* the meta crap */
276
	int metaflags;
277
	unsigned char id3buf[128];
278
#ifndef NO_ID3V2
279
	mpg123_id3v2 id3v2;
280
#endif
281
#ifndef NO_ICY
282
	struct icy_meta icy;
283
#endif
284
};
285
 
286
/* generic init, does not include dynamic buffers */
287
void frame_init(mpg123_handle *fr);
288
void frame_init_par(mpg123_handle *fr, mpg123_pars *mp);
289
/* output buffer and format */
290
int  frame_outbuffer(mpg123_handle *fr);
291
int  frame_output_format(mpg123_handle *fr);
292
 
293
int frame_buffers(mpg123_handle *fr); /* various decoder buffers, needed once */
294
int frame_reset(mpg123_handle* fr);   /* reset for next track */
295
int frame_buffers_reset(mpg123_handle *fr);
296
void frame_exit(mpg123_handle *fr);   /* end, free all buffers */
297
 
298
/* Index functions... */
299
/* Well... print it... */
300
int mpg123_print_index(mpg123_handle *fr, FILE* out);
301
/* Find a seek position in index. */
302
off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame);
303
/* Apply index_size setting. */
304
int frame_index_setup(mpg123_handle *fr);
305
 
306
void do_volume(mpg123_handle *fr, double factor);
307
void do_rva(mpg123_handle *fr);
308
 
309
/* samples per frame ...
310
Layer I
311
Layer II
312
Layer III
313
MPEG-1
314
384
315
1152
316
1152
317
MPEG-2 LSF
318
384
319
1152
320
576
321
MPEG 2.5
322
384
323
1152
324
576
325
*/
326
#define spf(fr) ((fr)->lay == 1 ? 384 : ((fr)->lay==2 ? 1152 : ((fr)->lsf || (fr)->mpeg25 ? 576 : 1152)))
327
 
328
#ifdef GAPLESS
329
/* well, I take that one for granted... at least layer3 */
330
#define GAPLESS_DELAY 529
331
/* still fine-tuning the "real music" window... see read_frame */
332
void frame_gapless_init(mpg123_handle *fr, off_t b, off_t e);
333
void frame_gapless_realinit(mpg123_handle *fr);
334
void frame_gapless_update(mpg123_handle *mh, off_t total_samples);
335
/*void frame_gapless_position(mpg123_handle* fr);
336
void frame_gapless_bytify(mpg123_handle *fr);
337
void frame_gapless_ignore(mpg123_handle *fr, off_t frames);*/
338
/* void frame_gapless_buffercheck(mpg123_handle *fr); */
339
#endif
340
 
341
/* Skip this frame... do some fake action to get away without actually decoding it. */
342
void frame_skip(mpg123_handle *fr);
343
 
344
/*
345
	Seeking core functions:
346
	- convert input sample offset to output sample offset
347
	- convert frame offset to output sample offset
348
	- get leading frame offset for output sample offset
349
	The offsets are "unadjusted"/internal; resampling is being taken care of.
350
*/
351
off_t frame_ins2outs(mpg123_handle *fr, off_t ins);
352
off_t frame_outs(mpg123_handle *fr, off_t num);
353
off_t frame_offset(mpg123_handle *fr, off_t outs);
354
void frame_set_frameseek(mpg123_handle *fr, off_t fe);
355
void frame_set_seek(mpg123_handle *fr, off_t sp);
356
off_t frame_tell_seek(mpg123_handle *fr);
357
/* Take a copy of the Xing VBR TOC for fuzzy seeking. */
358
int frame_fill_toc(mpg123_handle *fr, unsigned char* in);
359
 
360
 
361
/* adjust volume to current outscale and rva values if wanted */
362
void do_rva(mpg123_handle *fr);
363
#endif