quartz: Fix support for files with multiple odml indexes.
[wine/wine64.git] / dlls / winemp3.acm / layer1.c
blob16bc55cb649d86773aa2e940fbf34a3dda1f78a5
1 /*
2 * Mpeg Layer-1 audio decoder
3 * --------------------------
4 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
5 * This file has been copied from mpglib.
6 * near unoptimzed ...
8 * may have a few bugs after last optimization ...
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "mpg123.h"
27 static void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
29 unsigned int *ba=balloc;
30 unsigned int *sca = (unsigned int *) scale_index;
32 if(fr->stereo) {
33 int i;
34 int jsbound = fr->jsbound;
35 for (i=0;i<jsbound;i++) {
36 *ba++ = getbits(4);
37 *ba++ = getbits(4);
39 for (i=jsbound;i<SBLIMIT;i++)
40 *ba++ = getbits(4);
42 ba = balloc;
44 for (i=0;i<jsbound;i++) {
45 if ((*ba++))
46 *sca++ = getbits(6);
47 if ((*ba++))
48 *sca++ = getbits(6);
50 for (i=jsbound;i<SBLIMIT;i++)
51 if ((*ba++)) {
52 *sca++ = getbits(6);
53 *sca++ = getbits(6);
56 else {
57 int i;
58 for (i=0;i<SBLIMIT;i++)
59 *ba++ = getbits(4);
60 ba = balloc;
61 for (i=0;i<SBLIMIT;i++)
62 if ((*ba++))
63 *sca++ = getbits(6);
67 static void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
68 unsigned int scale_index[2][SBLIMIT],struct frame *fr)
70 int i,n;
71 int smpb[2*SBLIMIT]; /* values: 0-65535 */
72 int *sample;
73 register unsigned int *ba;
74 register unsigned int *sca = (unsigned int *) scale_index;
76 if(fr->stereo) {
77 int jsbound = fr->jsbound;
78 register real *f0 = fraction[0];
79 register real *f1 = fraction[1];
80 ba = balloc;
81 for (sample=smpb,i=0;i<jsbound;i++) {
82 if ((n = *ba++))
83 *sample++ = getbits(n+1);
84 if ((n = *ba++))
85 *sample++ = getbits(n+1);
87 for (i=jsbound;i<SBLIMIT;i++)
88 if ((n = *ba++))
89 *sample++ = getbits(n+1);
91 ba = balloc;
92 for (sample=smpb,i=0;i<jsbound;i++) {
93 if((n=*ba++))
94 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
95 else
96 *f0++ = 0.0;
97 if((n=*ba++))
98 *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
99 else
100 *f1++ = 0.0;
102 for (i=jsbound;i<SBLIMIT;i++) {
103 if ((n=*ba++)) {
104 real samp = ( ((-1)<<n) + (*sample++) + 1);
105 *f0++ = samp * muls[n+1][*sca++];
106 *f1++ = samp * muls[n+1][*sca++];
108 else
109 *f0++ = *f1++ = 0.0;
112 else {
113 register real *f0 = fraction[0];
114 ba = balloc;
115 for (sample=smpb,i=0;i<SBLIMIT;i++)
116 if ((n = *ba++))
117 *sample++ = getbits(n+1);
118 ba = balloc;
119 for (sample=smpb,i=0;i<SBLIMIT;i++) {
120 if((n=*ba++))
121 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
122 else
123 *f0++ = 0.0;
128 int do_layer1(struct frame *fr,unsigned char *pcm_sample,int *pcm_point)
130 int clip=0;
131 int i,stereo = fr->stereo;
132 unsigned int balloc[2*SBLIMIT];
133 unsigned int scale_index[2][SBLIMIT];
134 real fraction[2][SBLIMIT];
135 int single = fr->single;
137 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32;
139 if(stereo == 1 || single == 3)
140 single = 0;
142 I_step_one(balloc,scale_index,fr);
144 for (i=0;i<SCALE_BLOCK;i++)
146 I_step_two(fraction,balloc,scale_index,fr);
148 if(single >= 0) {
149 clip += synth_1to1_mono(fr->mp,(real*)fraction[single],pcm_sample,pcm_point);
151 else {
152 int p1 = *pcm_point;
153 clip += synth_1to1(fr->mp,(real*)fraction[0],0,pcm_sample,&p1);
154 clip += synth_1to1(fr->mp,(real*)fraction[1],1,pcm_sample,pcm_point);
158 return clip;