Mercurial > audlegacy-plugins
comparison src/mpg123/layer1.c @ 12:3da1b8942b8b trunk
[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author | nenolod |
---|---|
date | Mon, 18 Sep 2006 03:14:20 -0700 |
parents | src/Input/mpg123/layer1.c@13389e613d67 |
children | 914c96de3244 |
comparison
equal
deleted
inserted
replaced
11:cff1d04026ae | 12:3da1b8942b8b |
---|---|
1 /* | |
2 * Mpeg Layer-1 audio decoder | |
3 * -------------------------- | |
4 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README' | |
5 * near unoptimzed ... | |
6 * | |
7 * may have a few bugs after last optimization ... | |
8 * | |
9 */ | |
10 | |
11 #include "audacious/output.h" | |
12 #include "mpg123.h" | |
13 #include "getbits.h" | |
14 | |
15 void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr) | |
16 { | |
17 unsigned int *ba=balloc; | |
18 unsigned int *sca = (unsigned int *) scale_index; | |
19 | |
20 if(fr->stereo) { | |
21 int i; | |
22 int jsbound = fr->jsbound; | |
23 for (i=0;i<jsbound;i++) { | |
24 *ba++ = mpgdec_getbits(&bsi,4); | |
25 *ba++ = mpgdec_getbits(&bsi,4); | |
26 } | |
27 for (i=jsbound;i<SBLIMIT;i++) | |
28 *ba++ = mpgdec_getbits(&bsi,4); | |
29 | |
30 ba = balloc; | |
31 | |
32 for (i=0;i<jsbound;i++) { | |
33 if ((*ba++)) | |
34 *sca++ = mpgdec_getbits(&bsi,6); | |
35 if ((*ba++)) | |
36 *sca++ = mpgdec_getbits(&bsi,6); | |
37 } | |
38 for (i=jsbound;i<SBLIMIT;i++) | |
39 if ((*ba++)) { | |
40 *sca++ = mpgdec_getbits(&bsi,6); | |
41 *sca++ = mpgdec_getbits(&bsi,6); | |
42 } | |
43 } | |
44 else { | |
45 int i; | |
46 for (i=0;i<SBLIMIT;i++) | |
47 *ba++ = mpgdec_getbits(&bsi,4); | |
48 ba = balloc; | |
49 for (i=0;i<SBLIMIT;i++) | |
50 if ((*ba++)) | |
51 *sca++ = mpgdec_getbits(&bsi,6); | |
52 } | |
53 } | |
54 | |
55 void I_step_two(mpgdec_real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT], | |
56 unsigned int scale_index[2][SBLIMIT],struct frame *fr) | |
57 { | |
58 int i,n; | |
59 int smpb[2*SBLIMIT]; /* values: 0-65535 */ | |
60 int *sample; | |
61 register unsigned int *ba; | |
62 register unsigned int *sca = (unsigned int *) scale_index; | |
63 | |
64 if(fr->stereo) { | |
65 int jsbound = fr->jsbound; | |
66 register mpgdec_real *f0 = fraction[0]; | |
67 register mpgdec_real *f1 = fraction[1]; | |
68 ba = balloc; | |
69 for (sample=smpb,i=0;i<jsbound;i++) { | |
70 if ((n = *ba++)) | |
71 *sample++ = mpgdec_getbits(&bsi,n+1); | |
72 if ((n = *ba++)) | |
73 *sample++ = mpgdec_getbits(&bsi,n+1); | |
74 } | |
75 for (i=jsbound;i<SBLIMIT;i++) | |
76 if ((n = *ba++)) | |
77 *sample++ = mpgdec_getbits(&bsi,n+1); | |
78 | |
79 ba = balloc; | |
80 for (sample=smpb,i=0;i<jsbound;i++) { | |
81 if((n=*ba++)) | |
82 *f0++ = (mpgdec_real) ( ((-1)<<n) + (*sample++) + 1) * mpgdec_muls[n+1][*sca++]; | |
83 else | |
84 *f0++ = 0.0; | |
85 if((n=*ba++)) | |
86 *f1++ = (mpgdec_real) ( ((-1)<<n) + (*sample++) + 1) * mpgdec_muls[n+1][*sca++]; | |
87 else | |
88 *f1++ = 0.0; | |
89 } | |
90 for (i=jsbound;i<SBLIMIT;i++) { | |
91 if ((n=*ba++)) { | |
92 mpgdec_real samp = ( ((-1)<<n) + (*sample++) + 1); | |
93 *f0++ = samp * mpgdec_muls[n+1][*sca++]; | |
94 *f1++ = samp * mpgdec_muls[n+1][*sca++]; | |
95 } | |
96 else | |
97 *f0++ = *f1++ = 0.0; | |
98 } | |
99 for(i=fr->down_sample_sblimit;i<32;i++) | |
100 fraction[0][i] = fraction[1][i] = 0.0; | |
101 } | |
102 else { | |
103 register mpgdec_real *f0 = fraction[0]; | |
104 ba = balloc; | |
105 for (sample=smpb,i=0;i<SBLIMIT;i++) | |
106 if ((n = *ba++)) | |
107 *sample++ = mpgdec_getbits(&bsi,n+1); | |
108 ba = balloc; | |
109 for (sample=smpb,i=0;i<SBLIMIT;i++) { | |
110 if((n=*ba++)) | |
111 *f0++ = (mpgdec_real) ( ((-1)<<n) + (*sample++) + 1) * mpgdec_muls[n+1][*sca++]; | |
112 else | |
113 *f0++ = 0.0; | |
114 } | |
115 for(i=fr->down_sample_sblimit;i<32;i++) | |
116 fraction[0][i] = 0.0; | |
117 } | |
118 } | |
119 | |
120 int | |
121 mpgdec_do_layer1(struct frame *fr) | |
122 { | |
123 int i, stereo = fr->stereo; | |
124 unsigned int balloc[2 * SBLIMIT]; | |
125 unsigned int scale_index[2][SBLIMIT]; | |
126 mpgdec_real fraction[2][SBLIMIT]; | |
127 int single = fr->single; | |
128 | |
129 fr->jsbound = | |
130 (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext << 2) + 4 : 32; | |
131 | |
132 if (stereo == 1 || single == 3) | |
133 single = 0; | |
134 | |
135 I_step_one(balloc, scale_index, fr); | |
136 | |
137 for (i = 0; i < SCALE_BLOCK; i++) { | |
138 I_step_two(fraction, balloc, scale_index, fr); | |
139 | |
140 if (single >= 0) { | |
141 (fr->synth_mono) ((mpgdec_real *) fraction[single], mpgdec_pcm_sample, | |
142 &mpgdec_pcm_point); | |
143 } | |
144 else { | |
145 int p1 = mpgdec_pcm_point; | |
146 | |
147 (fr->synth) ((mpgdec_real *) fraction[0], 0, mpgdec_pcm_sample, &p1); | |
148 (fr->synth) ((mpgdec_real *) fraction[1], 1, mpgdec_pcm_sample, | |
149 &mpgdec_pcm_point); | |
150 } | |
151 #ifdef PSYCHO | |
152 psycho_process(mpgdec_pcm_sample, mpgdec_pcm_point, mpgdec_cfg.channels == 2 ? fr->stereo : 1); | |
153 #endif | |
154 if (mpgdec_info->output_audio && mpgdec_info->jump_to_time == -1) { | |
155 produce_audio(mpgdec_ip.output->written_time(), | |
156 mpgdec_cfg.resolution == | |
157 16 ? FMT_S16_NE : FMT_U8, | |
158 mpgdec_cfg.channels == | |
159 2 ? fr->stereo : 1, mpgdec_pcm_point, | |
160 mpgdec_pcm_sample, &mpgdec_info->going); | |
161 } | |
162 | |
163 mpgdec_pcm_point = 0; | |
164 } | |
165 | |
166 return 1; | |
167 } |