vo_tag: fix RGB with alpha output on little-endian
[mplayer/glamo.git] / mp3lib / layer1.c
bloba4be24677aa6dad0f8c351db3d67e769db369e1f
1 /*
2 * Mpeg Layer-1 audio decoder
3 * --------------------------
4 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
5 * near unoptimzed ...
7 * may have a few bugs after last optimization ...
9 */
12 * Modified for use with MPlayer, for details see the changelog at
13 * http://svn.mplayerhq.hu/mplayer/trunk/
14 * $Id$
16 * The above-mentioned README file has the following to say about licensing:
18 * COPYING: you may use this source under LGPL terms!
21 #include "mpg123.h"
23 static void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
25 unsigned int *ba=balloc;
26 unsigned int *sca = (unsigned int *) scale_index;
28 if(fr->stereo == 2) {
29 int i;
30 int jsbound = fr->jsbound;
31 for (i=0;i<jsbound;i++) {
32 *ba++ = getbits(4);
33 *ba++ = getbits(4);
35 for (i=jsbound;i<SBLIMIT;i++)
36 *ba++ = getbits(4);
38 ba = balloc;
40 for (i=0;i<jsbound;i++) {
41 if ((*ba++))
42 *sca++ = getbits(6);
43 if ((*ba++))
44 *sca++ = getbits(6);
46 for (i=jsbound;i<SBLIMIT;i++)
47 if ((*ba++)) {
48 *sca++ = getbits(6);
49 *sca++ = getbits(6);
52 else {
53 int i;
54 for (i=0;i<SBLIMIT;i++)
55 *ba++ = getbits(4);
56 ba = balloc;
57 for (i=0;i<SBLIMIT;i++)
58 if ((*ba++))
59 *sca++ = getbits(6);
63 static void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
64 unsigned int scale_index[2][SBLIMIT],struct frame *fr)
66 int i,n;
67 int smpb[2*SBLIMIT]; /* values: 0-65535 */
68 int *sample;
69 register unsigned int *ba;
70 register unsigned int *sca = (unsigned int *) scale_index;
72 if(fr->stereo == 2) {
73 int jsbound = fr->jsbound;
74 register real *f0 = fraction[0];
75 register real *f1 = fraction[1];
76 ba = balloc;
77 for (sample=smpb,i=0;i<jsbound;i++) {
78 if ((n = *ba++))
79 *sample++ = getbits(n+1);
80 if ((n = *ba++))
81 *sample++ = getbits(n+1);
83 for (i=jsbound;i<SBLIMIT;i++)
84 if ((n = *ba++))
85 *sample++ = getbits(n+1);
87 ba = balloc;
88 for (sample=smpb,i=0;i<jsbound;i++) {
89 if((n=*ba++))
90 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
91 else
92 *f0++ = 0.0;
93 if((n=*ba++))
94 *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
95 else
96 *f1++ = 0.0;
98 for (i=jsbound;i<SBLIMIT;i++) {
99 if ((n=*ba++)) {
100 real samp = ( ((-1)<<n) + (*sample++) + 1);
101 *f0++ = samp * muls[n+1][*sca++];
102 *f1++ = samp * muls[n+1][*sca++];
104 else
105 *f0++ = *f1++ = 0.0;
107 for(i=fr->down_sample_sblimit;i<32;i++)
108 fraction[0][i] = fraction[1][i] = 0.0;
110 else {
111 register real *f0 = fraction[0];
112 ba = balloc;
113 for (sample=smpb,i=0;i<SBLIMIT;i++)
114 if ((n = *ba++))
115 *sample++ = getbits(n+1);
116 ba = balloc;
117 for (sample=smpb,i=0;i<SBLIMIT;i++) {
118 if((n=*ba++))
119 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
120 else
121 *f0++ = 0.0;
123 for(i=fr->down_sample_sblimit;i<32;i++)
124 fraction[0][i] = 0.0;
128 static int do_layer1(struct frame *fr,int single)
130 int clip=0;
131 int i,stereo = fr->stereo;
132 unsigned int balloc[2*SBLIMIT];
133 unsigned int scale_index[2][SBLIMIT];
134 DECLARE_ALIGNED(16, real, fraction[2][SBLIMIT]);
135 // int single = fr->single;
137 // printf("do_layer1(0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X )\n",
138 // wordpointer[0],wordpointer[1],wordpointer[2],wordpointer[3],wordpointer[4],wordpointer[5],wordpointer[6],wordpointer[7]);
140 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
141 (fr->mode_ext<<2)+4 : 32;
143 if(stereo == 1 || single == 3)
144 single = 0;
146 I_step_one(balloc,scale_index,fr);
148 for (i=0;i<SCALE_BLOCK;i++)
150 I_step_two(fraction,balloc,scale_index,fr);
152 if(single >= 0)
154 clip += (fr->synth_mono)( (real *) fraction[single],pcm_sample,&pcm_point);
156 else {
157 int p1 = pcm_point;
158 clip += (fr->synth)( (real *) fraction[0],0,pcm_sample,&p1);
159 clip += (fr->synth)( (real *) fraction[1],1,pcm_sample,&pcm_point);
164 return clip;