261
|
1 #include <stdio.h>
|
|
2 #include <string.h>
|
|
3 #include <signal.h>
|
|
4
|
|
5 #ifndef WIN32
|
|
6 #include <sys/signal.h>
|
|
7 #include <unistd.h>
|
|
8 #endif
|
|
9
|
|
10 #include <math.h>
|
|
11
|
|
12 #ifdef _WIN32
|
|
13 # undef WIN32
|
|
14 # define WIN32
|
|
15
|
|
16 # define M_PI 3.14159265358979323846
|
|
17 # define M_SQRT2 1.41421356237309504880
|
|
18 # define REAL_IS_FLOAT
|
|
19 # define NEW_DCT9
|
|
20
|
|
21 # define random rand
|
|
22 # define srandom srand
|
|
23
|
|
24 #endif
|
|
25
|
|
26 #ifdef REAL_IS_FLOAT
|
|
27 # define real float
|
|
28 #elif defined(REAL_IS_LONG_DOUBLE)
|
|
29 # define real long double
|
|
30 #else
|
|
31 # define real double
|
|
32 #endif
|
|
33
|
|
34 #ifdef __GNUC__
|
|
35 #define INLINE inline
|
|
36 #else
|
|
37 #define INLINE
|
|
38 #endif
|
|
39
|
|
40 /* AUDIOBUFSIZE = n*64 with n=1,2,3 ... */
|
|
41 #define AUDIOBUFSIZE 16384
|
|
42
|
|
43 #ifndef FALSE
|
|
44 #define FALSE 0
|
|
45 #endif
|
|
46 #ifndef FALSE
|
|
47 #define TRUE 1
|
|
48 #endif
|
|
49
|
|
50 #define SBLIMIT 32
|
|
51 #define SSLIMIT 18
|
|
52
|
|
53 #define SCALE_BLOCK 12
|
|
54
|
|
55
|
|
56 #define MPG_MD_STEREO 0
|
|
57 #define MPG_MD_JOINT_STEREO 1
|
|
58 #define MPG_MD_DUAL_CHANNEL 2
|
|
59 #define MPG_MD_MONO 3
|
|
60
|
|
61 #define MAXFRAMESIZE 1792
|
|
62
|
|
63
|
|
64 /* Pre Shift fo 16 to 8 bit converter table */
|
|
65 #define AUSHIFT (3)
|
|
66
|
|
67 struct frame {
|
|
68 int stereo;
|
|
69 int jsbound;
|
|
70 int single;
|
|
71 int lsf;
|
|
72 int mpeg25;
|
|
73 int header_change;
|
|
74 int lay;
|
|
75 int error_protection;
|
|
76 int bitrate_index;
|
|
77 int sampling_frequency;
|
|
78 int padding;
|
|
79 int extension;
|
|
80 int mode;
|
|
81 int mode_ext;
|
|
82 int copyright;
|
|
83 int original;
|
|
84 int emphasis;
|
|
85 int framesize; /* computed framesize */
|
|
86
|
|
87 /* layer2 stuff */
|
|
88 int II_sblimit;
|
|
89 void *alloc;
|
|
90 };
|
|
91
|
|
92 struct parameter {
|
|
93 int quiet; /* shut up! */
|
|
94 int tryresync; /* resync stream after error */
|
|
95 int verbose; /* verbose level */
|
|
96 int checkrange;
|
|
97 };
|
|
98
|
|
99 extern unsigned int get1bit(void);
|
|
100 extern unsigned int getbits(int);
|
|
101 extern unsigned int getbits_fast(int);
|
|
102 extern int set_pointer(long);
|
|
103
|
|
104 extern unsigned char *wordpointer;
|
|
105 extern int bitindex;
|
|
106
|
|
107 extern void make_decode_tables(long scaleval);
|
|
108 extern int do_layer3(struct frame *fr,unsigned char *,int *);
|
|
109 extern int do_layer2(struct frame *fr,unsigned char *,int *);
|
|
110 extern int do_layer1(struct frame *fr,unsigned char *,int *);
|
|
111 extern int decode_header(struct frame *fr,unsigned long newhead);
|
|
112
|
|
113
|
|
114
|
|
115 struct gr_info_s {
|
|
116 int scfsi;
|
|
117 unsigned part2_3_length;
|
|
118 unsigned big_values;
|
|
119 unsigned scalefac_compress;
|
|
120 unsigned block_type;
|
|
121 unsigned mixed_block_flag;
|
|
122 unsigned table_select[3];
|
|
123 unsigned subblock_gain[3];
|
|
124 unsigned maxband[3];
|
|
125 unsigned maxbandl;
|
|
126 unsigned maxb;
|
|
127 unsigned region1start;
|
|
128 unsigned region2start;
|
|
129 unsigned preflag;
|
|
130 unsigned scalefac_scale;
|
|
131 unsigned count1table_select;
|
|
132 real *full_gain[3];
|
|
133 real *pow2gain;
|
|
134 };
|
|
135
|
|
136 struct III_sideinfo
|
|
137 {
|
|
138 unsigned main_data_begin;
|
|
139 unsigned private_bits;
|
|
140 struct {
|
|
141 struct gr_info_s gr[2];
|
|
142 } ch[2];
|
|
143 };
|
|
144
|
|
145 extern int synth_1to1 (real *,int,unsigned char *,int *);
|
|
146 extern int synth_1to1_8bit (real *,int,unsigned char *,int *);
|
|
147 extern int synth_1to1_mono (real *,unsigned char *,int *);
|
|
148 extern int synth_1to1_mono2stereo (real *,unsigned char *,int *);
|
|
149 extern int synth_1to1_8bit_mono (real *,unsigned char *,int *);
|
|
150 extern int synth_1to1_8bit_mono2stereo (real *,unsigned char *,int *);
|
|
151
|
|
152 extern int synth_2to1 (real *,int,unsigned char *,int *);
|
|
153 extern int synth_2to1_8bit (real *,int,unsigned char *,int *);
|
|
154 extern int synth_2to1_mono (real *,unsigned char *,int *);
|
|
155 extern int synth_2to1_mono2stereo (real *,unsigned char *,int *);
|
|
156 extern int synth_2to1_8bit_mono (real *,unsigned char *,int *);
|
|
157 extern int synth_2to1_8bit_mono2stereo (real *,unsigned char *,int *);
|
|
158
|
|
159 extern int synth_4to1 (real *,int,unsigned char *,int *);
|
|
160 extern int synth_4to1_8bit (real *,int,unsigned char *,int *);
|
|
161 extern int synth_4to1_mono (real *,unsigned char *,int *);
|
|
162 extern int synth_4to1_mono2stereo (real *,unsigned char *,int *);
|
|
163 extern int synth_4to1_8bit_mono (real *,unsigned char *,int *);
|
|
164 extern int synth_4to1_8bit_mono2stereo (real *,unsigned char *,int *);
|
|
165
|
|
166 extern int synth_ntom (real *,int,unsigned char *,int *);
|
|
167 extern int synth_ntom_8bit (real *,int,unsigned char *,int *);
|
|
168 extern int synth_ntom_mono (real *,unsigned char *,int *);
|
|
169 extern int synth_ntom_mono2stereo (real *,unsigned char *,int *);
|
|
170 extern int synth_ntom_8bit_mono (real *,unsigned char *,int *);
|
|
171 extern int synth_ntom_8bit_mono2stereo (real *,unsigned char *,int *);
|
|
172
|
|
173 extern void rewindNbits(int bits);
|
|
174 extern int hsstell(void);
|
|
175 extern int get_songlen(struct frame *fr,int no);
|
|
176
|
|
177 extern void init_layer3(int);
|
|
178 extern void init_layer2(void);
|
|
179 extern void make_decode_tables(long scale);
|
|
180 extern void make_conv16to8_table(int);
|
|
181 extern void dct64(real *,real *,real *);
|
|
182
|
|
183 extern void synth_ntom_set_step(long,long);
|
|
184
|
|
185 extern unsigned char *conv16to8;
|
|
186 extern long freqs[9];
|
|
187 extern real muls[27][64];
|
|
188 extern real decwin[512+32];
|
|
189 extern real *pnts[5];
|
|
190
|
|
191 extern struct parameter param;
|
|
192
|
|
193
|