annotate mpegaudiodec.c @ 1057:bb5de8a59da8 libavcodec

* static,const,compiler warning cleanup
author kabi
date Mon, 10 Feb 2003 09:35:32 +0000
parents 1f9afd8b9131
children b32afefe7d33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * MPEG Audio decoder
429
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
3 * Copyright (c) 2001, 2002 Fabrice Bellard.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
429
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
5 * This library is free software; you can redistribute it and/or
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
7 * License as published by the Free Software Foundation; either
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
8 * version 2 of the License, or (at your option) any later version.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 *
429
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
10 * This library is distributed in the hope that it will be useful,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
13 * Lesser General Public License for more details.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 *
429
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
16 * License along with this library; if not, write to the Free Software
718a22dc121f license/copyright change
glantau
parents: 407
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 */
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
19 //#define DEBUG
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 #include "avcodec.h"
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
21 #include "mpegaudio.h"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
22
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 /*
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
24 * TODO:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
25 * - in low precision mode, use more 16 bit multiplies in synth filter
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
26 * - test lsf / mpeg25 extensively.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
28
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
29 /* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
30 audio decoder */
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
31 #ifdef CONFIG_MPEGAUDIO_HP
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
32 #define USE_HIGHPRECISION
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
33 #endif
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
34
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
35 #ifdef USE_HIGHPRECISION
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
36 #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
37 #define WFRAC_BITS 16 /* fractional bits for window */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
38 #else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
39 #define FRAC_BITS 15 /* fractional bits for sb_samples and dct */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
40 #define WFRAC_BITS 14 /* fractional bits for window */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
41 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
42
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
43 #define FRAC_ONE (1 << FRAC_BITS)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
44
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
45 #define MULL(a,b) (((INT64)(a) * (INT64)(b)) >> FRAC_BITS)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
46 #define MUL64(a,b) ((INT64)(a) * (INT64)(b))
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
47 #define FIX(a) ((int)((a) * FRAC_ONE))
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
48 /* WARNING: only correct for posititive numbers */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
49 #define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
50 #define FRAC_RND(a) (((a) + (FRAC_ONE/2)) >> FRAC_BITS)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
51
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
52 #if FRAC_BITS <= 15
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
53 typedef INT16 MPA_INT;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
54 #else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
55 typedef INT32 MPA_INT;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
56 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
57
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
58 /****************/
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
59
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 #define HEADER_SIZE 4
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 #define BACKSTEP_SIZE 512
986e461dc072 Initial revision
glantau
parents:
diff changeset
62
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 typedef struct MPADecodeContext {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
64 UINT8 inbuf1[2][MPA_MAX_CODED_FRAME_SIZE + BACKSTEP_SIZE]; /* input buffer */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 int inbuf_index;
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 UINT8 *inbuf_ptr, *inbuf;
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 int frame_size;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
68 int free_format_frame_size; /* frame size in case of free format
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
69 (zero if currently unknown) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
70 /* next header (used in free format parsing) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
71 UINT32 free_format_next_header;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 int error_protection;
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 int layer;
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 int sample_rate;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
75 int sample_rate_index; /* between 0 and 8 */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 int bit_rate;
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 int old_frame_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
78 GetBitContext gb;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
79 int nb_channels;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
80 int mode;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
81 int mode_ext;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
82 int lsf;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
83 MPA_INT synth_buf[MPA_MAX_CHANNELS][512 * 2];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
84 int synth_buf_offset[MPA_MAX_CHANNELS];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
85 INT32 sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
86 INT32 mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
87 #ifdef DEBUG
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
88 int frame_count;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
89 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 } MPADecodeContext;
986e461dc072 Initial revision
glantau
parents:
diff changeset
91
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
92 /* layer 3 "granule" */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
93 typedef struct GranuleDef {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
94 UINT8 scfsi;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
95 int part2_3_length;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
96 int big_values;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
97 int global_gain;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
98 int scalefac_compress;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
99 UINT8 block_type;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
100 UINT8 switch_point;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
101 int table_select[3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
102 int subblock_gain[3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
103 UINT8 scalefac_scale;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
104 UINT8 count1table_select;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
105 int region_size[3]; /* number of huffman codes in each region */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
106 int preflag;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
107 int short_start, long_end; /* long/short band indexes */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
108 UINT8 scale_factors[40];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
109 INT32 sb_hybrid[SBLIMIT * 18]; /* 576 samples */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
110 } GranuleDef;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
111
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
112 #define MODE_EXT_MS_STEREO 2
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
113 #define MODE_EXT_I_STEREO 1
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
114
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
115 /* layer 3 huffman tables */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
116 typedef struct HuffTable {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
117 int xsize;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
118 const UINT8 *bits;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
119 const UINT16 *codes;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
120 } HuffTable;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
121
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
122 #include "mpegaudiodectab.h"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
123
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
124 /* vlc structure for decoding layer 3 huffman tables */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
125 static VLC huff_vlc[16];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
126 static UINT8 *huff_code_table[16];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
127 static VLC huff_quad_vlc[2];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
128 /* computed from band_size_long */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
129 static UINT16 band_index_long[9][23];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
130 /* XXX: free when all decoders are closed */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
131 #define TABLE_4_3_SIZE (8191 + 16)
404
29dc52c127c6 fixed one overflow problem
glantau
parents: 392
diff changeset
132 static INT8 *table_4_3_exp;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
133 #if FRAC_BITS <= 15
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
134 static UINT16 *table_4_3_value;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
135 #else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
136 static UINT32 *table_4_3_value;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
137 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
138 /* intensity stereo coef table */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
139 static INT32 is_table[2][16];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
140 static INT32 is_table_lsf[2][2][16];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
141 static INT32 csa_table[8][2];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
142 static INT32 mdct_win[8][36];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
143
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
144 /* lower 2 bits: modulo 3, higher bits: shift */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
145 static UINT16 scale_factor_modshift[64];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
146 /* [i][j]: 2^(-j/3) * FRAC_ONE * 2^(i+2) / (2^(i+2) - 1) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
147 static INT32 scale_factor_mult[15][3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
148 /* mult table for layer 2 group quantization */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
149
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
150 #define SCALE_GEN(v) \
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
151 { FIXR(1.0 * (v)), FIXR(0.7937005259 * (v)), FIXR(0.6299605249 * (v)) }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
152
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
153 static INT32 scale_factor_mult2[3][3] = {
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
154 SCALE_GEN(4.0 / 3.0), /* 3 steps */
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
155 SCALE_GEN(4.0 / 5.0), /* 5 steps */
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
156 SCALE_GEN(4.0 / 9.0), /* 9 steps */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
157 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
158
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
159 /* 2^(n/4) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
160 static UINT32 scale_factor_mult3[4] = {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
161 FIXR(1.0),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
162 FIXR(1.18920711500272106671),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
163 FIXR(1.41421356237309504880),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
164 FIXR(1.68179283050742908605),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
165 };
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
166
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
167 static MPA_INT window[512];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
168
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
169 /* layer 1 unscaling */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
170 /* n = number of bits of the mantissa minus 1 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
171 static inline int l1_unscale(int n, int mant, int scale_factor)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
172 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
173 int shift, mod;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
174 INT64 val;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
175
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
176 shift = scale_factor_modshift[scale_factor];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
177 mod = shift & 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
178 shift >>= 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
179 val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
180 shift += n;
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
181 /* NOTE: at this point, 1 <= shift >= 21 + 15 */
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
182 return (int)((val + (1LL << (shift - 1))) >> shift);
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
183 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
184
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
185 static inline int l2_unscale_group(int steps, int mant, int scale_factor)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
186 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
187 int shift, mod, val;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
188
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
189 shift = scale_factor_modshift[scale_factor];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
190 mod = shift & 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
191 shift >>= 2;
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
192
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
193 val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod];
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
194 /* NOTE: at this point, 0 <= shift <= 21 */
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
195 if (shift > 0)
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
196 val = (val + (1 << (shift - 1))) >> shift;
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
197 return val;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
198 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
199
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
200 /* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
201 static inline int l3_unscale(int value, int exponent)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
202 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
203 #if FRAC_BITS <= 15
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
204 unsigned int m;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
205 #else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
206 UINT64 m;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
207 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
208 int e;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
209
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
210 e = table_4_3_exp[value];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
211 e += (exponent >> 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
212 e = FRAC_BITS - e;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
213 #if FRAC_BITS <= 15
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
214 if (e > 31)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
215 e = 31;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
216 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
217 m = table_4_3_value[value];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
218 #if FRAC_BITS <= 15
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
219 m = (m * scale_factor_mult3[exponent & 3]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
220 m = (m + (1 << (e-1))) >> e;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
221 return m;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
222 #else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
223 m = MUL64(m, scale_factor_mult3[exponent & 3]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
224 m = (m + (UINT64_C(1) << (e-1))) >> e;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
225 return m;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
226 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
227 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
228
392
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
229 /* all integer n^(4/3) computation code */
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
230 #define DEV_ORDER 13
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
231
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
232 #define POW_FRAC_BITS 24
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
233 #define POW_FRAC_ONE (1 << POW_FRAC_BITS)
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
234 #define POW_FIX(a) ((int)((a) * POW_FRAC_ONE))
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
235 #define POW_MULL(a,b) (((INT64)(a) * (INT64)(b)) >> POW_FRAC_BITS)
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
236
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
237 static int dev_4_3_coefs[DEV_ORDER];
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
238
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
239 static int pow_mult3[3] = {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
240 POW_FIX(1.0),
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
241 POW_FIX(1.25992104989487316476),
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
242 POW_FIX(1.58740105196819947474),
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
243 };
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
244
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
245 static void int_pow_init(void)
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
246 {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
247 int i, a;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
248
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
249 a = POW_FIX(1.0);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
250 for(i=0;i<DEV_ORDER;i++) {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
251 a = POW_MULL(a, POW_FIX(4.0 / 3.0) - i * POW_FIX(1.0)) / (i + 1);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
252 dev_4_3_coefs[i] = a;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
253 }
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
254 }
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
255
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
256 /* return the mantissa and the binary exponent */
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
257 static int int_pow(int i, int *exp_ptr)
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
258 {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
259 int e, er, eq, j;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
260 int a, a1;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
261
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
262 /* renormalize */
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
263 a = i;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
264 e = POW_FRAC_BITS;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
265 while (a < (1 << (POW_FRAC_BITS - 1))) {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
266 a = a << 1;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
267 e--;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
268 }
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
269 a -= (1 << POW_FRAC_BITS);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
270 a1 = 0;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
271 for(j = DEV_ORDER - 1; j >= 0; j--)
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
272 a1 = POW_MULL(a, dev_4_3_coefs[j] + a1);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
273 a = (1 << POW_FRAC_BITS) + a1;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
274 /* exponent compute (exact) */
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
275 e = e * 4;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
276 er = e % 3;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
277 eq = e / 3;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
278 a = POW_MULL(a, pow_mult3[er]);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
279 while (a >= 2 * POW_FRAC_ONE) {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
280 a = a >> 1;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
281 eq++;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
282 }
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
283 /* convert to float */
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
284 while (a < POW_FRAC_ONE) {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
285 a = a << 1;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
286 eq--;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
287 }
407
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
288 /* now POW_FRAC_ONE <= a < 2 * POW_FRAC_ONE */
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
289 #if POW_FRAC_BITS > FRAC_BITS
407
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
290 a = (a + (1 << (POW_FRAC_BITS - FRAC_BITS - 1))) >> (POW_FRAC_BITS - FRAC_BITS);
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
291 /* correct overflow */
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
292 if (a >= 2 * (1 << FRAC_BITS)) {
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
293 a = a >> 1;
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
294 eq++;
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
295 }
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
296 #endif
392
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
297 *exp_ptr = eq;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
298 return a;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
299 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
300
986e461dc072 Initial revision
glantau
parents:
diff changeset
301 static int decode_init(AVCodecContext * avctx)
986e461dc072 Initial revision
glantau
parents:
diff changeset
302 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
303 MPADecodeContext *s = avctx->priv_data;
836
932eb34d17c1 vc++ sucks, found by ("csharprules" <csharprules at hotmail dot com>)
michaelni
parents: 602
diff changeset
304 static int init=0;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
305 int i, j, k;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
306
986e461dc072 Initial revision
glantau
parents:
diff changeset
307 if(!init) {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
308 /* scale factors table for layer 1/2 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
309 for(i=0;i<64;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
310 int shift, mod;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
311 /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
312 shift = (i / 3);
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
313 mod = i % 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
314 scale_factor_modshift[i] = mod | (shift << 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
315 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
316
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
317 /* scale factor multiply for layer 1 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
318 for(i=0;i<15;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
319 int n, norm;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
320 n = i + 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
321 norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1);
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
322 scale_factor_mult[i][0] = MULL(FIXR(1.0 * 2.0), norm);
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
323 scale_factor_mult[i][1] = MULL(FIXR(0.7937005259 * 2.0), norm);
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
324 scale_factor_mult[i][2] = MULL(FIXR(0.6299605249 * 2.0), norm);
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
325 dprintf("%d: norm=%x s=%x %x %x\n",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
326 i, norm,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
327 scale_factor_mult[i][0],
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
328 scale_factor_mult[i][1],
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
329 scale_factor_mult[i][2]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
330 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
331
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
332 /* window */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
333 /* max = 18760, max sum over all 16 coefs : 44736 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
334 for(i=0;i<257;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
335 int v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
336 v = mpa_enwindow[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
337 #if WFRAC_BITS < 16
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
338 v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
339 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
340 window[i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
341 if ((i & 63) != 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
342 v = -v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
343 if (i != 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
344 window[512 - i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
345 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
346
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
347 /* huffman decode tables */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
348 huff_code_table[0] = NULL;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
349 for(i=1;i<16;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
350 const HuffTable *h = &mpa_huff_tables[i];
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 1025
diff changeset
351 int xsize, x, y;
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 1025
diff changeset
352 unsigned int n;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
353 UINT8 *code_table;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
354
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
355 xsize = h->xsize;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
356 n = xsize * xsize;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
357 /* XXX: fail test */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
358 init_vlc(&huff_vlc[i], 8, n,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
359 h->bits, 1, 1, h->codes, 2, 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
360
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
361 code_table = av_mallocz(n);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
362 j = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
363 for(x=0;x<xsize;x++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
364 for(y=0;y<xsize;y++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
365 code_table[j++] = (x << 4) | y;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
366 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
367 huff_code_table[i] = code_table;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
368 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
369 for(i=0;i<2;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
370 init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
371 mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
372 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
373
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
374 for(i=0;i<9;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
375 k = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
376 for(j=0;j<22;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
377 band_index_long[i][j] = k;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
378 k += band_size_long[i][j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
379 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
380 band_index_long[i][22] = k;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
381 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
382
902
6acc8394960d * two functions to handle allocation of static data more simple
kabi
parents: 836
diff changeset
383 /* compute n ^ (4/3) and store it in mantissa/exp format */
6acc8394960d * two functions to handle allocation of static data more simple
kabi
parents: 836
diff changeset
384 if (!av_mallocz_static(&table_4_3_exp,
6acc8394960d * two functions to handle allocation of static data more simple
kabi
parents: 836
diff changeset
385 TABLE_4_3_SIZE * sizeof(table_4_3_exp[0])))
6acc8394960d * two functions to handle allocation of static data more simple
kabi
parents: 836
diff changeset
386 return -1;
6acc8394960d * two functions to handle allocation of static data more simple
kabi
parents: 836
diff changeset
387 if (!av_mallocz_static(&table_4_3_value,
6acc8394960d * two functions to handle allocation of static data more simple
kabi
parents: 836
diff changeset
388 TABLE_4_3_SIZE * sizeof(table_4_3_value[0])))
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
389 return -1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
390
392
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
391 int_pow_init();
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
392 for(i=1;i<TABLE_4_3_SIZE;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
393 int e, m;
392
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
394 m = int_pow(i, &e);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
395 #if 0
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
396 /* test code */
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
397 {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
398 double f, fm;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
399 int e1, m1;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
400 f = pow((double)i, 4.0 / 3.0);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
401 fm = frexp(f, &e1);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
402 m1 = FIXR(2 * fm);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
403 #if FRAC_BITS <= 15
407
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
404 if ((unsigned short)m1 != m1) {
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
405 m1 = m1 >> 1;
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
406 e1++;
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
407 }
392
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
408 #endif
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
409 e1--;
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
410 if (m != m1 || e != e1) {
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
411 printf("%4d: m=%x m1=%x e=%d e1=%d\n",
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
412 i, m, m1, e, e1);
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
413 }
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
414 }
4ef26ed29399 put all integer init code to compute n^(4/3) - memory alloc and header fixes
glantau
parents: 322
diff changeset
415 #endif
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
416 /* normalized to FRAC_BITS */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
417 table_4_3_value[i] = m;
407
c3aebacf546e fixed incorrect global gain - slightly increased precision of n^(4/3) table
glantau
parents: 404
diff changeset
418 table_4_3_exp[i] = e;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
419 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
420
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
421 for(i=0;i<7;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
422 float f;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
423 int v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
424 if (i != 6) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
425 f = tan((double)i * M_PI / 12.0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
426 v = FIXR(f / (1.0 + f));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
427 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
428 v = FIXR(1.0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
429 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
430 is_table[0][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
431 is_table[1][6 - i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
432 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
433 /* invalid values */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
434 for(i=7;i<16;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
435 is_table[0][i] = is_table[1][i] = 0.0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
436
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
437 for(i=0;i<16;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
438 double f;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
439 int e, k;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
440
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
441 for(j=0;j<2;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
442 e = -(j + 1) * ((i + 1) >> 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
443 f = pow(2.0, e / 4.0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
444 k = i & 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
445 is_table_lsf[j][k ^ 1][i] = FIXR(f);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
446 is_table_lsf[j][k][i] = FIXR(1.0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
447 dprintf("is_table_lsf %d %d: %x %x\n",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
448 i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
449 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
450 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
451
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
452 for(i=0;i<8;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
453 float ci, cs, ca;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
454 ci = ci_table[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
455 cs = 1.0 / sqrt(1.0 + ci * ci);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
456 ca = cs * ci;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
457 csa_table[i][0] = FIX(cs);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
458 csa_table[i][1] = FIX(ca);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
459 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
460
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
461 /* compute mdct windows */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
462 for(i=0;i<36;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
463 int v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
464 v = FIXR(sin(M_PI * (i + 0.5) / 36.0));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
465 mdct_win[0][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
466 mdct_win[1][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
467 mdct_win[3][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
468 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
469 for(i=0;i<6;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
470 mdct_win[1][18 + i] = FIXR(1.0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
471 mdct_win[1][24 + i] = FIXR(sin(M_PI * ((i + 6) + 0.5) / 12.0));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
472 mdct_win[1][30 + i] = FIXR(0.0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
473
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
474 mdct_win[3][i] = FIXR(0.0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
475 mdct_win[3][6 + i] = FIXR(sin(M_PI * (i + 0.5) / 12.0));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
476 mdct_win[3][12 + i] = FIXR(1.0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
477 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
478
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
479 for(i=0;i<12;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
480 mdct_win[2][i] = FIXR(sin(M_PI * (i + 0.5) / 12.0));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
481
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
482 /* NOTE: we do frequency inversion adter the MDCT by changing
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
483 the sign of the right window coefs */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
484 for(j=0;j<4;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
485 for(i=0;i<36;i+=2) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
486 mdct_win[j + 4][i] = mdct_win[j][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
487 mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
488 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
489 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
490
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
491 #if defined(DEBUG)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
492 for(j=0;j<8;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
493 printf("win%d=\n", j);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
494 for(i=0;i<36;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
495 printf("%f, ", (double)mdct_win[j][i] / FRAC_ONE);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
496 printf("\n");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
497 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
498 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
499 init = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
500 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
501
986e461dc072 Initial revision
glantau
parents:
diff changeset
502 s->inbuf_index = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
503 s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE];
986e461dc072 Initial revision
glantau
parents:
diff changeset
504 s->inbuf_ptr = s->inbuf;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
505 #ifdef DEBUG
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
506 s->frame_count = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
507 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
508 return 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
509 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
510
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (M«©ns Rullg«©rd))
michaelni
parents: 902
diff changeset
511 /* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
512
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
513 /* cos(i*pi/64) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
514
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
515 #define COS0_0 FIXR(0.50060299823519630134)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
516 #define COS0_1 FIXR(0.50547095989754365998)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
517 #define COS0_2 FIXR(0.51544730992262454697)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
518 #define COS0_3 FIXR(0.53104259108978417447)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
519 #define COS0_4 FIXR(0.55310389603444452782)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
520 #define COS0_5 FIXR(0.58293496820613387367)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
521 #define COS0_6 FIXR(0.62250412303566481615)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
522 #define COS0_7 FIXR(0.67480834145500574602)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
523 #define COS0_8 FIXR(0.74453627100229844977)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
524 #define COS0_9 FIXR(0.83934964541552703873)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
525 #define COS0_10 FIXR(0.97256823786196069369)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
526 #define COS0_11 FIXR(1.16943993343288495515)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
527 #define COS0_12 FIXR(1.48416461631416627724)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
528 #define COS0_13 FIXR(2.05778100995341155085)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
529 #define COS0_14 FIXR(3.40760841846871878570)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
530 #define COS0_15 FIXR(10.19000812354805681150)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
531
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
532 #define COS1_0 FIXR(0.50241928618815570551)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
533 #define COS1_1 FIXR(0.52249861493968888062)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
534 #define COS1_2 FIXR(0.56694403481635770368)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
535 #define COS1_3 FIXR(0.64682178335999012954)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
536 #define COS1_4 FIXR(0.78815462345125022473)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
537 #define COS1_5 FIXR(1.06067768599034747134)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
538 #define COS1_6 FIXR(1.72244709823833392782)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
539 #define COS1_7 FIXR(5.10114861868916385802)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
540
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
541 #define COS2_0 FIXR(0.50979557910415916894)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
542 #define COS2_1 FIXR(0.60134488693504528054)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
543 #define COS2_2 FIXR(0.89997622313641570463)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
544 #define COS2_3 FIXR(2.56291544774150617881)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
545
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
546 #define COS3_0 FIXR(0.54119610014619698439)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
547 #define COS3_1 FIXR(1.30656296487637652785)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
548
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
549 #define COS4_0 FIXR(0.70710678118654752439)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
550
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
551 /* butterfly operator */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
552 #define BF(a, b, c)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
553 {\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
554 tmp0 = tab[a] + tab[b];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
555 tmp1 = tab[a] - tab[b];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
556 tab[a] = tmp0;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
557 tab[b] = MULL(tmp1, c);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
558 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
559
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
560 #define BF1(a, b, c, d)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
561 {\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
562 BF(a, b, COS4_0);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
563 BF(c, d, -COS4_0);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
564 tab[c] += tab[d];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
565 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
566
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
567 #define BF2(a, b, c, d)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
568 {\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
569 BF(a, b, COS4_0);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
570 BF(c, d, -COS4_0);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
571 tab[c] += tab[d];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
572 tab[a] += tab[c];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
573 tab[c] += tab[b];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
574 tab[b] += tab[d];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
575 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
576
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
577 #define ADD(a, b) tab[a] += tab[b]
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
578
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
579 /* DCT32 without 1/sqrt(2) coef zero scaling. */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
580 static void dct32(INT32 *out, INT32 *tab)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
581 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
582 int tmp0, tmp1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
583
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
584 /* pass 1 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
585 BF(0, 31, COS0_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
586 BF(1, 30, COS0_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
587 BF(2, 29, COS0_2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
588 BF(3, 28, COS0_3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
589 BF(4, 27, COS0_4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
590 BF(5, 26, COS0_5);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
591 BF(6, 25, COS0_6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
592 BF(7, 24, COS0_7);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
593 BF(8, 23, COS0_8);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
594 BF(9, 22, COS0_9);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
595 BF(10, 21, COS0_10);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
596 BF(11, 20, COS0_11);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
597 BF(12, 19, COS0_12);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
598 BF(13, 18, COS0_13);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
599 BF(14, 17, COS0_14);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
600 BF(15, 16, COS0_15);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
601
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
602 /* pass 2 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
603 BF(0, 15, COS1_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
604 BF(1, 14, COS1_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
605 BF(2, 13, COS1_2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
606 BF(3, 12, COS1_3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
607 BF(4, 11, COS1_4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
608 BF(5, 10, COS1_5);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
609 BF(6, 9, COS1_6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
610 BF(7, 8, COS1_7);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
611
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
612 BF(16, 31, -COS1_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
613 BF(17, 30, -COS1_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
614 BF(18, 29, -COS1_2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
615 BF(19, 28, -COS1_3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
616 BF(20, 27, -COS1_4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
617 BF(21, 26, -COS1_5);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
618 BF(22, 25, -COS1_6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
619 BF(23, 24, -COS1_7);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
620
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
621 /* pass 3 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
622 BF(0, 7, COS2_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
623 BF(1, 6, COS2_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
624 BF(2, 5, COS2_2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
625 BF(3, 4, COS2_3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
626
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
627 BF(8, 15, -COS2_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
628 BF(9, 14, -COS2_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
629 BF(10, 13, -COS2_2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
630 BF(11, 12, -COS2_3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
631
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
632 BF(16, 23, COS2_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
633 BF(17, 22, COS2_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
634 BF(18, 21, COS2_2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
635 BF(19, 20, COS2_3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
636
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
637 BF(24, 31, -COS2_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
638 BF(25, 30, -COS2_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
639 BF(26, 29, -COS2_2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
640 BF(27, 28, -COS2_3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
641
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
642 /* pass 4 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
643 BF(0, 3, COS3_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
644 BF(1, 2, COS3_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
645
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
646 BF(4, 7, -COS3_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
647 BF(5, 6, -COS3_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
648
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
649 BF(8, 11, COS3_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
650 BF(9, 10, COS3_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
651
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
652 BF(12, 15, -COS3_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
653 BF(13, 14, -COS3_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
654
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
655 BF(16, 19, COS3_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
656 BF(17, 18, COS3_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
657
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
658 BF(20, 23, -COS3_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
659 BF(21, 22, -COS3_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
660
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
661 BF(24, 27, COS3_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
662 BF(25, 26, COS3_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
663
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
664 BF(28, 31, -COS3_0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
665 BF(29, 30, -COS3_1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
666
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
667 /* pass 5 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
668 BF1(0, 1, 2, 3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
669 BF2(4, 5, 6, 7);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
670 BF1(8, 9, 10, 11);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
671 BF2(12, 13, 14, 15);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
672 BF1(16, 17, 18, 19);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
673 BF2(20, 21, 22, 23);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
674 BF1(24, 25, 26, 27);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
675 BF2(28, 29, 30, 31);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
676
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
677 /* pass 6 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
678
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
679 ADD( 8, 12);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
680 ADD(12, 10);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
681 ADD(10, 14);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
682 ADD(14, 9);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
683 ADD( 9, 13);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
684 ADD(13, 11);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
685 ADD(11, 15);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
686
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
687 out[ 0] = tab[0];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
688 out[16] = tab[1];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
689 out[ 8] = tab[2];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
690 out[24] = tab[3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
691 out[ 4] = tab[4];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
692 out[20] = tab[5];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
693 out[12] = tab[6];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
694 out[28] = tab[7];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
695 out[ 2] = tab[8];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
696 out[18] = tab[9];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
697 out[10] = tab[10];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
698 out[26] = tab[11];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
699 out[ 6] = tab[12];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
700 out[22] = tab[13];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
701 out[14] = tab[14];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
702 out[30] = tab[15];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
703
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
704 ADD(24, 28);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
705 ADD(28, 26);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
706 ADD(26, 30);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
707 ADD(30, 25);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
708 ADD(25, 29);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
709 ADD(29, 27);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
710 ADD(27, 31);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
711
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
712 out[ 1] = tab[16] + tab[24];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
713 out[17] = tab[17] + tab[25];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
714 out[ 9] = tab[18] + tab[26];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
715 out[25] = tab[19] + tab[27];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
716 out[ 5] = tab[20] + tab[28];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
717 out[21] = tab[21] + tab[29];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
718 out[13] = tab[22] + tab[30];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
719 out[29] = tab[23] + tab[31];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
720 out[ 3] = tab[24] + tab[20];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
721 out[19] = tab[25] + tab[21];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
722 out[11] = tab[26] + tab[22];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
723 out[27] = tab[27] + tab[23];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
724 out[ 7] = tab[28] + tab[18];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
725 out[23] = tab[29] + tab[19];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
726 out[15] = tab[30] + tab[17];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
727 out[31] = tab[31];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
728 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
729
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
730 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
731
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
732 #if FRAC_BITS <= 15
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
733
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
734 #define OUT_SAMPLE(sum)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
735 {\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
736 int sum1;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
737 sum1 = (sum + (1 << (OUT_SHIFT - 1))) >> OUT_SHIFT;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
738 if (sum1 < -32768)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
739 sum1 = -32768;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
740 else if (sum1 > 32767)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
741 sum1 = 32767;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
742 *samples = sum1;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
743 samples += incr;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
744 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
745
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
746 #define SUM8(off, op) \
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
747 { \
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
748 sum op w[0 * 64 + off] * p[0 * 64];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
749 sum op w[1 * 64 + off] * p[1 * 64];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
750 sum op w[2 * 64 + off] * p[2 * 64];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
751 sum op w[3 * 64 + off] * p[3 * 64];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
752 sum op w[4 * 64 + off] * p[4 * 64];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
753 sum op w[5 * 64 + off] * p[5 * 64];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
754 sum op w[6 * 64 + off] * p[6 * 64];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
755 sum op w[7 * 64 + off] * p[7 * 64];\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
756 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
757
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
758 #else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
759
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
760 #define OUT_SAMPLE(sum)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
761 {\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
762 int sum1;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
763 sum1 = (int)((sum + (INT64_C(1) << (OUT_SHIFT - 1))) >> OUT_SHIFT);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
764 if (sum1 < -32768)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
765 sum1 = -32768;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
766 else if (sum1 > 32767)\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
767 sum1 = 32767;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
768 *samples = sum1;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
769 samples += incr;\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
770 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
771
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
772 #define SUM8(off, op) \
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
773 { \
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
774 sum op MUL64(w[0 * 64 + off], p[0 * 64]);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
775 sum op MUL64(w[1 * 64 + off], p[1 * 64]);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
776 sum op MUL64(w[2 * 64 + off], p[2 * 64]);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
777 sum op MUL64(w[3 * 64 + off], p[3 * 64]);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
778 sum op MUL64(w[4 * 64 + off], p[4 * 64]);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
779 sum op MUL64(w[5 * 64 + off], p[5 * 64]);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
780 sum op MUL64(w[6 * 64 + off], p[6 * 64]);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
781 sum op MUL64(w[7 * 64 + off], p[7 * 64]);\
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
782 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
783
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
784 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
785
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
786 /* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
787 32 samples. */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
788 /* XXX: optimize by avoiding ring buffer usage */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
789 static void synth_filter(MPADecodeContext *s1,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
790 int ch, INT16 *samples, int incr,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
791 INT32 sb_samples[SBLIMIT])
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
792 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
793 INT32 tmp[32];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
794 register MPA_INT *synth_buf, *p;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
795 register MPA_INT *w;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
796 int j, offset, v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
797 #if FRAC_BITS <= 15
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
798 int sum;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
799 #else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
800 INT64 sum;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
801 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
802
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
803 dct32(tmp, sb_samples);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
804
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
805 offset = s1->synth_buf_offset[ch];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
806 synth_buf = s1->synth_buf[ch] + offset;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
807
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
808 for(j=0;j<32;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
809 v = tmp[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
810 #if FRAC_BITS <= 15
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
811 /* NOTE: can cause a loss in precision if very high amplitude
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
812 sound */
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
813 if (v > 32767)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
814 v = 32767;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
815 else if (v < -32768)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
816 v = -32768;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
817 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
818 synth_buf[j] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
819 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
820 /* copy to avoid wrap */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
821 memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
822
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
823 w = window;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
824 for(j=0;j<16;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
825 sum = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
826 p = synth_buf + 16 + j; /* 0-15 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
827 SUM8(0, +=);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
828 p = synth_buf + 48 - j; /* 32-47 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
829 SUM8(32, -=);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
830 OUT_SAMPLE(sum);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
831 w++;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
832 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
833
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
834 p = synth_buf + 32; /* 48 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
835 sum = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
836 SUM8(32, -=);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
837 OUT_SAMPLE(sum);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
838 w++;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
839
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
840 for(j=17;j<32;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
841 sum = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
842 p = synth_buf + 48 - j; /* 17-31 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
843 SUM8(0, -=);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
844 p = synth_buf + 16 + j; /* 49-63 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
845 SUM8(32, -=);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
846 OUT_SAMPLE(sum);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
847 w++;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
848 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
849 offset = (offset - 32) & 511;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
850 s1->synth_buf_offset[ch] = offset;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
851 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
852
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
853 /* cos(pi*i/24) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
854 #define C1 FIXR(0.99144486137381041114)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
855 #define C3 FIXR(0.92387953251128675612)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
856 #define C5 FIXR(0.79335334029123516458)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
857 #define C7 FIXR(0.60876142900872063941)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
858 #define C9 FIXR(0.38268343236508977173)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
859 #define C11 FIXR(0.13052619222005159154)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
860
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
861 /* 12 points IMDCT. We compute it "by hand" by factorizing obvious
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
862 cases. */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
863 static void imdct12(int *out, int *in)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
864 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
865 int tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
866 INT64 in1_3, in1_9, in4_3, in4_9;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
867
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
868 in1_3 = MUL64(in[1], C3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
869 in1_9 = MUL64(in[1], C9);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
870 in4_3 = MUL64(in[4], C3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
871 in4_9 = MUL64(in[4], C9);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
872
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
873 tmp = FRAC_RND(MUL64(in[0], C7) - in1_3 - MUL64(in[2], C11) +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
874 MUL64(in[3], C1) - in4_9 - MUL64(in[5], C5));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
875 out[0] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
876 out[5] = -tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
877 tmp = FRAC_RND(MUL64(in[0] - in[3], C9) - in1_3 +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
878 MUL64(in[2] + in[5], C3) - in4_9);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
879 out[1] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
880 out[4] = -tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
881 tmp = FRAC_RND(MUL64(in[0], C11) - in1_9 + MUL64(in[2], C7) -
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
882 MUL64(in[3], C5) + in4_3 - MUL64(in[5], C1));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
883 out[2] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
884 out[3] = -tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
885 tmp = FRAC_RND(MUL64(-in[0], C5) + in1_9 + MUL64(in[2], C1) +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
886 MUL64(in[3], C11) - in4_3 - MUL64(in[5], C7));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
887 out[6] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
888 out[11] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
889 tmp = FRAC_RND(MUL64(-in[0] + in[3], C3) - in1_9 +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
890 MUL64(in[2] + in[5], C9) + in4_3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
891 out[7] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
892 out[10] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
893 tmp = FRAC_RND(-MUL64(in[0], C1) - in1_3 - MUL64(in[2], C5) -
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
894 MUL64(in[3], C7) - in4_9 - MUL64(in[5], C11));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
895 out[8] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
896 out[9] = tmp;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
897 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
898
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
899 #undef C1
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
900 #undef C3
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
901 #undef C5
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
902 #undef C7
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
903 #undef C9
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
904 #undef C11
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
905
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
906 /* cos(pi*i/18) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
907 #define C1 FIXR(0.98480775301220805936)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
908 #define C2 FIXR(0.93969262078590838405)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
909 #define C3 FIXR(0.86602540378443864676)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
910 #define C4 FIXR(0.76604444311897803520)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
911 #define C5 FIXR(0.64278760968653932632)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
912 #define C6 FIXR(0.5)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
913 #define C7 FIXR(0.34202014332566873304)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
914 #define C8 FIXR(0.17364817766693034885)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
915
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
916 /* 0.5 / cos(pi*(2*i+1)/36) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
917 static const int icos36[9] = {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
918 FIXR(0.50190991877167369479),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
919 FIXR(0.51763809020504152469),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
920 FIXR(0.55168895948124587824),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
921 FIXR(0.61038729438072803416),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
922 FIXR(0.70710678118654752439),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
923 FIXR(0.87172339781054900991),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
924 FIXR(1.18310079157624925896),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
925 FIXR(1.93185165257813657349),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
926 FIXR(5.73685662283492756461),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
927 };
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
928
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
929 static const int icos72[18] = {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
930 /* 0.5 / cos(pi*(2*i+19)/72) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
931 FIXR(0.74009361646113053152),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
932 FIXR(0.82133981585229078570),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
933 FIXR(0.93057949835178895673),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
934 FIXR(1.08284028510010010928),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
935 FIXR(1.30656296487637652785),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
936 FIXR(1.66275476171152078719),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
937 FIXR(2.31011315767264929558),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
938 FIXR(3.83064878777019433457),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
939 FIXR(11.46279281302667383546),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
940
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
941 /* 0.5 / cos(pi*(2*(i + 18) +19)/72) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
942 FIXR(-0.67817085245462840086),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
943 FIXR(-0.63023620700513223342),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
944 FIXR(-0.59284452371708034528),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
945 FIXR(-0.56369097343317117734),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
946 FIXR(-0.54119610014619698439),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
947 FIXR(-0.52426456257040533932),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
948 FIXR(-0.51213975715725461845),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
949 FIXR(-0.50431448029007636036),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
950 FIXR(-0.50047634258165998492),
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
951 };
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
952
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
953 /* using Lee like decomposition followed by hand coded 9 points DCT */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
954 static void imdct36(int *out, int *in)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
955 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
956 int i, j, t0, t1, t2, t3, s0, s1, s2, s3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
957 int tmp[18], *tmp1, *in1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
958 INT64 in3_3, in6_6;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
959
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
960 for(i=17;i>=1;i--)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
961 in[i] += in[i-1];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
962 for(i=17;i>=3;i-=2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
963 in[i] += in[i-2];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
964
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
965 for(j=0;j<2;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
966 tmp1 = tmp + j;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
967 in1 = in + j;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
968
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
969 in3_3 = MUL64(in1[2*3], C3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
970 in6_6 = MUL64(in1[2*6], C6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
971
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
972 tmp1[0] = FRAC_RND(MUL64(in1[2*1], C1) + in3_3 +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
973 MUL64(in1[2*5], C5) + MUL64(in1[2*7], C7));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
974 tmp1[2] = in1[2*0] + FRAC_RND(MUL64(in1[2*2], C2) +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
975 MUL64(in1[2*4], C4) + in6_6 +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
976 MUL64(in1[2*8], C8));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
977 tmp1[4] = FRAC_RND(MUL64(in1[2*1] - in1[2*5] - in1[2*7], C3));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
978 tmp1[6] = FRAC_RND(MUL64(in1[2*2] - in1[2*4] - in1[2*8], C6)) -
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
979 in1[2*6] + in1[2*0];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
980 tmp1[8] = FRAC_RND(MUL64(in1[2*1], C5) - in3_3 -
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
981 MUL64(in1[2*5], C7) + MUL64(in1[2*7], C1));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
982 tmp1[10] = in1[2*0] + FRAC_RND(MUL64(-in1[2*2], C8) -
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
983 MUL64(in1[2*4], C2) + in6_6 +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
984 MUL64(in1[2*8], C4));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
985 tmp1[12] = FRAC_RND(MUL64(in1[2*1], C7) - in3_3 +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
986 MUL64(in1[2*5], C1) -
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
987 MUL64(in1[2*7], C5));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
988 tmp1[14] = in1[2*0] + FRAC_RND(MUL64(-in1[2*2], C4) +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
989 MUL64(in1[2*4], C8) + in6_6 -
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
990 MUL64(in1[2*8], C2));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
991 tmp1[16] = in1[2*0] - in1[2*2] + in1[2*4] - in1[2*6] + in1[2*8];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
992 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
993
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
994 i = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
995 for(j=0;j<4;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
996 t0 = tmp[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
997 t1 = tmp[i + 2];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
998 s0 = t1 + t0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
999 s2 = t1 - t0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1000
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1001 t2 = tmp[i + 1];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1002 t3 = tmp[i + 3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1003 s1 = MULL(t3 + t2, icos36[j]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1004 s3 = MULL(t3 - t2, icos36[8 - j]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1005
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1006 t0 = MULL(s0 + s1, icos72[9 + 8 - j]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1007 t1 = MULL(s0 - s1, icos72[8 - j]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1008 out[18 + 9 + j] = t0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1009 out[18 + 8 - j] = t0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1010 out[9 + j] = -t1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1011 out[8 - j] = t1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1012
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1013 t0 = MULL(s2 + s3, icos72[9+j]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1014 t1 = MULL(s2 - s3, icos72[j]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1015 out[18 + 9 + (8 - j)] = t0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1016 out[18 + j] = t0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1017 out[9 + (8 - j)] = -t1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1018 out[j] = t1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1019 i += 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1020 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1021
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1022 s0 = tmp[16];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1023 s1 = MULL(tmp[17], icos36[4]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1024 t0 = MULL(s0 + s1, icos72[9 + 4]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1025 t1 = MULL(s0 - s1, icos72[4]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1026 out[18 + 9 + 4] = t0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1027 out[18 + 8 - 4] = t0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1028 out[9 + 4] = -t1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1029 out[8 - 4] = t1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1030 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1031
986e461dc072 Initial revision
glantau
parents:
diff changeset
1032 /* fast header check for resync */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1033 static int check_header(UINT32 header)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1034 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1035 /* header */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1036 if ((header & 0xffe00000) != 0xffe00000)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1037 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1038 /* layer check */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1039 if (((header >> 17) & 3) == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1040 return -1;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1041 /* bit rate */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1042 if (((header >> 12) & 0xf) == 0xf)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1043 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1044 /* frequency */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1045 if (((header >> 10) & 3) == 3)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1046 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1047 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1048 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1049
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1050 /* header + layer + bitrate + freq + lsf/mpeg25 */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1051 #define SAME_HEADER_MASK \
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1052 (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1053
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1054 /* header decoding. MUST check the header before because no
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1055 consistency check is done there. Return 1 if free format found and
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1056 that the frame size must be computed externally */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1057 static int decode_header(MPADecodeContext *s, UINT32 header)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1058 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1059 int sample_rate, frame_size, mpeg25, padding;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1060 int sample_rate_index, bitrate_index;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1061 if (header & (1<<20)) {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1062 s->lsf = (header & (1<<19)) ? 0 : 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1063 mpeg25 = 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1064 } else {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1065 s->lsf = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1066 mpeg25 = 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1067 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1068
986e461dc072 Initial revision
glantau
parents:
diff changeset
1069 s->layer = 4 - ((header >> 17) & 3);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1070 /* extract frequency */
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1071 sample_rate_index = (header >> 10) & 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1072 sample_rate = mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1073 sample_rate_index += 3 * (s->lsf + mpeg25);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1074 s->sample_rate_index = sample_rate_index;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1075 s->error_protection = ((header >> 16) & 1) ^ 1;
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1076 s->sample_rate = sample_rate;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1077
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1078 bitrate_index = (header >> 12) & 0xf;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1079 padding = (header >> 9) & 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1080 //extension = (header >> 8) & 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1081 s->mode = (header >> 6) & 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1082 s->mode_ext = (header >> 4) & 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1083 //copyright = (header >> 3) & 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1084 //original = (header >> 2) & 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1085 //emphasis = header & 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1086
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1087 if (s->mode == MPA_MONO)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1088 s->nb_channels = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1089 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1090 s->nb_channels = 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1091
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1092 if (bitrate_index != 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1093 frame_size = mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1094 s->bit_rate = frame_size * 1000;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1095 switch(s->layer) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1096 case 1:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1097 frame_size = (frame_size * 12000) / sample_rate;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1098 frame_size = (frame_size + padding) * 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1099 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1100 case 2:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1101 frame_size = (frame_size * 144000) / sample_rate;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1102 frame_size += padding;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1103 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1104 default:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1105 case 3:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1106 frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1107 frame_size += padding;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1108 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1109 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1110 s->frame_size = frame_size;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1111 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1112 /* if no frame size computed, signal it */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1113 if (!s->free_format_frame_size)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1114 return 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1115 /* free format: compute bitrate and real frame size from the
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1116 frame size we extracted by reading the bitstream */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1117 s->frame_size = s->free_format_frame_size;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1118 switch(s->layer) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1119 case 1:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1120 s->frame_size += padding * 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1121 s->bit_rate = (s->frame_size * sample_rate) / 48000;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1122 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1123 case 2:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1124 s->frame_size += padding;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1125 s->bit_rate = (s->frame_size * sample_rate) / 144000;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1126 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1127 default:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1128 case 3:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1129 s->frame_size += padding;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1130 s->bit_rate = (s->frame_size * (sample_rate << s->lsf)) / 144000;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1131 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1132 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1133 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1134
431
1dd34dba2b7c removed invalid buffer handling
bellard
parents: 429
diff changeset
1135 #if defined(DEBUG)
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1136 printf("layer%d, %d Hz, %d kbits/s, ",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1137 s->layer, s->sample_rate, s->bit_rate);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1138 if (s->nb_channels == 2) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1139 if (s->layer == 3) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1140 if (s->mode_ext & MODE_EXT_MS_STEREO)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1141 printf("ms-");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1142 if (s->mode_ext & MODE_EXT_I_STEREO)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1143 printf("i-");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1144 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1145 printf("stereo");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1146 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1147 printf("mono");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1148 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1149 printf("\n");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1150 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1151 return 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1152 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1153
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1154 /* return the number of decoded frames */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1155 static int mp_decode_layer1(MPADecodeContext *s)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1156 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1157 int bound, i, v, n, ch, j, mant;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1158 UINT8 allocation[MPA_MAX_CHANNELS][SBLIMIT];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1159 UINT8 scale_factors[MPA_MAX_CHANNELS][SBLIMIT];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1160
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1161 if (s->mode == MPA_JSTEREO)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1162 bound = (s->mode_ext + 1) * 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1163 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1164 bound = SBLIMIT;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1165
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1166 /* allocation bits */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1167 for(i=0;i<bound;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1168 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1169 allocation[ch][i] = get_bits(&s->gb, 4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1170 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1171 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1172 for(i=bound;i<SBLIMIT;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1173 allocation[0][i] = get_bits(&s->gb, 4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1174 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1175
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1176 /* scale factors */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1177 for(i=0;i<bound;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1178 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1179 if (allocation[ch][i])
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1180 scale_factors[ch][i] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1181 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1182 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1183 for(i=bound;i<SBLIMIT;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1184 if (allocation[0][i]) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1185 scale_factors[0][i] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1186 scale_factors[1][i] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1187 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1188 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1189
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1190 /* compute samples */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1191 for(j=0;j<12;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1192 for(i=0;i<bound;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1193 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1194 n = allocation[ch][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1195 if (n) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1196 mant = get_bits(&s->gb, n + 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1197 v = l1_unscale(n, mant, scale_factors[ch][i]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1198 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1199 v = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1200 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1201 s->sb_samples[ch][j][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1202 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1203 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1204 for(i=bound;i<SBLIMIT;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1205 n = allocation[0][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1206 if (n) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1207 mant = get_bits(&s->gb, n + 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1208 v = l1_unscale(n, mant, scale_factors[0][i]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1209 s->sb_samples[0][j][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1210 v = l1_unscale(n, mant, scale_factors[1][i]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1211 s->sb_samples[1][j][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1212 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1213 s->sb_samples[0][j][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1214 s->sb_samples[1][j][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1215 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1216 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1217 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1218 return 12;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1219 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1220
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1221 /* bitrate is in kb/s */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1222 int l2_select_table(int bitrate, int nb_channels, int freq, int lsf)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1223 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1224 int ch_bitrate, table;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1225
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1226 ch_bitrate = bitrate / nb_channels;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1227 if (!lsf) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1228 if ((freq == 48000 && ch_bitrate >= 56) ||
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1229 (ch_bitrate >= 56 && ch_bitrate <= 80))
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1230 table = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1231 else if (freq != 48000 && ch_bitrate >= 96)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1232 table = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1233 else if (freq != 32000 && ch_bitrate <= 48)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1234 table = 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1235 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1236 table = 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1237 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1238 table = 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1239 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1240 return table;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1241 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1242
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1243 static int mp_decode_layer2(MPADecodeContext *s)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1244 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1245 int sblimit; /* number of used subbands */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1246 const unsigned char *alloc_table;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1247 int table, bit_alloc_bits, i, j, ch, bound, v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1248 unsigned char bit_alloc[MPA_MAX_CHANNELS][SBLIMIT];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1249 unsigned char scale_code[MPA_MAX_CHANNELS][SBLIMIT];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1250 unsigned char scale_factors[MPA_MAX_CHANNELS][SBLIMIT][3], *sf;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1251 int scale, qindex, bits, steps, k, l, m, b;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1252
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1253 /* select decoding table */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1254 table = l2_select_table(s->bit_rate / 1000, s->nb_channels,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1255 s->sample_rate, s->lsf);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1256 sblimit = sblimit_table[table];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1257 alloc_table = alloc_tables[table];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1258
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1259 if (s->mode == MPA_JSTEREO)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1260 bound = (s->mode_ext + 1) * 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1261 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1262 bound = sblimit;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1263
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1264 dprintf("bound=%d sblimit=%d\n", bound, sblimit);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1265 /* parse bit allocation */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1266 j = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1267 for(i=0;i<bound;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1268 bit_alloc_bits = alloc_table[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1269 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1270 bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1271 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1272 j += 1 << bit_alloc_bits;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1273 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1274 for(i=bound;i<sblimit;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1275 bit_alloc_bits = alloc_table[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1276 v = get_bits(&s->gb, bit_alloc_bits);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1277 bit_alloc[0][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1278 bit_alloc[1][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1279 j += 1 << bit_alloc_bits;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1280 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1281
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1282 #ifdef DEBUG
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1283 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1284 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1285 for(i=0;i<sblimit;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1286 printf(" %d", bit_alloc[ch][i]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1287 printf("\n");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1288 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1289 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1290 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1291
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1292 /* scale codes */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1293 for(i=0;i<sblimit;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1294 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1295 if (bit_alloc[ch][i])
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1296 scale_code[ch][i] = get_bits(&s->gb, 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1297 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1298 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1299
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1300 /* scale factors */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1301 for(i=0;i<sblimit;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1302 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1303 if (bit_alloc[ch][i]) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1304 sf = scale_factors[ch][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1305 switch(scale_code[ch][i]) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1306 default:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1307 case 0:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1308 sf[0] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1309 sf[1] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1310 sf[2] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1311 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1312 case 2:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1313 sf[0] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1314 sf[1] = sf[0];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1315 sf[2] = sf[0];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1316 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1317 case 1:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1318 sf[0] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1319 sf[2] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1320 sf[1] = sf[0];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1321 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1322 case 3:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1323 sf[0] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1324 sf[2] = get_bits(&s->gb, 6);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1325 sf[1] = sf[2];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1326 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1327 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1328 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1329 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1330 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1331
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1332 #ifdef DEBUG
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1333 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1334 for(i=0;i<sblimit;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1335 if (bit_alloc[ch][i]) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1336 sf = scale_factors[ch][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1337 printf(" %d %d %d", sf[0], sf[1], sf[2]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1338 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1339 printf(" -");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1340 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1341 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1342 printf("\n");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1343 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1344 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1345
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1346 /* samples */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1347 for(k=0;k<3;k++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1348 for(l=0;l<12;l+=3) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1349 j = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1350 for(i=0;i<bound;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1351 bit_alloc_bits = alloc_table[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1352 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1353 b = bit_alloc[ch][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1354 if (b) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1355 scale = scale_factors[ch][i][k];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1356 qindex = alloc_table[j+b];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1357 bits = quant_bits[qindex];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1358 if (bits < 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1359 /* 3 values at the same time */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1360 v = get_bits(&s->gb, -bits);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1361 steps = quant_steps[qindex];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1362 s->sb_samples[ch][k * 12 + l + 0][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1363 l2_unscale_group(steps, v % steps, scale);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1364 v = v / steps;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1365 s->sb_samples[ch][k * 12 + l + 1][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1366 l2_unscale_group(steps, v % steps, scale);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1367 v = v / steps;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1368 s->sb_samples[ch][k * 12 + l + 2][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1369 l2_unscale_group(steps, v, scale);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1370 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1371 for(m=0;m<3;m++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1372 v = get_bits(&s->gb, bits);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1373 v = l1_unscale(bits - 1, v, scale);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1374 s->sb_samples[ch][k * 12 + l + m][i] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1375 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1376 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1377 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1378 s->sb_samples[ch][k * 12 + l + 0][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1379 s->sb_samples[ch][k * 12 + l + 1][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1380 s->sb_samples[ch][k * 12 + l + 2][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1381 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1382 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1383 /* next subband in alloc table */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1384 j += 1 << bit_alloc_bits;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1385 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1386 /* XXX: find a way to avoid this duplication of code */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1387 for(i=bound;i<sblimit;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1388 bit_alloc_bits = alloc_table[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1389 b = bit_alloc[0][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1390 if (b) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1391 int mant, scale0, scale1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1392 scale0 = scale_factors[0][i][k];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1393 scale1 = scale_factors[1][i][k];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1394 qindex = alloc_table[j+b];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1395 bits = quant_bits[qindex];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1396 if (bits < 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1397 /* 3 values at the same time */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1398 v = get_bits(&s->gb, -bits);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1399 steps = quant_steps[qindex];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1400 mant = v % steps;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1401 v = v / steps;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1402 s->sb_samples[0][k * 12 + l + 0][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1403 l2_unscale_group(steps, mant, scale0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1404 s->sb_samples[1][k * 12 + l + 0][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1405 l2_unscale_group(steps, mant, scale1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1406 mant = v % steps;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1407 v = v / steps;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1408 s->sb_samples[0][k * 12 + l + 1][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1409 l2_unscale_group(steps, mant, scale0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1410 s->sb_samples[1][k * 12 + l + 1][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1411 l2_unscale_group(steps, mant, scale1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1412 s->sb_samples[0][k * 12 + l + 2][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1413 l2_unscale_group(steps, v, scale0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1414 s->sb_samples[1][k * 12 + l + 2][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1415 l2_unscale_group(steps, v, scale1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1416 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1417 for(m=0;m<3;m++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1418 mant = get_bits(&s->gb, bits);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1419 s->sb_samples[0][k * 12 + l + m][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1420 l1_unscale(bits - 1, mant, scale0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1421 s->sb_samples[1][k * 12 + l + m][i] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1422 l1_unscale(bits - 1, mant, scale1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1423 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1424 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1425 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1426 s->sb_samples[0][k * 12 + l + 0][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1427 s->sb_samples[0][k * 12 + l + 1][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1428 s->sb_samples[0][k * 12 + l + 2][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1429 s->sb_samples[1][k * 12 + l + 0][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1430 s->sb_samples[1][k * 12 + l + 1][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1431 s->sb_samples[1][k * 12 + l + 2][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1432 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1433 /* next subband in alloc table */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1434 j += 1 << bit_alloc_bits;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1435 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1436 /* fill remaining samples to zero */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1437 for(i=sblimit;i<SBLIMIT;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1438 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1439 s->sb_samples[ch][k * 12 + l + 0][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1440 s->sb_samples[ch][k * 12 + l + 1][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1441 s->sb_samples[ch][k * 12 + l + 2][i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1442 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1443 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1444 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1445 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1446 return 3 * 12;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1447 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1448
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1449 /*
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1450 * Seek back in the stream for backstep bytes (at most 511 bytes)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1451 */
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 1025
diff changeset
1452 static void seek_to_maindata(MPADecodeContext *s, unsigned int backstep)
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1453 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1454 UINT8 *ptr;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1455
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1456 /* compute current position in stream */
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 468
diff changeset
1457 ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3);
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 468
diff changeset
1458
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1459 /* copy old data before current one */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1460 ptr -= backstep;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1461 memcpy(ptr, s->inbuf1[s->inbuf_index ^ 1] +
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1462 BACKSTEP_SIZE + s->old_frame_size - backstep, backstep);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1463 /* init get bits again */
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 1014
diff changeset
1464 init_get_bits(&s->gb, ptr, (s->frame_size + backstep)*8);
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1465
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1466 /* prepare next buffer */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1467 s->inbuf_index ^= 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1468 s->inbuf = &s->inbuf1[s->inbuf_index][BACKSTEP_SIZE];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1469 s->old_frame_size = s->frame_size;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1470 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1471
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1472 static inline void lsf_sf_expand(int *slen,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1473 int sf, int n1, int n2, int n3)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1474 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1475 if (n3) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1476 slen[3] = sf % n3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1477 sf /= n3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1478 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1479 slen[3] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1480 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1481 if (n2) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1482 slen[2] = sf % n2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1483 sf /= n2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1484 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1485 slen[2] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1486 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1487 slen[1] = sf % n1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1488 sf /= n1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1489 slen[0] = sf;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1490 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1491
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1492 static void exponents_from_scale_factors(MPADecodeContext *s,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1493 GranuleDef *g,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1494 INT16 *exponents)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1495 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1496 const UINT8 *bstab, *pretab;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1497 int len, i, j, k, l, v0, shift, gain, gains[3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1498 INT16 *exp_ptr;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1499
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1500 exp_ptr = exponents;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1501 gain = g->global_gain - 210;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1502 shift = g->scalefac_scale + 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1503
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1504 bstab = band_size_long[s->sample_rate_index];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1505 pretab = mpa_pretab[g->preflag];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1506 for(i=0;i<g->long_end;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1507 v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1508 len = bstab[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1509 for(j=len;j>0;j--)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1510 *exp_ptr++ = v0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1511 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1512
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1513 if (g->short_start < 13) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1514 bstab = band_size_short[s->sample_rate_index];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1515 gains[0] = gain - (g->subblock_gain[0] << 3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1516 gains[1] = gain - (g->subblock_gain[1] << 3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1517 gains[2] = gain - (g->subblock_gain[2] << 3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1518 k = g->long_end;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1519 for(i=g->short_start;i<13;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1520 len = bstab[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1521 for(l=0;l<3;l++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1522 v0 = gains[l] - (g->scale_factors[k++] << shift);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1523 for(j=len;j>0;j--)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1524 *exp_ptr++ = v0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1525 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1526 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1527 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1528 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1529
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1530 /* handle n = 0 too */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1531 static inline int get_bitsz(GetBitContext *s, int n)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1532 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1533 if (n == 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1534 return 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1535 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1536 return get_bits(s, n);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1537 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1538
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1539 static int huffman_decode(MPADecodeContext *s, GranuleDef *g,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1540 INT16 *exponents, int end_pos)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1541 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1542 int s_index;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1543 int linbits, code, x, y, l, v, i, j, k, pos;
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 468
diff changeset
1544 GetBitContext last_gb;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1545 VLC *vlc;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1546 UINT8 *code_table;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1547
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1548 /* low frequencies (called big values) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1549 s_index = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1550 for(i=0;i<3;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1551 j = g->region_size[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1552 if (j == 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1553 continue;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1554 /* select vlc table */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1555 k = g->table_select[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1556 l = mpa_huff_data[k][0];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1557 linbits = mpa_huff_data[k][1];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1558 vlc = &huff_vlc[l];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1559 code_table = huff_code_table[l];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1560
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1561 /* read huffcode and compute each couple */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1562 for(;j>0;j--) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1563 if (get_bits_count(&s->gb) >= end_pos)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1564 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1565 if (code_table) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1566 code = get_vlc(&s->gb, vlc);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1567 if (code < 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1568 return -1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1569 y = code_table[code];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1570 x = y >> 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1571 y = y & 0x0f;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1572 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1573 x = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1574 y = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1575 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1576 dprintf("region=%d n=%d x=%d y=%d exp=%d\n",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1577 i, g->region_size[i] - j, x, y, exponents[s_index]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1578 if (x) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1579 if (x == 15)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1580 x += get_bitsz(&s->gb, linbits);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1581 v = l3_unscale(x, exponents[s_index]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1582 if (get_bits1(&s->gb))
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1583 v = -v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1584 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1585 v = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1586 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1587 g->sb_hybrid[s_index++] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1588 if (y) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1589 if (y == 15)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1590 y += get_bitsz(&s->gb, linbits);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1591 v = l3_unscale(y, exponents[s_index]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1592 if (get_bits1(&s->gb))
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1593 v = -v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1594 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1595 v = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1596 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1597 g->sb_hybrid[s_index++] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1598 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1599 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1600
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1601 /* high frequencies */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1602 vlc = &huff_quad_vlc[g->count1table_select];
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 468
diff changeset
1603 last_gb.buffer = NULL;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1604 while (s_index <= 572) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1605 pos = get_bits_count(&s->gb);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1606 if (pos >= end_pos) {
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 468
diff changeset
1607 if (pos > end_pos && last_gb.buffer != NULL) {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1608 /* some encoders generate an incorrect size for this
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1609 part. We must go back into the data */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1610 s_index -= 4;
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 468
diff changeset
1611 s->gb = last_gb;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1612 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1613 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1614 }
520
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 468
diff changeset
1615 last_gb= s->gb;
19a5e2a81e1a new bitstream reader API (old get_bits() based one is emulated and will still be supported in the future cuz its simpler)
michaelni
parents: 468
diff changeset
1616
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1617 code = get_vlc(&s->gb, vlc);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1618 dprintf("t=%d code=%d\n", g->count1table_select, code);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1619 if (code < 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1620 return -1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1621 for(i=0;i<4;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1622 if (code & (8 >> i)) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1623 /* non zero value. Could use a hand coded function for
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1624 'one' value */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1625 v = l3_unscale(1, exponents[s_index]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1626 if(get_bits1(&s->gb))
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1627 v = -v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1628 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1629 v = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1630 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1631 g->sb_hybrid[s_index++] = v;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1632 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1633 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1634 while (s_index < 576)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1635 g->sb_hybrid[s_index++] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1636 return 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1637 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1638
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1639 /* Reorder short blocks from bitstream order to interleaved order. It
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1640 would be faster to do it in parsing, but the code would be far more
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1641 complicated */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1642 static void reorder_block(MPADecodeContext *s, GranuleDef *g)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1643 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1644 int i, j, k, len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1645 INT32 *ptr, *dst, *ptr1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1646 INT32 tmp[576];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1647
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1648 if (g->block_type != 2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1649 return;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1650
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1651 if (g->switch_point) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1652 if (s->sample_rate_index != 8) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1653 ptr = g->sb_hybrid + 36;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1654 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1655 ptr = g->sb_hybrid + 48;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1656 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1657 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1658 ptr = g->sb_hybrid;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1659 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1660
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1661 for(i=g->short_start;i<13;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1662 len = band_size_short[s->sample_rate_index][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1663 ptr1 = ptr;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1664 for(k=0;k<3;k++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1665 dst = tmp + k;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1666 for(j=len;j>0;j--) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1667 *dst = *ptr++;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1668 dst += 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1669 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1670 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1671 memcpy(ptr1, tmp, len * 3 * sizeof(INT32));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1672 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1673 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1674
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1675 #define ISQRT2 FIXR(0.70710678118654752440)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1676
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1677 static void compute_stereo(MPADecodeContext *s,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1678 GranuleDef *g0, GranuleDef *g1)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1679 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1680 int i, j, k, l;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1681 INT32 v1, v2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1682 int sf_max, tmp0, tmp1, sf, len, non_zero_found;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1683 INT32 (*is_tab)[16];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1684 INT32 *tab0, *tab1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1685 int non_zero_found_short[3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1686
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1687 /* intensity stereo */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1688 if (s->mode_ext & MODE_EXT_I_STEREO) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1689 if (!s->lsf) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1690 is_tab = is_table;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1691 sf_max = 7;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1692 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1693 is_tab = is_table_lsf[g1->scalefac_compress & 1];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1694 sf_max = 16;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1695 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1696
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1697 tab0 = g0->sb_hybrid + 576;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1698 tab1 = g1->sb_hybrid + 576;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1699
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1700 non_zero_found_short[0] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1701 non_zero_found_short[1] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1702 non_zero_found_short[2] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1703 k = (13 - g1->short_start) * 3 + g1->long_end - 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1704 for(i = 12;i >= g1->short_start;i--) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1705 /* for last band, use previous scale factor */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1706 if (i != 11)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1707 k -= 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1708 len = band_size_short[s->sample_rate_index][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1709 for(l=2;l>=0;l--) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1710 tab0 -= len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1711 tab1 -= len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1712 if (!non_zero_found_short[l]) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1713 /* test if non zero band. if so, stop doing i-stereo */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1714 for(j=0;j<len;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1715 if (tab1[j] != 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1716 non_zero_found_short[l] = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1717 goto found1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1718 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1719 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1720 sf = g1->scale_factors[k + l];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1721 if (sf >= sf_max)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1722 goto found1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1723
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1724 v1 = is_tab[0][sf];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1725 v2 = is_tab[1][sf];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1726 for(j=0;j<len;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1727 tmp0 = tab0[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1728 tab0[j] = MULL(tmp0, v1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1729 tab1[j] = MULL(tmp0, v2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1730 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1731 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1732 found1:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1733 if (s->mode_ext & MODE_EXT_MS_STEREO) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1734 /* lower part of the spectrum : do ms stereo
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1735 if enabled */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1736 for(j=0;j<len;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1737 tmp0 = tab0[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1738 tmp1 = tab1[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1739 tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1740 tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1741 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1742 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1743 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1744 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1745 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1746
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1747 non_zero_found = non_zero_found_short[0] |
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1748 non_zero_found_short[1] |
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1749 non_zero_found_short[2];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1750
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1751 for(i = g1->long_end - 1;i >= 0;i--) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1752 len = band_size_long[s->sample_rate_index][i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1753 tab0 -= len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1754 tab1 -= len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1755 /* test if non zero band. if so, stop doing i-stereo */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1756 if (!non_zero_found) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1757 for(j=0;j<len;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1758 if (tab1[j] != 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1759 non_zero_found = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1760 goto found2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1761 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1762 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1763 /* for last band, use previous scale factor */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1764 k = (i == 21) ? 20 : i;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1765 sf = g1->scale_factors[k];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1766 if (sf >= sf_max)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1767 goto found2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1768 v1 = is_tab[0][sf];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1769 v2 = is_tab[1][sf];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1770 for(j=0;j<len;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1771 tmp0 = tab0[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1772 tab0[j] = MULL(tmp0, v1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1773 tab1[j] = MULL(tmp0, v2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1774 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1775 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1776 found2:
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1777 if (s->mode_ext & MODE_EXT_MS_STEREO) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1778 /* lower part of the spectrum : do ms stereo
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1779 if enabled */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1780 for(j=0;j<len;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1781 tmp0 = tab0[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1782 tmp1 = tab1[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1783 tab0[j] = MULL(tmp0 + tmp1, ISQRT2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1784 tab1[j] = MULL(tmp0 - tmp1, ISQRT2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1785 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1786 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1787 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1788 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1789 } else if (s->mode_ext & MODE_EXT_MS_STEREO) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1790 /* ms stereo ONLY */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1791 /* NOTE: the 1/sqrt(2) normalization factor is included in the
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1792 global gain */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1793 tab0 = g0->sb_hybrid;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1794 tab1 = g1->sb_hybrid;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1795 for(i=0;i<576;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1796 tmp0 = tab0[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1797 tmp1 = tab1[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1798 tab0[i] = tmp0 + tmp1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1799 tab1[i] = tmp0 - tmp1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1800 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1801 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1802 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1803
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1804 static void compute_antialias(MPADecodeContext *s,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1805 GranuleDef *g)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1806 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1807 INT32 *ptr, *p0, *p1, *csa;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1808 int n, tmp0, tmp1, i, j;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1809
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1810 /* we antialias only "long" bands */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1811 if (g->block_type == 2) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1812 if (!g->switch_point)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1813 return;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1814 /* XXX: check this for 8000Hz case */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1815 n = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1816 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1817 n = SBLIMIT - 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1818 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1819
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1820 ptr = g->sb_hybrid + 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1821 for(i = n;i > 0;i--) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1822 p0 = ptr - 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1823 p1 = ptr;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1824 csa = &csa_table[0][0];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1825 for(j=0;j<8;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1826 tmp0 = *p0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1827 tmp1 = *p1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1828 *p0 = FRAC_RND(MUL64(tmp0, csa[0]) - MUL64(tmp1, csa[1]));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1829 *p1 = FRAC_RND(MUL64(tmp0, csa[1]) + MUL64(tmp1, csa[0]));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1830 p0--;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1831 p1++;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1832 csa += 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1833 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1834 ptr += 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1835 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1836 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1837
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1838 static void compute_imdct(MPADecodeContext *s,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1839 GranuleDef *g,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1840 INT32 *sb_samples,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1841 INT32 *mdct_buf)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1842 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1843 INT32 *ptr, *win, *win1, *buf, *buf2, *out_ptr, *ptr1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1844 INT32 in[6];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1845 INT32 out[36];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1846 INT32 out2[12];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1847 int i, j, k, mdct_long_end, v, sblimit;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1848
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1849 /* find last non zero block */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1850 ptr = g->sb_hybrid + 576;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1851 ptr1 = g->sb_hybrid + 2 * 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1852 while (ptr >= ptr1) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1853 ptr -= 6;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1854 v = ptr[0] | ptr[1] | ptr[2] | ptr[3] | ptr[4] | ptr[5];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1855 if (v != 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1856 break;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1857 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1858 sblimit = ((ptr - g->sb_hybrid) / 18) + 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1859
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1860 if (g->block_type == 2) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1861 /* XXX: check for 8000 Hz */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1862 if (g->switch_point)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1863 mdct_long_end = 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1864 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1865 mdct_long_end = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1866 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1867 mdct_long_end = sblimit;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1868 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1869
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1870 buf = mdct_buf;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1871 ptr = g->sb_hybrid;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1872 for(j=0;j<mdct_long_end;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1873 imdct36(out, ptr);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1874 /* apply window & overlap with previous buffer */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1875 out_ptr = sb_samples + j;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1876 /* select window */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1877 if (g->switch_point && j < 2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1878 win1 = mdct_win[0];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1879 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1880 win1 = mdct_win[g->block_type];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1881 /* select frequency inversion */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1882 win = win1 + ((4 * 36) & -(j & 1));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1883 for(i=0;i<18;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1884 *out_ptr = MULL(out[i], win[i]) + buf[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1885 buf[i] = MULL(out[i + 18], win[i + 18]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1886 out_ptr += SBLIMIT;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1887 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1888 ptr += 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1889 buf += 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1890 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1891 for(j=mdct_long_end;j<sblimit;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1892 for(i=0;i<6;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1893 out[i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1894 out[6 + i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1895 out[30+i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1896 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1897 /* select frequency inversion */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1898 win = mdct_win[2] + ((4 * 36) & -(j & 1));
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1899 buf2 = out + 6;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1900 for(k=0;k<3;k++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1901 /* reorder input for short mdct */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1902 ptr1 = ptr + k;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1903 for(i=0;i<6;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1904 in[i] = *ptr1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1905 ptr1 += 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1906 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1907 imdct12(out2, in);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1908 /* apply 12 point window and do small overlap */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1909 for(i=0;i<6;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1910 buf2[i] = MULL(out2[i], win[i]) + buf2[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1911 buf2[i + 6] = MULL(out2[i + 6], win[i + 6]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1912 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1913 buf2 += 6;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1914 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1915 /* overlap */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1916 out_ptr = sb_samples + j;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1917 for(i=0;i<18;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1918 *out_ptr = out[i] + buf[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1919 buf[i] = out[i + 18];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1920 out_ptr += SBLIMIT;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1921 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1922 ptr += 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1923 buf += 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1924 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1925 /* zero bands */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1926 for(j=sblimit;j<SBLIMIT;j++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1927 /* overlap */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1928 out_ptr = sb_samples + j;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1929 for(i=0;i<18;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1930 *out_ptr = buf[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1931 buf[i] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1932 out_ptr += SBLIMIT;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1933 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1934 buf += 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1935 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1936 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1937
404
29dc52c127c6 fixed one overflow problem
glantau
parents: 392
diff changeset
1938 #if defined(DEBUG)
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1939 void sample_dump(int fnum, INT32 *tab, int n)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1940 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1941 static FILE *files[16], *f;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1942 char buf[512];
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1943 int i;
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1944 INT32 v;
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1945
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1946 f = files[fnum];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1947 if (!f) {
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1948 sprintf(buf, "/tmp/out%d.%s.pcm",
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1949 fnum,
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1950 #ifdef USE_HIGHPRECISION
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1951 "hp"
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1952 #else
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1953 "lp"
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1954 #endif
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1955 );
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1956 f = fopen(buf, "w");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1957 if (!f)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1958 return;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1959 files[fnum] = f;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1960 }
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1961
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1962 if (fnum == 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1963 static int pos = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1964 printf("pos=%d\n", pos);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1965 for(i=0;i<n;i++) {
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1966 printf(" %0.4f", (double)tab[i] / FRAC_ONE);
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1967 if ((i % 18) == 17)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1968 printf("\n");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1969 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1970 pos += n;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1971 }
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1972 for(i=0;i<n;i++) {
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1973 /* normalize to 23 frac bits */
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1974 v = tab[i] << (23 - FRAC_BITS);
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1975 fwrite(&v, 1, sizeof(INT32), f);
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
1976 }
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1977 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1978 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1979
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1980
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1981 /* main layer3 decoding function */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1982 static int mp_decode_layer3(MPADecodeContext *s)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1983 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1984 int nb_granules, main_data_begin, private_bits;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1985 int gr, ch, blocksplit_flag, i, j, k, n, bits_pos, bits_left;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1986 GranuleDef granules[2][2], *g;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1987 INT16 exponents[576];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1988
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1989 /* read side info */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1990 if (s->lsf) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1991 main_data_begin = get_bits(&s->gb, 8);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1992 if (s->nb_channels == 2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1993 private_bits = get_bits(&s->gb, 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1994 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1995 private_bits = get_bits(&s->gb, 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1996 nb_granules = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1997 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1998 main_data_begin = get_bits(&s->gb, 9);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
1999 if (s->nb_channels == 2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2000 private_bits = get_bits(&s->gb, 3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2001 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2002 private_bits = get_bits(&s->gb, 5);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2003 nb_granules = 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2004 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2005 granules[ch][0].scfsi = 0; /* all scale factors are transmitted */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2006 granules[ch][1].scfsi = get_bits(&s->gb, 4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2007 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2008 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2009
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2010 for(gr=0;gr<nb_granules;gr++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2011 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2012 dprintf("gr=%d ch=%d: side_info\n", gr, ch);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2013 g = &granules[ch][gr];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2014 g->part2_3_length = get_bits(&s->gb, 12);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2015 g->big_values = get_bits(&s->gb, 9);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2016 g->global_gain = get_bits(&s->gb, 8);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2017 /* if MS stereo only is selected, we precompute the
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2018 1/sqrt(2) renormalization factor */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2019 if ((s->mode_ext & (MODE_EXT_MS_STEREO | MODE_EXT_I_STEREO)) ==
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2020 MODE_EXT_MS_STEREO)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2021 g->global_gain -= 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2022 if (s->lsf)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2023 g->scalefac_compress = get_bits(&s->gb, 9);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2024 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2025 g->scalefac_compress = get_bits(&s->gb, 4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2026 blocksplit_flag = get_bits(&s->gb, 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2027 if (blocksplit_flag) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2028 g->block_type = get_bits(&s->gb, 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2029 if (g->block_type == 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2030 return -1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2031 g->switch_point = get_bits(&s->gb, 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2032 for(i=0;i<2;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2033 g->table_select[i] = get_bits(&s->gb, 5);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2034 for(i=0;i<3;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2035 g->subblock_gain[i] = get_bits(&s->gb, 3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2036 /* compute huffman coded region sizes */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2037 if (g->block_type == 2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2038 g->region_size[0] = (36 / 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2039 else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2040 if (s->sample_rate_index <= 2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2041 g->region_size[0] = (36 / 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2042 else if (s->sample_rate_index != 8)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2043 g->region_size[0] = (54 / 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2044 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2045 g->region_size[0] = (108 / 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2046 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2047 g->region_size[1] = (576 / 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2048 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2049 int region_address1, region_address2, l;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2050 g->block_type = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2051 g->switch_point = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2052 for(i=0;i<3;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2053 g->table_select[i] = get_bits(&s->gb, 5);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2054 /* compute huffman coded region sizes */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2055 region_address1 = get_bits(&s->gb, 4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2056 region_address2 = get_bits(&s->gb, 3);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2057 dprintf("region1=%d region2=%d\n",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2058 region_address1, region_address2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2059 g->region_size[0] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2060 band_index_long[s->sample_rate_index][region_address1 + 1] >> 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2061 l = region_address1 + region_address2 + 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2062 /* should not overflow */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2063 if (l > 22)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2064 l = 22;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2065 g->region_size[1] =
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2066 band_index_long[s->sample_rate_index][l] >> 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2067 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2068 /* convert region offsets to region sizes and truncate
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2069 size to big_values */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2070 g->region_size[2] = (576 / 2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2071 j = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2072 for(i=0;i<3;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2073 k = g->region_size[i];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2074 if (k > g->big_values)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2075 k = g->big_values;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2076 g->region_size[i] = k - j;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2077 j = k;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2078 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2079
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2080 /* compute band indexes */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2081 if (g->block_type == 2) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2082 if (g->switch_point) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2083 /* if switched mode, we handle the 36 first samples as
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2084 long blocks. For 8000Hz, we handle the 48 first
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2085 exponents as long blocks (XXX: check this!) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2086 if (s->sample_rate_index <= 2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2087 g->long_end = 8;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2088 else if (s->sample_rate_index != 8)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2089 g->long_end = 6;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2090 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2091 g->long_end = 4; /* 8000 Hz */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2092
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2093 if (s->sample_rate_index != 8)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2094 g->short_start = 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2095 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2096 g->short_start = 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2097 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2098 g->long_end = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2099 g->short_start = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2100 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2101 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2102 g->short_start = 13;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2103 g->long_end = 22;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2104 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2105
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2106 g->preflag = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2107 if (!s->lsf)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2108 g->preflag = get_bits(&s->gb, 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2109 g->scalefac_scale = get_bits(&s->gb, 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2110 g->count1table_select = get_bits(&s->gb, 1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2111 dprintf("block_type=%d switch_point=%d\n",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2112 g->block_type, g->switch_point);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2113 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2114 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2115
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2116 /* now we get bits from the main_data_begin offset */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2117 dprintf("seekback: %d\n", main_data_begin);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2118 seek_to_maindata(s, main_data_begin);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2119
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2120 for(gr=0;gr<nb_granules;gr++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2121 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2122 g = &granules[ch][gr];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2123
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2124 bits_pos = get_bits_count(&s->gb);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2125
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2126 if (!s->lsf) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2127 UINT8 *sc;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2128 int slen, slen1, slen2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2129
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2130 /* MPEG1 scale factors */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2131 slen1 = slen_table[0][g->scalefac_compress];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2132 slen2 = slen_table[1][g->scalefac_compress];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2133 dprintf("slen1=%d slen2=%d\n", slen1, slen2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2134 if (g->block_type == 2) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2135 n = g->switch_point ? 17 : 18;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2136 j = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2137 for(i=0;i<n;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2138 g->scale_factors[j++] = get_bitsz(&s->gb, slen1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2139 for(i=0;i<18;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2140 g->scale_factors[j++] = get_bitsz(&s->gb, slen2);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2141 for(i=0;i<3;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2142 g->scale_factors[j++] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2143 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2144 sc = granules[ch][0].scale_factors;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2145 j = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2146 for(k=0;k<4;k++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2147 n = (k == 0 ? 6 : 5);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2148 if ((g->scfsi & (0x8 >> k)) == 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2149 slen = (k < 2) ? slen1 : slen2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2150 for(i=0;i<n;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2151 g->scale_factors[j++] = get_bitsz(&s->gb, slen);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2152 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2153 /* simply copy from last granule */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2154 for(i=0;i<n;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2155 g->scale_factors[j] = sc[j];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2156 j++;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2157 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2158 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2159 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2160 g->scale_factors[j++] = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2161 }
404
29dc52c127c6 fixed one overflow problem
glantau
parents: 392
diff changeset
2162 #if defined(DEBUG)
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2163 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2164 printf("scfsi=%x gr=%d ch=%d scale_factors:\n",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2165 g->scfsi, gr, ch);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2166 for(i=0;i<j;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2167 printf(" %d", g->scale_factors[i]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2168 printf("\n");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2169 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2170 #endif
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2171 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2172 int tindex, tindex2, slen[4], sl, sf;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2173
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2174 /* LSF scale factors */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2175 if (g->block_type == 2) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2176 tindex = g->switch_point ? 2 : 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2177 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2178 tindex = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2179 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2180 sf = g->scalefac_compress;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2181 if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2182 /* intensity stereo case */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2183 sf >>= 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2184 if (sf < 180) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2185 lsf_sf_expand(slen, sf, 6, 6, 0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2186 tindex2 = 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2187 } else if (sf < 244) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2188 lsf_sf_expand(slen, sf - 180, 4, 4, 0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2189 tindex2 = 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2190 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2191 lsf_sf_expand(slen, sf - 244, 3, 0, 0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2192 tindex2 = 5;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2193 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2194 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2195 /* normal case */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2196 if (sf < 400) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2197 lsf_sf_expand(slen, sf, 5, 4, 4);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2198 tindex2 = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2199 } else if (sf < 500) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2200 lsf_sf_expand(slen, sf - 400, 5, 4, 0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2201 tindex2 = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2202 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2203 lsf_sf_expand(slen, sf - 500, 3, 0, 0);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2204 tindex2 = 2;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2205 g->preflag = 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2206 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2207 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2208
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2209 j = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2210 for(k=0;k<4;k++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2211 n = lsf_nsf_table[tindex2][tindex][k];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2212 sl = slen[k];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2213 for(i=0;i<n;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2214 g->scale_factors[j++] = get_bitsz(&s->gb, sl);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2215 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2216 /* XXX: should compute exact size */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2217 for(;j<40;j++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2218 g->scale_factors[j] = 0;
404
29dc52c127c6 fixed one overflow problem
glantau
parents: 392
diff changeset
2219 #if defined(DEBUG)
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2220 {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2221 printf("gr=%d ch=%d scale_factors:\n",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2222 gr, ch);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2223 for(i=0;i<40;i++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2224 printf(" %d", g->scale_factors[i]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2225 printf("\n");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2226 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2227 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2228 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2229
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2230 exponents_from_scale_factors(s, g, exponents);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2231
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2232 /* read Huffman coded residue */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2233 if (huffman_decode(s, g, exponents,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2234 bits_pos + g->part2_3_length) < 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2235 return -1;
404
29dc52c127c6 fixed one overflow problem
glantau
parents: 392
diff changeset
2236 #if defined(DEBUG)
29dc52c127c6 fixed one overflow problem
glantau
parents: 392
diff changeset
2237 sample_dump(0, g->sb_hybrid, 576);
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2238 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2239
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2240 /* skip extension bits */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2241 bits_left = g->part2_3_length - (get_bits_count(&s->gb) - bits_pos);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2242 if (bits_left < 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2243 dprintf("bits_left=%d\n", bits_left);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2244 return -1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2245 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2246 while (bits_left >= 16) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2247 skip_bits(&s->gb, 16);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2248 bits_left -= 16;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2249 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2250 if (bits_left > 0)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2251 skip_bits(&s->gb, bits_left);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2252 } /* ch */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2253
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2254 if (s->nb_channels == 2)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2255 compute_stereo(s, &granules[0][gr], &granules[1][gr]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2256
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2257 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2258 g = &granules[ch][gr];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2259
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2260 reorder_block(s, g);
404
29dc52c127c6 fixed one overflow problem
glantau
parents: 392
diff changeset
2261 #if defined(DEBUG)
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2262 sample_dump(0, g->sb_hybrid, 576);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2263 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2264 compute_antialias(s, g);
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
2265 #if defined(DEBUG)
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2266 sample_dump(1, g->sb_hybrid, 576);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2267 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2268 compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]);
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
2269 #if defined(DEBUG)
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2270 sample_dump(2, &s->sb_samples[ch][18 * gr][0], 576);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2271 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2272 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2273 } /* gr */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2274 return nb_granules * 18;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2275 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
2276
986e461dc072 Initial revision
glantau
parents:
diff changeset
2277 static int mp_decode_frame(MPADecodeContext *s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2278 short *samples)
986e461dc072 Initial revision
glantau
parents:
diff changeset
2279 {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2280 int i, nb_frames, ch;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2281 short *samples_ptr;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2282
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2283 init_get_bits(&s->gb, s->inbuf + HEADER_SIZE,
1025
1f9afd8b9131 GetBitContext.size is allways multiplied by 8 -> use size_in_bits to avoid useless *8 in a few inner loops
michaelni
parents: 1014
diff changeset
2284 (s->inbuf_ptr - s->inbuf - HEADER_SIZE)*8);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2285
986e461dc072 Initial revision
glantau
parents:
diff changeset
2286 /* skip error protection field */
986e461dc072 Initial revision
glantau
parents:
diff changeset
2287 if (s->error_protection)
986e461dc072 Initial revision
glantau
parents:
diff changeset
2288 get_bits(&s->gb, 16);
986e461dc072 Initial revision
glantau
parents:
diff changeset
2289
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2290 dprintf("frame %d:\n", s->frame_count);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2291 switch(s->layer) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
2292 case 1:
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2293 nb_frames = mp_decode_layer1(s);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2294 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2295 case 2:
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2296 nb_frames = mp_decode_layer2(s);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2297 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2298 case 3:
986e461dc072 Initial revision
glantau
parents:
diff changeset
2299 default:
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2300 nb_frames = mp_decode_layer3(s);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2301 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2302 }
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2303 #if defined(DEBUG)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2304 for(i=0;i<nb_frames;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2305 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2306 int j;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2307 printf("%d-%d:", i, ch);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2308 for(j=0;j<SBLIMIT;j++)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2309 printf(" %0.6f", (double)s->sb_samples[ch][i][j] / FRAC_ONE);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2310 printf("\n");
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2311 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2312 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2313 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2314 /* apply the synthesis filter */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2315 for(ch=0;ch<s->nb_channels;ch++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2316 samples_ptr = samples + ch;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2317 for(i=0;i<nb_frames;i++) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2318 synth_filter(s, ch, samples_ptr, s->nb_channels,
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2319 s->sb_samples[ch][i]);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2320 samples_ptr += 32 * s->nb_channels;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2321 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2322 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2323 #ifdef DEBUG
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2324 s->frame_count++;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2325 #endif
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2326 return nb_frames * 32 * sizeof(short) * s->nb_channels;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2327 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
2328
986e461dc072 Initial revision
glantau
parents:
diff changeset
2329 static int decode_frame(AVCodecContext * avctx,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2330 void *data, int *data_size,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2331 UINT8 * buf, int buf_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
2332 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
2333 MPADecodeContext *s = avctx->priv_data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2334 UINT32 header;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2335 UINT8 *buf_ptr;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2336 int len, out_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2337 short *out_samples = data;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2338
986e461dc072 Initial revision
glantau
parents:
diff changeset
2339 *data_size = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2340 buf_ptr = buf;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2341 while (buf_size > 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
2342 len = s->inbuf_ptr - s->inbuf;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2343 if (s->frame_size == 0) {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2344 /* special case for next header for first frame in free
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2345 format case (XXX: find a simpler method) */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2346 if (s->free_format_next_header != 0) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2347 s->inbuf[0] = s->free_format_next_header >> 24;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2348 s->inbuf[1] = s->free_format_next_header >> 16;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2349 s->inbuf[2] = s->free_format_next_header >> 8;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2350 s->inbuf[3] = s->free_format_next_header;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2351 s->inbuf_ptr = s->inbuf + 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2352 s->free_format_next_header = 0;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2353 goto got_header;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2354 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2355 /* no header seen : find one. We need at least HEADER_SIZE
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2356 bytes to parse it */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2357 len = HEADER_SIZE - len;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2358 if (len > buf_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
2359 len = buf_size;
143
35e3ced6cfd9 * fixed decoding busy loop
kabi
parents: 125
diff changeset
2360 if (len > 0) {
125
42a36eb08c8d * and finaly avoid deadlock at the end of audio stream
kabi
parents: 124
diff changeset
2361 memcpy(s->inbuf_ptr, buf_ptr, len);
42a36eb08c8d * and finaly avoid deadlock at the end of audio stream
kabi
parents: 124
diff changeset
2362 buf_ptr += len;
42a36eb08c8d * and finaly avoid deadlock at the end of audio stream
kabi
parents: 124
diff changeset
2363 buf_size -= len;
123
3073d4ea6ee5 * simple fix to avoid memcpy with len < 0
kabi
parents: 82
diff changeset
2364 s->inbuf_ptr += len;
3073d4ea6ee5 * simple fix to avoid memcpy with len < 0
kabi
parents: 82
diff changeset
2365 }
3073d4ea6ee5 * simple fix to avoid memcpy with len < 0
kabi
parents: 82
diff changeset
2366 if ((s->inbuf_ptr - s->inbuf) >= HEADER_SIZE) {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2367 got_header:
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2368 header = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
986e461dc072 Initial revision
glantau
parents:
diff changeset
2369 (s->inbuf[2] << 8) | s->inbuf[3];
143
35e3ced6cfd9 * fixed decoding busy loop
kabi
parents: 125
diff changeset
2370
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2371 if (check_header(header) < 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
2372 /* no sync found : move by one byte (inefficient, but simple!) */
125
42a36eb08c8d * and finaly avoid deadlock at the end of audio stream
kabi
parents: 124
diff changeset
2373 memcpy(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2374 s->inbuf_ptr--;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2375 dprintf("skip %x\n", header);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2376 /* reset free format frame size to give a chance
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2377 to get a new bitrate */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2378 s->free_format_frame_size = 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2379 } else {
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2380 if (decode_header(s, header) == 1) {
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
2381 /* free format: prepare to compute frame size */
125
42a36eb08c8d * and finaly avoid deadlock at the end of audio stream
kabi
parents: 124
diff changeset
2382 s->frame_size = -1;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2383 }
449
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
2384 /* update codec info */
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
2385 avctx->sample_rate = s->sample_rate;
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
2386 avctx->channels = s->nb_channels;
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
2387 avctx->bit_rate = s->bit_rate;
7b2f23b5dcdd fixed layer1/2 overflow if very loud sound - fixed broken free format decoding to pass all mpeg audio standard decoding tests (please avoid patching the parser without having all test streams available - contact me if necessary)
bellard
parents: 440
diff changeset
2388 avctx->frame_size = s->frame_size;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2389 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
2390 }
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2391 } else if (s->frame_size == -1) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2392 /* free format : find next sync to compute frame size */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2393 len = MPA_MAX_CODED_FRAME_SIZE - len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2394 if (len > buf_size)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2395 len = buf_size;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2396 if (len == 0) {
602
d8d23aae4ac3 * resync without endless loop
kabi
parents: 520
diff changeset
2397 /* frame too long: resync */
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2398 s->frame_size = 0;
602
d8d23aae4ac3 * resync without endless loop
kabi
parents: 520
diff changeset
2399 memcpy(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
d8d23aae4ac3 * resync without endless loop
kabi
parents: 520
diff changeset
2400 s->inbuf_ptr--;
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2401 } else {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2402 UINT8 *p, *pend;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2403 UINT32 header1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2404 int padding;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2405
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2406 memcpy(s->inbuf_ptr, buf_ptr, len);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2407 /* check for header */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2408 p = s->inbuf_ptr - 3;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2409 pend = s->inbuf_ptr + len - 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2410 while (p <= pend) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2411 header = (p[0] << 24) | (p[1] << 16) |
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2412 (p[2] << 8) | p[3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2413 header1 = (s->inbuf[0] << 24) | (s->inbuf[1] << 16) |
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2414 (s->inbuf[2] << 8) | s->inbuf[3];
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2415 /* check with high probability that we have a
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2416 valid header */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2417 if ((header & SAME_HEADER_MASK) ==
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2418 (header1 & SAME_HEADER_MASK)) {
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2419 /* header found: update pointers */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2420 len = (p + 4) - s->inbuf_ptr;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2421 buf_ptr += len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2422 buf_size -= len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2423 s->inbuf_ptr = p;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2424 /* compute frame size */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2425 s->free_format_next_header = header;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2426 s->free_format_frame_size = s->inbuf_ptr - s->inbuf;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2427 padding = (header1 >> 9) & 1;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2428 if (s->layer == 1)
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2429 s->free_format_frame_size -= padding * 4;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2430 else
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2431 s->free_format_frame_size -= padding;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2432 dprintf("free frame size=%d padding=%d\n",
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2433 s->free_format_frame_size, padding);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2434 decode_header(s, header1);
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2435 goto next_data;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2436 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2437 p++;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2438 }
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2439 /* not found: simply increase pointers */
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2440 buf_ptr += len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2441 s->inbuf_ptr += len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2442 buf_size -= len;
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2443 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2444 } else if (len < s->frame_size) {
124
036ec148fb18 * fixes to avoid crash when broken mp3 header is found
kabi
parents: 123
diff changeset
2445 if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
036ec148fb18 * fixes to avoid crash when broken mp3 header is found
kabi
parents: 123
diff changeset
2446 s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2447 len = s->frame_size - len;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2448 if (len > buf_size)
986e461dc072 Initial revision
glantau
parents:
diff changeset
2449 len = buf_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2450 memcpy(s->inbuf_ptr, buf_ptr, len);
986e461dc072 Initial revision
glantau
parents:
diff changeset
2451 buf_ptr += len;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2452 s->inbuf_ptr += len;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2453 buf_size -= len;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2454 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
2455 out_size = mp_decode_frame(s, out_samples);
986e461dc072 Initial revision
glantau
parents:
diff changeset
2456 s->inbuf_ptr = s->inbuf;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2457 s->frame_size = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2458 *data_size = out_size;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2459 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2460 }
82
46ee548e47e4 added completely new mpeg audio decoder (integer only, free format support, lsf/mpeg25 support, high/low precision support, simpler code)
glantau
parents: 0
diff changeset
2461 next_data:
468
1e23eae32087 Minor warning cleanup.
mellum
parents: 449
diff changeset
2462 ;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2463 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
2464 return buf_ptr - buf;
986e461dc072 Initial revision
glantau
parents:
diff changeset
2465 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
2466
322
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2467 AVCodec mp2_decoder =
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2468 {
322
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2469 "mp2",
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2470 CODEC_TYPE_AUDIO,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2471 CODEC_ID_MP2,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2472 sizeof(MPADecodeContext),
986e461dc072 Initial revision
glantau
parents:
diff changeset
2473 decode_init,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2474 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2475 NULL,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2476 decode_frame,
986e461dc072 Initial revision
glantau
parents:
diff changeset
2477 };
322
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2478
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2479 AVCodec mp3_decoder =
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2480 {
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2481 "mp3",
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2482 CODEC_TYPE_AUDIO,
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2483 CODEC_ID_MP3LAME,
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2484 sizeof(MPADecodeContext),
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2485 decode_init,
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2486 NULL,
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2487 NULL,
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2488 decode_frame,
ce35fd27bbb0 - Versions defined for libav/libavcodec.
pulento
parents: 313
diff changeset
2489 };
440
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2490
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2491 #undef C1
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2492 #undef C2
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2493 #undef C3
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2494 #undef C4
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2495 #undef C5
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2496 #undef C6
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2497 #undef C7
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2498 #undef C8
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2499 #undef FRAC_BITS
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 431
diff changeset
2500 #undef HEADER_SIZE