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