ReactOS  0.4.14-dev-554-g2f8d847
frame.h
Go to the documentation of this file.
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 "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"
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; /* main data pointer, aligned */
42  unsigned char *p; /* read pointer */
43  size_t fill; /* fill from read pointer */
44  size_t size;
45  unsigned char *rdata; /* unaligned base pointer */
46 };
47 
49 {
50  int encoding; /* Final encoding, after post-processing. */
51  int encsize; /* Size of one sample in bytes, plain int should be fine here... */
52  int dec_enc; /* Encoding of decoder synth. */
53  int dec_encsize; /* Size of one decoder sample. */
54  int channels;
55  long rate;
56 };
57 
58 void invalidate_format(struct audioformat *af);
59 
61 {
62  int verbose; /* verbose level */
63  long flags; /* combination of above */
64 #ifndef NO_NTOM
65  long force_rate;
66 #endif
68  int rva; /* (which) rva to do: 0: nothing, 1: radio/mix/track 2: album/audiophile */
69  long halfspeed;
71  long timeout;
72 #define NUM_CHANNELS 2
74 /* long start_frame; */ /* frame offset to begin with */
75 /* long frame_number;*/ /* number of frames to decode */
76 #ifndef NO_ICY
78 #endif
79  double outscale;
81  long index_size; /* Long, because: negative values have a meaning. */
82  long preframes;
83 #ifndef NO_FEEDER
84  long feedpool;
85  long feedbuffer;
86 #endif
87 };
88 
90 {
94 };
95 
96 /* There is a lot to condense here... many ints can be merged as flags; though the main space is still consumed by buffers. */
98 {
99  int fresh; /* to be moved into flags */
102  int hybrid_blc[2];
103  /* the scratch vars for the decoders, sometimes real, sometimes short... sometimes int/long */
104  short *short_buffs[2][2];
105  real *real_buffs[2][2];
106  unsigned char *rawbuffs;
108 #ifdef OPT_I486
109  int i486bo[2];
110 #endif
111  int bo; /* Just have it always here. */
112 #ifdef OPT_DITHER
113  int ditherindex;
114  float *dithernoise;
115 #endif
116  unsigned char* rawdecwin; /* the block with all decwins */
117  int rawdecwins; /* size of rawdecwin memory */
118  real *decwin; /* _the_ decode table */
119 #ifdef OPT_MMXORSSE
120  /* I am not really sure that I need both of them... used in assembler */
121  float *decwin_mmx;
122  float *decwins;
123 #endif
124 #ifndef NO_EQUALIZER
126  real equalizer[2][32];
127 #endif
128  /* for halfspeed mode */
129  unsigned char ssave[34];
131 #ifndef NO_8BIT
132  /* a raw buffer and a pointer into the middle for signed short conversion, only allocated on demand */
133  unsigned char *conv16to8_buf;
134  unsigned char *conv16to8;
135 #endif
136  /* There's some possible memory saving for stuff that is not _really_ dynamic. */
137 
138  /* layer3 */
139  int longLimit[9][23];
140  int shortLimit[9][14];
141  real gainpow2[256+118+4]; /* not really dynamic, just different for mmx */
142 
143  /* layer2 */
144  real muls[27][64]; /* also used by layer 1 */
145 
146 #ifndef NO_NTOM
147  /* decode_ntom */
148  unsigned long ntom_val[2];
149  unsigned long ntom_step;
150 #endif
151  /* special i486 fun */
152 #ifdef OPT_I486
153  int *int_buffs[2][2];
154 #endif
155  /* special altivec... */
156 #ifdef OPT_ALTIVEC
157  real *areal_buffs[4][4];
158 #endif
159  struct synth_s synths;
160  struct
161  {
162 #ifdef OPT_MULTI
163 
164 #ifndef NO_LAYER3
165 #if (defined OPT_3DNOW_VINTAGE || defined OPT_3DNOWEXT_VINTAGE || defined OPT_SSE || defined OPT_X86_64 || defined OPT_AVX || defined OPT_NEON || defined OPT_NEON64)
166  void (*the_dct36)(real *,real *,real *,real *,real *);
167 #endif
168 #endif
169 
170 #endif
171  enum optdec type;
172  enum optcla class;
173  } cpu_opts;
174 
175  int verbose; /* 0: nothing, 1: just print chosen decoder, 2: be verbose */
176 
177  const struct al_table *alloc;
178  /* The runtime-chosen decoding, based on input and output format. */
182  /* Yes, this function is runtime-switched, too. */
183  void (*make_decode_tables)(mpg123_handle *fr); /* That is the volume control. */
184 
185  int stereo; /* I _think_ 1 for mono and 2 for stereo */
186  int jsbound;
187 #define SINGLE_STEREO -1
188 #define SINGLE_LEFT 0
189 #define SINGLE_RIGHT 1
190 #define SINGLE_MIX 3
191  int single;
194  int lsf; /* 0: MPEG 1.0; 1: MPEG 2.0/2.5 -- both used as bool and array index! */
195  /* Many flags in disguise as integers... wasting bytes. */
196  int mpeg25;
199  int lay;
200  long spf; /* cached count of samples per frame */
205  int padding;
207  int mode;
208  int mode_ext;
210  int original;
211  int emphasis;
212  int framesize; /* computed framesize */
213  int freesize; /* free format frame size */
214  enum mpg123_vbr vbr; /* 1 if variable bitrate was detected */
215  off_t num; /* frame offset ... */
216  off_t input_offset; /* byte offset of this frame in input stream */
217  off_t playnum; /* playback offset... includes repetitions, reset at seeks */
218  off_t audio_start; /* The byte offset in the file where audio data begins. */
220  char silent_resync; /* Do not complain for the next n resyncs. */
221  unsigned char* xing_toc; /* The seek TOC from Xing header. */
224 
225  /* bitstream info; bsi */
226  int bitindex;
227  unsigned char *wordpointer;
228  /* temporary storage for getbits stuff */
229  unsigned long ultmp;
230  unsigned char uctmp;
231 
232  /* rva data, used in common.c, set in id3.c */
233 
234  double maxoutburst; /* The maximum amplitude in current sample represenation. */
235  double lastscale;
236  struct
237  {
238  int level[2];
239  float gain[2];
240  float peak[2];
241  } rva;
242 
243  /* input data */
248  int fsizeold;
249  int ssize;
250  unsigned int bitreservoir;
251  unsigned char bsspace[2][MAXFRAMESIZE+512]; /* MAXFRAMESIZE */
252  unsigned char *bsbuf;
253  unsigned char *bsbufold;
254  int bsnum;
255  /* That is the header matching the last read frame body. */
256  unsigned long oldhead;
257  /* That is the header that is supposedly the first of the stream. */
258  unsigned long firsthead;
259  int abr_rate;
260 #ifdef FRAME_INDEX
262 #endif
263 
264  /* output data */
266  struct audioformat af;
268  size_t outblock; /* number of bytes that this frame produces (upper bound) */
269  int to_decode; /* this frame holds data to be decoded */
270  int to_ignore; /* the same, somehow */
271  off_t firstframe; /* start decoding from here */
272  off_t lastframe; /* last frame to decode (for gapless or num_frames limit) */
273  off_t ignoreframe; /* frames to decode but discard before firstframe */
274 #ifdef GAPLESS
275  off_t gapless_frames; /* frame count for the gapless part */
276  off_t firstoff; /* number of samples to ignore from firstframe */
277  off_t lastoff; /* number of samples to use from lastframe */
278  off_t begin_s; /* overall begin offset in samples */
280  off_t end_s; /* overall end offset in samples */
282  off_t fullend_os; /* gapless_frames translated to output samples */
283 #endif
284  unsigned int crc; /* Well, I need a safe 16bit type, actually. But wider doesn't hurt. */
285  struct reader *rd; /* pointer to the reading functions */
286  struct reader_data rdat; /* reader data and state info */
288  int err;
291  long clip;
292  /* the meta crap */
294  unsigned char id3buf[128];
295 #ifndef NO_ID3V2
297 #endif
298 #ifndef NO_ICY
299  struct icy_meta icy;
300 #endif
301  /*
302  More variables needed for decoders, layerX.c.
303  This time it is not about static variables but about the need for alignment which cannot be guaranteed on the stack by certain compilers (Sun Studio).
304  We do not require the compiler to align stuff for our hand-written assembly. We only hope that it's able to align stuff for SSE and similar ops it generates itself.
305  */
306  /*
307  Those layer-specific structs could actually share memory, as they are not in use simultaneously. One might allocate on decoder switch, too.
308  They all reside in one lump of memory (after each other), allocated to layerscratch.
309  */
311 #ifndef NO_LAYER1
312  struct
313  {
314  real (*fraction)[SBLIMIT]; /* ALIGNED(16) real fraction[2][SBLIMIT]; */
315  } layer1;
316 #endif
317 #ifndef NO_LAYER2
318  struct
319  {
320  real (*fraction)[4][SBLIMIT]; /* ALIGNED(16) real fraction[2][4][SBLIMIT] */
321  } layer2;
322 #endif
323 #ifndef NO_LAYER3
324  /* These are significant chunks of memory already... */
325  struct
326  {
327  real (*hybrid_in)[SBLIMIT][SSLIMIT]; /* ALIGNED(16) real hybridIn[2][SBLIMIT][SSLIMIT]; */
328  real (*hybrid_out)[SSLIMIT][SBLIMIT]; /* ALIGNED(16) real hybridOut[2][SSLIMIT][SBLIMIT]; */
329  } layer3;
330 #endif
331  /* A place for storing additional data for the large file wrapper.
332  This is cruft! */
333  void *wrapperdata;
334  /* A callback used to properly destruct the wrapper data. */
335  void (*wrapperclean)(void*);
336 };
337 
338 /* generic init, does not include dynamic buffers */
339 void frame_init(mpg123_handle *fr);
341 /* output buffer and format */
344 
345 int frame_buffers(mpg123_handle *fr); /* various decoder buffers, needed once */
346 int frame_reset(mpg123_handle* fr); /* reset for next track */
348 void frame_exit(mpg123_handle *fr); /* end, free all buffers */
349 
350 /* Index functions... */
351 /* Well... print it... */
353 /* Find a seek position in index. */
354 off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t* get_frame);
355 /* Apply index_size setting. */
357 
358 void do_volume(mpg123_handle *fr, double factor);
359 void do_rva(mpg123_handle *fr);
360 
361 /* samples per frame ...
362 Layer I
363 Layer II
364 Layer III
365 MPEG-1
366 384
367 1152
368 1152
369 MPEG-2 LSF
370 384
371 1152
372 576
373 MPEG 2.5
374 384
375 1152
376 576
377 */
378 
379 #ifdef GAPLESS
380 /* well, I take that one for granted... at least layer3 */
381 #define GAPLESS_DELAY 529
382 void frame_gapless_init(mpg123_handle *fr, off_t framecount, off_t bskip, off_t eskip);
384 void frame_gapless_update(mpg123_handle *mh, off_t total_samples);
385 /*void frame_gapless_position(mpg123_handle* fr);
386 void frame_gapless_bytify(mpg123_handle *fr);
387 void frame_gapless_ignore(mpg123_handle *fr, off_t frames);*/
388 /* void frame_gapless_buffercheck(mpg123_handle *fr); */
389 #endif
390 
391 /* Number of samples the decoding of the current frame should yield. */
393 
394 /* Skip this frame... do some fake action to get away without actually decoding it. */
395 void frame_skip(mpg123_handle *fr);
396 
397 /*
398  Seeking core functions:
399  - convert input sample offset to output sample offset
400  - convert frame offset to output sample offset
401  - get leading frame offset for output sample offset
402  The offsets are "unadjusted"/internal; resampling is being taken care of.
403 */
406 /* This one just computes the expected sample count for _this_ frame. */
412 /* Take a copy of the Xing VBR TOC for fuzzy seeking. */
413 int frame_fill_toc(mpg123_handle *fr, unsigned char* in);
414 #endif
real equalizer[2][32]
Definition: frame.h:126
void invalidate_format(struct audioformat *af)
Definition: format.c:450
float gain[2]
Definition: frame.h:239
struct mpg123_handle_struct::@3322 cpu_opts
long index_size
Definition: frame.h:81
void frame_gapless_init(mpg123_handle *fr, off_t framecount, off_t bskip, off_t eskip)
GLint level
Definition: gl.h:1546
Definition: synths.h:44
Definition: icy.h:16
off_t frame_ins2outs(mpg123_handle *fr, off_t ins)
Definition: frame.c:727
int frame_outbuffer(mpg123_handle *fr)
Definition: frame.c:178
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
unsigned char * data
Definition: frame.h:41
long preframes
Definition: frame.h:82
real * layerscratch
Definition: frame.h:310
off_t frame_outs(mpg123_handle *fr, off_t num)
Definition: frame.c:747
int(* func_synth_stereo)(real *, real *, mpg123_handle *)
Definition: synths.h:12
int longLimit[9][23]
Definition: frame.h:139
long feedbuffer
Definition: frame.h:85
int(* func_synth_mono)(real *, mpg123_handle *)
Definition: synths.h:11
void frame_set_frameseek(mpg123_handle *fr, off_t fe)
Definition: frame.c:879
long freeformat_framesize
Definition: frame.h:223
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint factor
Definition: glfuncs.h:178
size_t size
Definition: frame.h:44
void * wrapperdata
Definition: frame.h:333
unsigned char * bsbufold
Definition: frame.h:253
__kernel_off_t off_t
Definition: linux.h:201
short bits
Definition: frame.h:34
#define SBLIMIT
struct synth_s synths
Definition: frame.h:159
double mean_framesize
Definition: frame.h:246
_Tp _STLP_CALL real(const complex< _Tp > &__z)
Definition: _complex.h:727
GLuint buffer
Definition: glext.h:5915
size_t fill
Definition: frame.h:43
unsigned char * wordpointer
Definition: frame.h:227
int encoding
Definition: frame.h:50
char audio_caps[NUM_CHANNELS][MPG123_RATES+1][MPG123_ENCODINGS]
Definition: frame.h:73
long icy_interval
Definition: frame.h:77
unsigned char * p
Definition: frame.h:42
off_t input_offset
Definition: frame.h:216
long doublespeed
Definition: frame.h:70
unsigned char uctmp
Definition: frame.h:230
const struct al_table * alloc
Definition: frame.h:177
struct mpg123_handle_struct::@3326 layer3
struct reader_data rdat
Definition: frame.h:286
unsigned long ultmp
Definition: frame.h:229
void(* wrapperclean)(void *)
Definition: frame.h:335
long halfspeed
Definition: frame.h:69
unsigned char * xing_toc
Definition: frame.h:221
int frame_buffers(mpg123_handle *fr)
Definition: frame.c:263
int down_sample_sblimit
Definition: frame.h:193
struct mpg123_handle_struct::@3325 layer2
off_t track_frames
Definition: frame.h:244
int(* func_synth)(real *, int, mpg123_handle *, int)
Definition: synths.h:10
off_t frame_expect_outsampels(mpg123_handle *fr)
int channels
Definition: frame.h:54
real(* fraction)[SBLIMIT]
Definition: frame.h:314
long rate
Definition: frame.h:55
real * real_buffs[2][2]
Definition: frame.h:105
int sampling_frequency
Definition: frame.h:204
void(* make_decode_tables)(mpg123_handle *fr)
Definition: frame.h:183
struct icy_meta icy
Definition: frame.h:299
unsigned char * rdata
Definition: frame.h:45
Definition: frame.h:32
unsigned char * conv16to8
Definition: frame.h:134
func_synth_mono synth_mono
Definition: frame.h:181
real muls[27][64]
Definition: frame.h:144
GLuint index
Definition: glext.h:6031
void do_volume(mpg123_handle *fr, double factor)
int(* do_layer)(mpg123_handle *)
Definition: frame.h:201
unsigned int crc
Definition: frame.h:284
off_t gapless_frames
Definition: frame.h:275
enum optdec type
Definition: frame.h:171
int dec_enc
Definition: frame.h:52
struct mpg123_handle_struct::@3324 layer1
float peak[2]
Definition: frame.h:240
off_t frame_offset(mpg123_handle *fr, off_t outs)
Definition: frame.c:789
static FILE * out
Definition: regtests2xml.c:44
long force_rate
Definition: frame.h:65
GLuint GLuint num
Definition: glext.h:9618
short d
Definition: frame.h:35
int dec_encsize
Definition: frame.h:53
#define SSLIMIT
#define MAXFRAMESIZE
Definition: frame.h:30
unsigned char bsspace[2][MAXFRAMESIZE+512]
Definition: frame.h:251
#define NUM_CHANNELS
Definition: frame.h:72
optdec
Definition: optimize.h:94
real hybrid_block[2][2][SBLIMIT *SSLIMIT]
Definition: frame.h:101
int frame_index_setup(mpg123_handle *fr)
func_synth_stereo synth_stereo
Definition: frame.h:180
int mpg123_print_index(mpg123_handle *fr, FILE *out)
#define MPG123_RATES
unsigned long ntom_val[2]
Definition: frame.h:148
off_t frame_tell_seek(mpg123_handle *fr)
void frame_gapless_realinit(mpg123_handle *fr)
short * short_buffs[2][2]
Definition: frame.h:104
long resync_limit
Definition: frame.h:80
int frame_buffers_reset(mpg123_handle *fr)
Definition: frame.c:436
mpg123_id3v2 id3v2
Definition: frame.h:296
int shortLimit[9][14]
Definition: frame.h:140
real(* hybrid_in)[SBLIMIT][SSLIMIT]
Definition: frame.h:327
func_synth synth
Definition: frame.h:179
double maxoutburst
Definition: frame.h:234
real gainpow2[256+118+4]
Definition: frame.h:141
unsigned long firsthead
Definition: frame.h:258
void frame_skip(mpg123_handle *fr)
Definition: frame.c:912
struct audioformat af
Definition: frame.h:266
GLuint in
Definition: glext.h:9616
unsigned char id3buf[128]
Definition: frame.h:294
double lastscale
Definition: frame.h:235
unsigned int bitreservoir
Definition: frame.h:250
void do_rva(mpg123_handle *fr)
Definition: frame.c:980
int encsize
Definition: frame.h:51
int frame_reset(mpg123_handle *fr)
Definition: frame.c:489
unsigned char * rawbuffs
Definition: frame.h:106
Definition: reader.h:83
off_t frame_index_find(mpg123_handle *fr, off_t want_frame, off_t *get_frame)
Definition: frame.c:682
off_t frame_expect_outsamples(mpg123_handle *fr)
Definition: frame.c:769
double outscale
Definition: frame.h:79
int hybrid_blc[2]
Definition: frame.h:102
optcla
Definition: optimize.h:166
real(* hybrid_out)[SSLIMIT][SBLIMIT]
Definition: frame.h:328
mpg123_vbr
Definition: mpg123.h:868
static const WCHAR sp[]
Definition: suminfo.c:288
unsigned long ntom_step
Definition: frame.h:149
struct reader * rd
Definition: frame.h:285
void frame_init_par(mpg123_handle *fr, mpg123_pars *mp)
Definition: frame.c:74
void frame_gapless_update(mpg123_handle *mh, off_t total_samples)
unsigned char * conv16to8_buf
Definition: frame.h:133
#define MPG123_ENCODINGS
GLfloat GLfloat p
Definition: glext.h:8902
off_t track_samples
Definition: frame.h:245
unsigned char ssave[34]
Definition: frame.h:129
#define frame_dither_init
Definition: intsym.h:166
unsigned char * rawdecwin
Definition: frame.h:116
void frame_set_seek(mpg123_handle *fr, off_t sp)
Definition: frame.c:921
struct mpg123_handle_struct::@3323 rva
int frame_fill_toc(mpg123_handle *fr, unsigned char *in)
Definition: frame.c:468
unsigned long oldhead
Definition: frame.h:256
int frame_output_format(mpg123_handle *fr)
Definition: format.c:215
void frame_init(mpg123_handle *fr)
Definition: frame.c:69
enum mpg123_vbr vbr
Definition: frame.h:214
frame_state_flags
Definition: frame.h:89
unsigned char * bsbuf
Definition: frame.h:252
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
void frame_exit(mpg123_handle *fr)
Definition: frame.c:581