annotate Plugins/Input/mpg123/layer2.c @ 767:3ade061e7364 trunk

[svn] - typo
author nenolod
date Wed, 01 Mar 2006 10:05:28 -0800
parents e39735f0b2f7
children 0f294f2b0a9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
1 /*
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
2 * Mpeg Layer-2 audio decoder
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 * --------------------------
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
8 #include "mpg123.h"
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 #include "audacious/output.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 #include "l2tables.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 #include "getbits.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
13 #include <math.h>
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
14
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
15 static int grp_3tab[32 * 3] = { 0, }; /* used: 27 */
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
16 static int grp_5tab[128 * 3] = { 0, }; /* used: 125 */
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
17 static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
19 real mpg123_muls[27][64]; /* also used by layer 1 */
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
21 void
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
22 mpg123_init_layer2 (gboolean mmx)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 {
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
24 static double mulmul[27] = {
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
25 0.0, -2.0 / 3.0, 2.0 / 3.0, 2.0 / 7.0, 2.0 / 15.0,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
26 2.0 / 31.0, 2.0 / 63.0, 2.0 / 127.0, 2.0 / 255.0,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
27 2.0 / 511.0, 2.0 / 1023.0, 2.0 / 2047.0, 2.0 / 4095.0,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
28 2.0 / 8191.0, 2.0 / 16383.0, 2.0 / 32767.0, 2.0 / 65535.0,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
29 -4.0 / 5.0, -2.0 / 5.0, 2.0 / 5.0, 4.0 / 5.0, -8.0 / 9.0,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
30 -4.0 / 9.0, -2.0 / 9.0, 2.0 / 9.0, 4.0 / 9.0, 8.0 / 9.0
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
31 };
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
32 static int base[3][9] = {
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
33 {1, 0, 2,},
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
34 {17, 18, 0, 19, 20,},
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
35 {21, 1, 22, 23, 0, 24, 25, 2, 26}
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
36 };
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
37 int i, j, k, l, len;
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
38 real *table;
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
39 static int tablen[3] = { 3, 5, 9 };
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
40 static int *itable, *tables[3] = { grp_3tab, grp_5tab, grp_9tab };
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
42 for (i = 0; i < 3; i++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
43 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
44 itable = tables[i];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
45 len = tablen[i];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
46 for (j = 0; j < len; j++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
47 for (k = 0; k < len; k++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
48 for (l = 0; l < len; l++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
49 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
50 *itable++ = base[i][l];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
51 *itable++ = base[i][k];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
52 *itable++ = base[i][j];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
53 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
54 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
56 for (k = 0; k < 27; k++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
57 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
58 double m = mulmul[k];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
59 table = mpg123_muls[k];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
60 for (j = 3, i = 0; i < 63; i++, j--)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
61 *table++ = m * pow (2.0, (double) j / 3.0);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
62 *table++ = 0.0;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
63 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
66 void
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
67 II_step_one (unsigned int *bit_alloc, int *scale, struct frame *fr)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68 {
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
69 int stereo = fr->stereo - 1;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
70 int sblimit = fr->II_sblimit;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
71 int jsbound = fr->jsbound;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
72 int sblimit2 = fr->II_sblimit << stereo;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
73 struct al_table *alloc1 = fr->alloc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
74 int i;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
75 static unsigned int scfsi_buf[64];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
76 unsigned int *scfsi, *bita;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
77 int sc, step;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
79 bita = bit_alloc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
80 if (stereo)
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
81 {
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
82 for (i = jsbound; i > 0; i--, alloc1 += (1 << step))
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
83 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
84 *bita++ = (char) mpg123_getbits (&bsi, step = alloc1->bits);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
85 *bita++ = (char) mpg123_getbits (&bsi, step);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
86 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
87 for (i = sblimit - jsbound; i > 0; i--, alloc1 += (1 << step))
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
88 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
89 bita[0] = (char) mpg123_getbits (&bsi, step = alloc1->bits);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
90 bita[1] = bita[0];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
91 bita += 2;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
92 }
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
93 bita = bit_alloc;
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
94 scfsi = scfsi_buf;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
95 for (i = sblimit2; i; i--)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
96 if (*bita++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
97 *scfsi++ = (char) mpg123_getbits_fast (&bsi, 2);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98 }
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
99 else
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
100 /* mono */
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 {
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
102 for (i = sblimit; i; i--, alloc1 += (1 << step))
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
103 *bita++ = (char) mpg123_getbits (&bsi, step = alloc1->bits);
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
104 bita = bit_alloc;
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
105 scfsi = scfsi_buf;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
106 for (i = sblimit; i; i--)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
107 if (*bita++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
108 *scfsi++ = (char) mpg123_getbits_fast (&bsi, 2);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
111 bita = bit_alloc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
112 scfsi = scfsi_buf;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
113 for (i = sblimit2; i; i--)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
114 if (*bita++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
115 switch (*scfsi++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
116 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
117 case 0:
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
118 *scale++ = mpg123_getbits_fast (&bsi, 6);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
119 *scale++ = mpg123_getbits_fast (&bsi, 6);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
120 *scale++ = mpg123_getbits_fast (&bsi, 6);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
121 break;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
122 case 1:
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
123 *scale++ = sc = mpg123_getbits_fast (&bsi, 6);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
124 *scale++ = sc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
125 *scale++ = mpg123_getbits_fast (&bsi, 6);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
126 break;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
127 case 2:
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
128 *scale++ = sc = mpg123_getbits_fast (&bsi, 6);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
129 *scale++ = sc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
130 *scale++ = sc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
131 break;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
132 default: /* case 3 */
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
133 *scale++ = mpg123_getbits_fast (&bsi, 6);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
134 *scale++ = sc = mpg123_getbits_fast (&bsi, 6);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
135 *scale++ = sc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
136 break;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
137 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
141 void
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
142 II_step_two (unsigned int *bit_alloc, real fraction[2][4][SBLIMIT],
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
143 int *scale, struct frame *fr, int x1)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 {
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
145 int i, j, k, ba;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
146 int stereo = fr->stereo;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
147 int sblimit = fr->II_sblimit;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
148 int jsbound = fr->jsbound;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
149 struct al_table *alloc2, *alloc1 = fr->alloc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
150 unsigned int *bita = bit_alloc;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
151 int d1, step;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
153 for (i = 0; i < jsbound; i++, alloc1 += (1 << step))
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
154 {
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
155 step = alloc1->bits;
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
156 for (j = 0; j < stereo; j++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
157 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
158 if ((ba = *bita++))
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
159 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
160 k = (alloc2 = alloc1 + ba)->bits;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
161 if ((d1 = alloc2->d) < 0)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
162 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
163 real cm = mpg123_muls[k][scale[x1]];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
164
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
165 fraction[j][0][i] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
166 ((real) ((int) mpg123_getbits (&bsi, k) + d1)) * cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
167 fraction[j][1][i] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
168 ((real) ((int) mpg123_getbits (&bsi, k) + d1)) * cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
169 fraction[j][2][i] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
170 ((real) ((int) mpg123_getbits (&bsi, k) + d1)) * cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
171 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
172 else
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
173 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
174 static int *table[] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
175 { 0, 0, 0, grp_3tab, 0, grp_5tab, 0, 0, 0, grp_9tab };
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
176 unsigned int idx, *tab, m = scale[x1];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
177
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
178 idx = (unsigned int) mpg123_getbits (&bsi, k);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
179 tab = (unsigned int *) (table[d1] + idx + idx + idx);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
180 fraction[j][0][i] = mpg123_muls[*tab++][m];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
181 fraction[j][1][i] = mpg123_muls[*tab++][m];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
182 fraction[j][2][i] = mpg123_muls[*tab][m];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
183 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
184 scale += 3;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
185 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
186 else
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
187 fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
188 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
191 for (i = jsbound; i < sblimit; i++, alloc1 += (1 << step))
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
192 {
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
193 step = alloc1->bits;
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
194 bita++; /* channel 1 and channel 2 bitalloc are the same */
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
195 if ((ba = *bita++))
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
196 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
197 k = (alloc2 = alloc1 + ba)->bits;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
198 if ((d1 = alloc2->d) < 0)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
199 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
200 real cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
201
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
202 cm = mpg123_muls[k][scale[x1 + 3]];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
203 fraction[1][0][i] = (fraction[0][0][i] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
204 (real) ((int) mpg123_getbits (&bsi, k) +
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
205 d1)) * cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
206 fraction[1][1][i] = (fraction[0][1][i] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
207 (real) ((int) mpg123_getbits (&bsi, k) +
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
208 d1)) * cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
209 fraction[1][2][i] = (fraction[0][2][i] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
210 (real) ((int) mpg123_getbits (&bsi, k) +
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
211 d1)) * cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
212 cm = mpg123_muls[k][scale[x1]];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
213 fraction[0][0][i] *= cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
214 fraction[0][1][i] *= cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
215 fraction[0][2][i] *= cm;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
216 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
217 else
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
218 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
219 static int *table[] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
220 { 0, 0, 0, grp_3tab, 0, grp_5tab, 0, 0, 0, grp_9tab };
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
221 unsigned int idx, *tab, m1, m2;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
222
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
223 m1 = scale[x1];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
224 m2 = scale[x1 + 3];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
225 idx = (unsigned int) mpg123_getbits (&bsi, k);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
226 tab = (unsigned int *) (table[d1] + idx + idx + idx);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
227 fraction[0][0][i] = mpg123_muls[*tab][m1];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
228 fraction[1][0][i] = mpg123_muls[*tab++][m2];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
229 fraction[0][1][i] = mpg123_muls[*tab][m1];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
230 fraction[1][1][i] = mpg123_muls[*tab++][m2];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
231 fraction[0][2][i] = mpg123_muls[*tab][m1];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
232 fraction[1][2][i] = mpg123_muls[*tab][m2];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
233 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
234 scale += 6;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
235 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
236 else
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
237 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
238 fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
239 fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
240 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
241 /*
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
242 should we use individual scalefac for channel 2 or
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
243 is the current way the right one , where we just copy channel 1 to
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
244 channel 2 ??
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
245 The current 'strange' thing is, that we throw away the scalefac
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
246 values for the second channel ...!!
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
247 -> changed .. now we use the scalefac values of channel one !!
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
248 */
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
251 if (sblimit > (fr->down_sample_sblimit))
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
252 sblimit = fr->down_sample_sblimit;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
254 for (i = sblimit; i < SBLIMIT; i++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
255 for (j = 0; j < stereo; j++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
256 fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
260 static void
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
261 II_select_table (struct frame *fr)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262 {
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
263 static int translate[3][2][16] = {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
264 {{0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, 0},
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
265 {0, 2, 2, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}},
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
266 {{0, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
267 {0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
268 {{0, 3, 3, 3, 3, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, 0},
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
269 {0, 3, 3, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}}
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
270 };
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
272 int table, sblim;
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
273 static struct al_table *tables[5] =
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
274 { alloc_0, alloc_1, alloc_2, alloc_3, alloc_4 };
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
275 static int sblims[5] = { 27, 30, 8, 12, 30 };
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
277 if (fr->lsf)
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
278 table = 4;
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
279 else
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
280 table =
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
281 translate[fr->sampling_frequency][2 - fr->stereo][fr->bitrate_index];
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
282 sblim = sblims[table];
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
284 fr->alloc = tables[table];
127
05d824e30afd [svn] Synchronize mpg123 code with mpg123-0.59s.mc3. This brings us superior accuracy to libMAD, apparently.
nenolod
parents: 61
diff changeset
285 fr->II_sblimit = sblim;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
288
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289 int
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
290 mpg123_do_layer2 (struct frame *fr)
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 {
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
292 int i, j;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
293 int stereo = fr->stereo;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
294 real fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
295 unsigned int bit_alloc[64];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
296 int scale[192];
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
297 int single = fr->single;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
299 II_select_table (fr);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
300 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ?
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
301 (fr->mode_ext << 2) + 4 : fr->II_sblimit;
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
302 if (fr->jsbound > fr->II_sblimit)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
303 fr->jsbound = fr->II_sblimit;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
305 if (stereo == 1 || single == 3)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
306 single = 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
308 II_step_one (bit_alloc, scale, fr);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
310 for (i = 0; i < SCALE_BLOCK; i++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
311 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
312 II_step_two (bit_alloc, fraction, scale, fr, i >> 2);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
313 for (j = 0; j < 3; j++)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
314 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
315 if (single >= 0)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
316 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
317 (fr->synth_mono) (fraction[single][j], mpg123_pcm_sample,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
318 &mpg123_pcm_point);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
319 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
320 else
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
321 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
322 int p1 = mpg123_pcm_point;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
324 (fr->synth) (fraction[0][j], 0, mpg123_pcm_sample, &p1);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
325 (fr->synth) (fraction[1][j], 1, mpg123_pcm_sample,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
326 &mpg123_pcm_point);
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
327 }
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
328
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
329 /* if(mpg123_pcm_point >= audiobufsize)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
330 audio_flush(outmode,ai); */
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
331 }
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332 }
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
333 if (mpg123_info->output_audio)
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
334 {
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
335 produce_audio (mpg123_ip.output->written_time (),
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
336 mpg123_cfg.resolution == 16 ? FMT_S16_NE : FMT_U8,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
337 mpg123_cfg.channels == 2 ? fr->stereo : 1,
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
338 mpg123_pcm_point, mpg123_pcm_sample, &mpg123_pcm_point);
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339 }
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
340 mpg123_pcm_point = 0;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341
728
e39735f0b2f7 [svn] - fix my layer2 implementation by looking at the one in XMMS. MP2 support at no additional charge.
nenolod
parents: 177
diff changeset
342 return 1;
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 }