nabaztag_hack_kit 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +4 -0
  5. data/README.md +119 -0
  6. data/Rakefile +21 -0
  7. data/bin/mtl_comp +41 -0
  8. data/bin/mtl_merge +22 -0
  9. data/bin/mtl_simu +40 -0
  10. data/bytecode/lib/buffer.mtl +109 -0
  11. data/bytecode/lib/button.mtl +27 -0
  12. data/bytecode/lib/data_helper.mtl +88 -0
  13. data/bytecode/lib/ear.mtl +90 -0
  14. data/bytecode/lib/led.mtl +33 -0
  15. data/bytecode/lib/rfid.mtl +50 -0
  16. data/bytecode/main.mtl +129 -0
  17. data/config.ru +6 -0
  18. data/ext/bytecode/Commands.md +172 -0
  19. data/ext/bytecode/Docs.md +488 -0
  20. data/ext/bytecode/README.md +5 -0
  21. data/ext/bytecode/lib/arp.mtl +159 -0
  22. data/ext/bytecode/lib/cfg.mtl +74 -0
  23. data/ext/bytecode/lib/choreos.mtl +1487 -0
  24. data/ext/bytecode/lib/dhcp.mtl +152 -0
  25. data/ext/bytecode/lib/dns.mtl +89 -0
  26. data/ext/bytecode/lib/http.mtl +84 -0
  27. data/ext/bytecode/lib/tcp.mtl +340 -0
  28. data/ext/bytecode/lib/udp.mtl +49 -0
  29. data/ext/bytecode/lib/util.mtl +74 -0
  30. data/ext/bytecode/lib/var.mtl +15 -0
  31. data/ext/bytecode/lib/wifi.mtl +243 -0
  32. data/ext/bytecode/nominal-ping.mtl +5828 -0
  33. data/ext/mtl/Makefile +42 -0
  34. data/ext/mtl/README.md +13 -0
  35. data/ext/mtl/bc.cpp +1891 -0
  36. data/ext/mtl/conf.bin.sans_password +0 -0
  37. data/ext/mtl/config.txt +5 -0
  38. data/ext/mtl/dumpbc.c +2566 -0
  39. data/ext/mtl/extconf.rb +1 -0
  40. data/ext/mtl/linux_simu.c +271 -0
  41. data/ext/mtl/linux_simuaudio.c +16 -0
  42. data/ext/mtl/linux_simuaudio.h +18 -0
  43. data/ext/mtl/linux_simunet.c +620 -0
  44. data/ext/mtl/linux_simunet.h +7 -0
  45. data/ext/mtl/log.c +297 -0
  46. data/ext/mtl/log.h +20 -0
  47. data/ext/mtl/main_compiler.cpp +104 -0
  48. data/ext/mtl/main_simu.cpp +221 -0
  49. data/ext/mtl/mp3/GTKANAL.H +97 -0
  50. data/ext/mtl/mp3/LAYER3.C +2090 -0
  51. data/ext/mtl/mp3/TABINIT.C +82 -0
  52. data/ext/mtl/mp3/common.c +265 -0
  53. data/ext/mtl/mp3/dct64_i386.c +316 -0
  54. data/ext/mtl/mp3/decode_i386.c +155 -0
  55. data/ext/mtl/mp3/huffman.h +332 -0
  56. data/ext/mtl/mp3/interface.c +258 -0
  57. data/ext/mtl/mp3/mpg123.h +182 -0
  58. data/ext/mtl/mp3/mpglib.h +44 -0
  59. data/ext/mtl/properties.c +293 -0
  60. data/ext/mtl/properties.h +10 -0
  61. data/ext/mtl/simu.c +750 -0
  62. data/ext/mtl/simuaudio.c +662 -0
  63. data/ext/mtl/simuaudio.h +74 -0
  64. data/ext/mtl/simunet.c +400 -0
  65. data/ext/mtl/simunet.h +30 -0
  66. data/ext/mtl/utils/correct_const.sh +34 -0
  67. data/ext/mtl/vaudio.c +677 -0
  68. data/ext/mtl/vaudio.h +46 -0
  69. data/ext/mtl/vbc.h +160 -0
  70. data/ext/mtl/vbc_str.h +166 -0
  71. data/ext/mtl/vcomp/Makefile +29 -0
  72. data/ext/mtl/vcomp/bootstrap.cpp +89 -0
  73. data/ext/mtl/vcomp/compiler.cpp +470 -0
  74. data/ext/mtl/vcomp/compiler.h +200 -0
  75. data/ext/mtl/vcomp/compiler_file.cpp +929 -0
  76. data/ext/mtl/vcomp/compiler_prog.cpp +250 -0
  77. data/ext/mtl/vcomp/compiler_term.cpp +1053 -0
  78. data/ext/mtl/vcomp/compiler_type.cpp +872 -0
  79. data/ext/mtl/vcomp/compiler_var.cpp +289 -0
  80. data/ext/mtl/vcomp/file.cpp +79 -0
  81. data/ext/mtl/vcomp/file.h +39 -0
  82. data/ext/mtl/vcomp/filesystem.h +14 -0
  83. data/ext/mtl/vcomp/interpreter.cpp +85 -0
  84. data/ext/mtl/vcomp/interpreter.h +121 -0
  85. data/ext/mtl/vcomp/memory.cpp +241 -0
  86. data/ext/mtl/vcomp/memory.h +326 -0
  87. data/ext/mtl/vcomp/param.h +95 -0
  88. data/ext/mtl/vcomp/parser.cpp +427 -0
  89. data/ext/mtl/vcomp/parser.h +97 -0
  90. data/ext/mtl/vcomp/parser_xml.cpp +124 -0
  91. data/ext/mtl/vcomp/prodbuffer.cpp +125 -0
  92. data/ext/mtl/vcomp/prodbuffer.h +42 -0
  93. data/ext/mtl/vcomp/resource.h +17 -0
  94. data/ext/mtl/vcomp/stdlib_core.cpp +122 -0
  95. data/ext/mtl/vcomp/terminal.cpp +73 -0
  96. data/ext/mtl/vcomp/terminal.h +30 -0
  97. data/ext/mtl/vcomp/util.cpp +48 -0
  98. data/ext/mtl/vcomp/util.h +31 -0
  99. data/ext/mtl/vinterp.c +1349 -0
  100. data/ext/mtl/vinterp.h +11 -0
  101. data/ext/mtl/vloader.c +127 -0
  102. data/ext/mtl/vloader.h +31 -0
  103. data/ext/mtl/vlog.c +589 -0
  104. data/ext/mtl/vlog.h +69 -0
  105. data/ext/mtl/vmem.c +424 -0
  106. data/ext/mtl/vmem.h +107 -0
  107. data/ext/mtl/vnet.c +255 -0
  108. data/ext/mtl/vnet.h +19 -0
  109. data/lib/nabaztag_hack_kit/message/api.rb +39 -0
  110. data/lib/nabaztag_hack_kit/message/helper.rb +39 -0
  111. data/lib/nabaztag_hack_kit/message.rb +36 -0
  112. data/lib/nabaztag_hack_kit/server.rb +50 -0
  113. data/lib/nabaztag_hack_kit/version.rb +3 -0
  114. data/lib/nabaztag_hack_kit.rb +4 -0
  115. data/nabaztag_hack_kit.gemspec +29 -0
  116. data/public/bytecode.bin +0 -0
  117. data/test/bytecode/helper.mtl +60 -0
  118. data/test/bytecode/native.mtl +28 -0
  119. data/test/bytecode/test.mtl +221 -0
  120. data/test/spec_helper.rb +5 -0
  121. data/test/unit/message_spec.rb +56 -0
  122. metadata +209 -0
@@ -0,0 +1,2090 @@
1
+ //#ifdef HAVEGTK
2
+ /*
3
+ * Mpeg Layer-3 audio decoder
4
+ * --------------------------
5
+ * copyright (c) 1995,1996,1997 by Michael Hipp.
6
+ * All rights reserved. See also 'README'
7
+ */
8
+
9
+ #include <stdlib.h>
10
+ #include "mpg123.h"
11
+ #include "mpglib.h"
12
+ #include "huffman.h"
13
+ #include "gtkanal.h"
14
+
15
+
16
+ extern struct mpstr *gmp;
17
+
18
+ #define MPEG1
19
+
20
+
21
+ static real ispow[8207];
22
+ static real aa_ca[8],aa_cs[8];
23
+ static real COS1[12][6];
24
+ static real win[4][36];
25
+ static real win1[4][36];
26
+ static real gainpow2[256+118+4];
27
+ static real COS9[9];
28
+ static real COS6_1,COS6_2;
29
+ static real tfcos36[9];
30
+ static real tfcos12[3];
31
+
32
+ struct bandInfoStruct {
33
+ short longIdx[23];
34
+ short longDiff[22];
35
+ short shortIdx[14];
36
+ short shortDiff[13];
37
+ };
38
+
39
+ int longLimit[9][23];
40
+ int shortLimit[9][14];
41
+
42
+ struct bandInfoStruct bandInfo[9] = {
43
+
44
+ /* MPEG 1.0 */
45
+ { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
46
+ {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158},
47
+ {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3},
48
+ {4,4,4,4,6,8,10,12,14,18,22,30,56} } ,
49
+
50
+ { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576},
51
+ {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192},
52
+ {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3},
53
+ {4,4,4,4,6,6,10,12,14,16,20,26,66} } ,
54
+
55
+ { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} ,
56
+ {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} ,
57
+ {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} ,
58
+ {4,4,4,4,6,8,12,16,20,26,34,42,12} } ,
59
+
60
+ /* MPEG 2.0 */
61
+ { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
62
+ {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } ,
63
+ {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} ,
64
+ {4,4,4,6,6,8,10,14,18,26,32,42,18 } } ,
65
+
66
+ { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},
67
+ {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } ,
68
+ {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} ,
69
+ {4,4,4,6,8,10,12,14,18,24,32,44,12 } } ,
70
+
71
+ { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
72
+ {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 },
73
+ {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3},
74
+ {4,4,4,6,8,10,12,14,18,24,30,40,18 } } ,
75
+ /* MPEG 2.5 */
76
+ { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
77
+ {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
78
+ {0,12,24,36,54,78,108,144,186,240,312,402,522,576},
79
+ {4,4,4,6,8,10,12,14,18,24,30,40,18} },
80
+ { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
81
+ {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
82
+ {0,12,24,36,54,78,108,144,186,240,312,402,522,576},
83
+ {4,4,4,6,8,10,12,14,18,24,30,40,18} },
84
+ { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576},
85
+ {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2},
86
+ {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576},
87
+ {8,8,8,12,16,20,24,28,36,2,2,2,26} } ,
88
+ };
89
+
90
+ static int mapbuf0[9][152];
91
+ static int mapbuf1[9][156];
92
+ static int mapbuf2[9][44];
93
+ static int *map[9][3];
94
+ static int *mapend[9][3];
95
+
96
+ static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */
97
+ static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */
98
+
99
+ static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
100
+ static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
101
+
102
+ static unsigned int get1bit(void)
103
+ {
104
+ unsigned char rval;
105
+ rval = *wordpointer << bitindex;
106
+
107
+ bitindex++;
108
+ wordpointer += (bitindex>>3);
109
+ bitindex &= 7;
110
+
111
+ return rval>>7;
112
+ }
113
+
114
+
115
+
116
+
117
+ /*
118
+ * init tables for layer-3
119
+ */
120
+ void init_layer3(int down_sample_sblimit)
121
+ {
122
+ int i,j,k,l;
123
+
124
+ for(i=-256;i<118+4;i++)
125
+ gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) );
126
+
127
+ for(i=0;i<8207;i++)
128
+ ispow[i] = pow((double)i,(double)4.0/3.0);
129
+
130
+ for (i=0;i<8;i++)
131
+ {
132
+ static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037};
133
+ double sq=sqrt(1.0+Ci[i]*Ci[i]);
134
+ aa_cs[i] = 1.0/sq;
135
+ aa_ca[i] = Ci[i]/sq;
136
+ }
137
+
138
+ for(i=0;i<18;i++)
139
+ {
140
+ win[0][i] = win[1][i] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 );
141
+ win[0][i+18] = win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
142
+ }
143
+ for(i=0;i<6;i++)
144
+ {
145
+ win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
146
+ win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 );
147
+ win[1][i+24] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 );
148
+ win[1][i+30] = win[3][i] = 0.0;
149
+ win[3][i+6 ] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 );
150
+ }
151
+
152
+ for(i=0;i<9;i++)
153
+ COS9[i] = cos( M_PI / 18.0 * (double) i);
154
+
155
+ for(i=0;i<9;i++)
156
+ tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 );
157
+ for(i=0;i<3;i++)
158
+ tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 );
159
+
160
+ COS6_1 = cos( M_PI / 6.0 * (double) 1);
161
+ COS6_2 = cos( M_PI / 6.0 * (double) 2);
162
+
163
+ for(i=0;i<12;i++)
164
+ {
165
+ win[2][i] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 );
166
+ for(j=0;j<6;j++)
167
+ COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) );
168
+ }
169
+
170
+ for(j=0;j<4;j++) {
171
+ static int len[4] = { 36,36,12,36 };
172
+ for(i=0;i<len[j];i+=2)
173
+ win1[j][i] = + win[j][i];
174
+ for(i=1;i<len[j];i+=2)
175
+ win1[j][i] = - win[j][i];
176
+ }
177
+
178
+ for(i=0;i<16;i++)
179
+ {
180
+ double t = tan( (double) i * M_PI / 12.0 );
181
+ tan1_1[i] = t / (1.0+t);
182
+ tan2_1[i] = 1.0 / (1.0 + t);
183
+ tan1_2[i] = M_SQRT2 * t / (1.0+t);
184
+ tan2_2[i] = M_SQRT2 / (1.0 + t);
185
+
186
+ for(j=0;j<2;j++) {
187
+ double base = pow(2.0,-0.25*(j+1.0));
188
+ double p1=1.0,p2=1.0;
189
+ if(i > 0) {
190
+ if( i & 1 )
191
+ p1 = pow(base,(i+1.0)*0.5);
192
+ else
193
+ p2 = pow(base,i*0.5);
194
+ }
195
+ pow1_1[j][i] = p1;
196
+ pow2_1[j][i] = p2;
197
+ pow1_2[j][i] = M_SQRT2 * p1;
198
+ pow2_2[j][i] = M_SQRT2 * p2;
199
+ }
200
+ }
201
+
202
+ for(j=0;j<9;j++)
203
+ {
204
+ struct bandInfoStruct *bi = &bandInfo[j];
205
+ int *mp;
206
+ int cb,lwin;
207
+ short *bdf;
208
+
209
+ mp = map[j][0] = mapbuf0[j];
210
+ bdf = bi->longDiff;
211
+ for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) {
212
+ *mp++ = (*bdf) >> 1;
213
+ *mp++ = i;
214
+ *mp++ = 3;
215
+ *mp++ = cb;
216
+ }
217
+ bdf = bi->shortDiff+3;
218
+ for(cb=3;cb<13;cb++) {
219
+ int l = (*bdf++) >> 1;
220
+ for(lwin=0;lwin<3;lwin++) {
221
+ *mp++ = l;
222
+ *mp++ = i + lwin;
223
+ *mp++ = lwin;
224
+ *mp++ = cb;
225
+ }
226
+ i += 6*l;
227
+ }
228
+ mapend[j][0] = mp;
229
+
230
+ mp = map[j][1] = mapbuf1[j];
231
+ bdf = bi->shortDiff+0;
232
+ for(i=0,cb=0;cb<13;cb++) {
233
+ int l = (*bdf++) >> 1;
234
+ for(lwin=0;lwin<3;lwin++) {
235
+ *mp++ = l;
236
+ *mp++ = i + lwin;
237
+ *mp++ = lwin;
238
+ *mp++ = cb;
239
+ }
240
+ i += 6*l;
241
+ }
242
+ mapend[j][1] = mp;
243
+
244
+ mp = map[j][2] = mapbuf2[j];
245
+ bdf = bi->longDiff;
246
+ for(cb = 0; cb < 22 ; cb++) {
247
+ *mp++ = (*bdf++) >> 1;
248
+ *mp++ = cb;
249
+ }
250
+ mapend[j][2] = mp;
251
+
252
+ }
253
+
254
+ for(j=0;j<9;j++) {
255
+ for(i=0;i<23;i++) {
256
+ longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1;
257
+ if(longLimit[j][i] > (down_sample_sblimit) )
258
+ longLimit[j][i] = down_sample_sblimit;
259
+ }
260
+ for(i=0;i<14;i++) {
261
+ shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1;
262
+ if(shortLimit[j][i] > (down_sample_sblimit) )
263
+ shortLimit[j][i] = down_sample_sblimit;
264
+ }
265
+ }
266
+
267
+ for(i=0;i<5;i++) {
268
+ for(j=0;j<6;j++) {
269
+ for(k=0;k<6;k++) {
270
+ int n = k + j * 6 + i * 36;
271
+ i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12);
272
+ }
273
+ }
274
+ }
275
+ for(i=0;i<4;i++) {
276
+ for(j=0;j<4;j++) {
277
+ for(k=0;k<4;k++) {
278
+ int n = k + j * 4 + i * 16;
279
+ i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12);
280
+ }
281
+ }
282
+ }
283
+ for(i=0;i<4;i++) {
284
+ for(j=0;j<3;j++) {
285
+ int n = j + i * 3;
286
+ i_slen2[n+244] = i|(j<<3) | (5<<12);
287
+ n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15);
288
+ }
289
+ }
290
+
291
+ for(i=0;i<5;i++) {
292
+ for(j=0;j<5;j++) {
293
+ for(k=0;k<4;k++) {
294
+ for(l=0;l<4;l++) {
295
+ int n = l + k * 4 + j * 16 + i * 80;
296
+ n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12);
297
+ }
298
+ }
299
+ }
300
+ }
301
+ for(i=0;i<5;i++) {
302
+ for(j=0;j<5;j++) {
303
+ for(k=0;k<4;k++) {
304
+ int n = k + j * 4 + i * 20;
305
+ n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12);
306
+ }
307
+ }
308
+ }
309
+ }
310
+
311
+ /*
312
+ * read additional side information
313
+ */
314
+ #ifdef MPEG1
315
+ static void III_get_side_info_1(struct III_sideinfo *si,int stereo,
316
+ int ms_stereo,long sfreq,int single)
317
+ {
318
+ int ch, gr;
319
+ int powdiff = (single == 3) ? 4 : 0;
320
+
321
+ si->main_data_begin = getbits(9);
322
+ if (stereo == 1)
323
+ si->private_bits = getbits_fast(5);
324
+ else
325
+ si->private_bits = getbits_fast(3);
326
+
327
+ for (ch=0; ch<stereo; ch++) {
328
+ si->ch[ch].gr[0].scfsi = -1;
329
+ si->ch[ch].gr[1].scfsi = getbits_fast(4);
330
+ }
331
+
332
+ for (gr=0; gr<2; gr++)
333
+ {
334
+ for (ch=0; ch<stereo; ch++)
335
+ {
336
+ register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
337
+
338
+ gr_info->part2_3_length = getbits(12);
339
+ gr_info->big_values = getbits_fast(9);
340
+ if(gr_info->big_values > 288) {
341
+ fprintf(stderr,"big_values too large!\n");
342
+ gr_info->big_values = 288;
343
+ }
344
+ {
345
+ unsigned int qss = getbits_fast(8);
346
+ gr_info->pow2gain = gainpow2+256 - qss + powdiff;
347
+ #ifdef HAVEGTK
348
+ pinfo->qss[gr][ch]=qss;
349
+ #endif
350
+ }
351
+ if(ms_stereo)
352
+ gr_info->pow2gain += 2;
353
+ gr_info->scalefac_compress = getbits_fast(4);
354
+ /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
355
+ if(get1bit())
356
+ {
357
+ int i;
358
+ gr_info->block_type = getbits_fast(2);
359
+ gr_info->mixed_block_flag = get1bit();
360
+ gr_info->table_select[0] = getbits_fast(5);
361
+ gr_info->table_select[1] = getbits_fast(5);
362
+
363
+
364
+ /*
365
+ * table_select[2] not needed, because there is no region2,
366
+ * but to satisfy some verifications tools we set it either.
367
+ */
368
+ gr_info->table_select[2] = 0;
369
+ for(i=0;i<3;i++) {
370
+ unsigned int sbg = (getbits_fast(3)<<3);
371
+ gr_info->full_gain[i] = gr_info->pow2gain + sbg;
372
+ #ifdef HAVEGTK
373
+ pinfo->sub_gain[gr][ch][i]=sbg/8;
374
+ #endif
375
+ }
376
+
377
+
378
+ if(gr_info->block_type == 0) {
379
+ fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
380
+ // exit(1);
381
+ return -1;
382
+ }
383
+ /* region_count/start parameters are implicit in this case. */
384
+ gr_info->region1start = 36>>1;
385
+ gr_info->region2start = 576>>1;
386
+ }
387
+ else
388
+ {
389
+ int i,r0c,r1c;
390
+ for (i=0; i<3; i++)
391
+ gr_info->table_select[i] = getbits_fast(5);
392
+ r0c = getbits_fast(4);
393
+ r1c = getbits_fast(3);
394
+ gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
395
+ gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
396
+ gr_info->block_type = 0;
397
+ gr_info->mixed_block_flag = 0;
398
+ }
399
+ gr_info->preflag = get1bit();
400
+ gr_info->scalefac_scale = get1bit();
401
+ gr_info->count1table_select = get1bit();
402
+ #ifdef HAVEGTK
403
+ pinfo->scalefac_scale[gr][ch]=gr_info->scalefac_scale;
404
+ #endif
405
+ }
406
+ }
407
+ }
408
+ #endif
409
+
410
+ /*
411
+ * Side Info for MPEG 2.0 / LSF
412
+ */
413
+ static void III_get_side_info_2(struct III_sideinfo *si,int stereo,
414
+ int ms_stereo,long sfreq,int single)
415
+ {
416
+ int ch;
417
+ int powdiff = (single == 3) ? 4 : 0;
418
+
419
+ si->main_data_begin = getbits(8);
420
+ if (stereo == 1)
421
+ si->private_bits = get1bit();
422
+ else
423
+ si->private_bits = getbits_fast(2);
424
+
425
+ for (ch=0; ch<stereo; ch++)
426
+ {
427
+ register struct gr_info_s *gr_info = &(si->ch[ch].gr[0]);
428
+
429
+ gr_info->part2_3_length = getbits(12);
430
+ gr_info->big_values = getbits_fast(9);
431
+ if(gr_info->big_values > 288) {
432
+ fprintf(stderr,"big_values too large!\n");
433
+ gr_info->big_values = 288;
434
+ }
435
+ gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff;
436
+ if(ms_stereo)
437
+ gr_info->pow2gain += 2;
438
+ gr_info->scalefac_compress = getbits(9);
439
+ /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
440
+ if(get1bit())
441
+ {
442
+ int i;
443
+ gr_info->block_type = getbits_fast(2);
444
+ gr_info->mixed_block_flag = get1bit();
445
+ gr_info->table_select[0] = getbits_fast(5);
446
+ gr_info->table_select[1] = getbits_fast(5);
447
+ /*
448
+ * table_select[2] not needed, because there is no region2,
449
+ * but to satisfy some verifications tools we set it either.
450
+ */
451
+ gr_info->table_select[2] = 0;
452
+ for(i=0;i<3;i++) {
453
+ gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);
454
+ }
455
+
456
+ if(gr_info->block_type == 0) {
457
+ fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
458
+ // exit(1);
459
+ return -1;
460
+ }
461
+ /* region_count/start parameters are implicit in this case. */
462
+ /* check this again! */
463
+ if(gr_info->block_type == 2)
464
+ gr_info->region1start = 36>>1;
465
+ else if(sfreq == 8)
466
+ /* check this for 2.5 and sfreq=8 */
467
+ gr_info->region1start = 108>>1;
468
+ else
469
+ gr_info->region1start = 54>>1;
470
+ gr_info->region2start = 576>>1;
471
+ }
472
+ else
473
+ {
474
+ int i,r0c,r1c;
475
+ for (i=0; i<3; i++)
476
+ gr_info->table_select[i] = getbits_fast(5);
477
+ r0c = getbits_fast(4);
478
+ r1c = getbits_fast(3);
479
+ gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
480
+ gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
481
+ gr_info->block_type = 0;
482
+ gr_info->mixed_block_flag = 0;
483
+ }
484
+ gr_info->scalefac_scale = get1bit();
485
+ gr_info->count1table_select = get1bit();
486
+ #ifdef HAVEGTK
487
+ pinfo->scalefac_scale[0][ch]=gr_info->scalefac_scale;
488
+ #endif
489
+ }
490
+ }
491
+
492
+ /*
493
+ * read scalefactors
494
+ */
495
+ #ifdef MPEG1
496
+ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
497
+ {
498
+ static unsigned char slen[2][16] = {
499
+ {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
500
+ {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
501
+ };
502
+ int numbits;
503
+ int num0 = slen[0][gr_info->scalefac_compress];
504
+ int num1 = slen[1][gr_info->scalefac_compress];
505
+
506
+ if (gr_info->block_type == 2)
507
+ {
508
+ int i=18;
509
+ numbits = (num0 + num1) * 18;
510
+
511
+ if (gr_info->mixed_block_flag) {
512
+ for (i=8;i;i--)
513
+ *scf++ = getbits_fast(num0);
514
+ i = 9;
515
+ numbits -= num0; /* num0 * 17 + num1 * 18 */
516
+ }
517
+
518
+ for (;i;i--)
519
+ *scf++ = getbits_fast(num0);
520
+ for (i = 18; i; i--)
521
+ *scf++ = getbits_fast(num1);
522
+ *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
523
+ }
524
+ else
525
+ {
526
+ int i;
527
+ int scfsi = gr_info->scfsi;
528
+
529
+ if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
530
+ for(i=11;i;i--)
531
+ *scf++ = getbits_fast(num0);
532
+ for(i=10;i;i--)
533
+ *scf++ = getbits_fast(num1);
534
+ numbits = (num0 + num1) * 10 + num0;
535
+ }
536
+ else {
537
+ numbits = 0;
538
+ if(!(scfsi & 0x8)) {
539
+ for (i=6;i;i--)
540
+ *scf++ = getbits_fast(num0);
541
+ numbits += num0 * 6;
542
+ }
543
+ else {
544
+ *scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
545
+ *scf++ = 0; *scf++ = 0; *scf++ = 0;
546
+ }
547
+
548
+ if(!(scfsi & 0x4)) {
549
+ for (i=5;i;i--)
550
+ *scf++ = getbits_fast(num0);
551
+ numbits += num0 * 5;
552
+ }
553
+ else {
554
+ *scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
555
+ *scf++ = 0; *scf++ = 0;
556
+ }
557
+
558
+ if(!(scfsi & 0x2)) {
559
+ for(i=5;i;i--)
560
+ *scf++ = getbits_fast(num1);
561
+ numbits += num1 * 5;
562
+ }
563
+ else {
564
+ *scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
565
+ *scf++ = 0; *scf++ = 0;
566
+ }
567
+
568
+ if(!(scfsi & 0x1)) {
569
+ for (i=5;i;i--)
570
+ *scf++ = getbits_fast(num1);
571
+ numbits += num1 * 5;
572
+ }
573
+ else {
574
+ *scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
575
+ *scf++ = 0; *scf++ = 0;
576
+ }
577
+ }
578
+
579
+ *scf++ = 0; /* no l[21] in original sources */
580
+ }
581
+ return numbits;
582
+ }
583
+ #endif
584
+
585
+ static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo)
586
+ {
587
+ unsigned char *pnt;
588
+ int i,j;
589
+ unsigned int slen;
590
+ int n = 0;
591
+ int numbits = 0;
592
+
593
+ static unsigned char stab[3][6][4] = {
594
+ { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} ,
595
+ { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } ,
596
+ { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
597
+ {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
598
+ { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
599
+ { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } };
600
+
601
+ if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
602
+ slen = i_slen2[gr_info->scalefac_compress>>1];
603
+ else
604
+ slen = n_slen2[gr_info->scalefac_compress];
605
+
606
+ gr_info->preflag = (slen>>15) & 0x1;
607
+
608
+ n = 0;
609
+ if( gr_info->block_type == 2 ) {
610
+ n++;
611
+ if(gr_info->mixed_block_flag)
612
+ n++;
613
+ }
614
+
615
+ pnt = stab[n][(slen>>12)&0x7];
616
+
617
+ for(i=0;i<4;i++) {
618
+ int num = slen & 0x7;
619
+ slen >>= 3;
620
+ if(num) {
621
+ for(j=0;j<(int)(pnt[i]);j++)
622
+ *scf++ = getbits_fast(num);
623
+ numbits += pnt[i] * num;
624
+ }
625
+ else {
626
+ for(j=0;j<(int)(pnt[i]);j++)
627
+ *scf++ = 0;
628
+ }
629
+ }
630
+
631
+ n = (n << 1) + 1;
632
+ for(i=0;i<n;i++)
633
+ *scf++ = 0;
634
+
635
+ return numbits;
636
+ }
637
+
638
+ static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0};
639
+ static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
640
+
641
+ /*
642
+ * don't forget to apply the same changes to III_dequantize_sample_ms() !!!
643
+ */
644
+ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
645
+ struct gr_info_s *gr_info,int sfreq,int part2bits)
646
+ {
647
+ int shift = 1 + gr_info->scalefac_scale;
648
+ real *xrpnt = (real *) xr;
649
+ int l[3],l3;
650
+ int part2remain = gr_info->part2_3_length - part2bits;
651
+ int *me;
652
+
653
+ {
654
+ int bv = gr_info->big_values;
655
+ int region1 = gr_info->region1start;
656
+ int region2 = gr_info->region2start;
657
+
658
+ l3 = ((576>>1)-bv)>>1;
659
+ /*
660
+ * we may lose the 'odd' bit here !!
661
+ * check this later again
662
+ */
663
+ if(bv <= region1) {
664
+ l[0] = bv; l[1] = 0; l[2] = 0;
665
+ }
666
+ else {
667
+ l[0] = region1;
668
+ if(bv <= region2) {
669
+ l[1] = bv - l[0]; l[2] = 0;
670
+ }
671
+ else {
672
+ l[1] = region2 - l[0]; l[2] = bv - region2;
673
+ }
674
+ }
675
+ }
676
+
677
+ if(gr_info->block_type == 2) {
678
+ /*
679
+ * decoding with short or mixed mode BandIndex table
680
+ */
681
+ int i,max[4];
682
+ int step=0,lwin=0,cb=0;
683
+ register real v = 0.0;
684
+ register int *m,mc;
685
+
686
+ if(gr_info->mixed_block_flag) {
687
+ max[3] = -1;
688
+ max[0] = max[1] = max[2] = 2;
689
+ m = map[sfreq][0];
690
+ me = mapend[sfreq][0];
691
+ }
692
+ else {
693
+ max[0] = max[1] = max[2] = max[3] = -1;
694
+ /* max[3] not really needed in this case */
695
+ m = map[sfreq][1];
696
+ me = mapend[sfreq][1];
697
+ }
698
+
699
+ mc = 0;
700
+ for(i=0;i<2;i++) {
701
+ int lp = l[i];
702
+ struct newhuff *h = ht+gr_info->table_select[i];
703
+ for(;lp;lp--,mc--) {
704
+ register int x,y;
705
+ if( (!mc) ) {
706
+ mc = *m++;
707
+ xrpnt = ((real *) xr) + (*m++);
708
+ lwin = *m++;
709
+ cb = *m++;
710
+ if(lwin == 3) {
711
+ v = gr_info->pow2gain[(*scf++) << shift];
712
+ step = 1;
713
+ }
714
+ else {
715
+ v = gr_info->full_gain[lwin][(*scf++) << shift];
716
+ step = 3;
717
+ }
718
+ }
719
+ {
720
+ register short *val = h->table;
721
+ while((y=*val++)<0) {
722
+ if (get1bit())
723
+ val -= y;
724
+ part2remain--;
725
+ }
726
+ x = y >> 4;
727
+ y &= 0xf;
728
+ }
729
+ if(x == 15) {
730
+ max[lwin] = cb;
731
+ part2remain -= h->linbits+1;
732
+ x += getbits(h->linbits);
733
+ if(get1bit())
734
+ *xrpnt = -ispow[x] * v;
735
+ else
736
+ *xrpnt = ispow[x] * v;
737
+ }
738
+ else if(x) {
739
+ max[lwin] = cb;
740
+ if(get1bit())
741
+ *xrpnt = -ispow[x] * v;
742
+ else
743
+ *xrpnt = ispow[x] * v;
744
+ part2remain--;
745
+ }
746
+ else
747
+ *xrpnt = 0.0;
748
+ xrpnt += step;
749
+ if(y == 15) {
750
+ max[lwin] = cb;
751
+ part2remain -= h->linbits+1;
752
+ y += getbits(h->linbits);
753
+ if(get1bit())
754
+ *xrpnt = -ispow[y] * v;
755
+ else
756
+ *xrpnt = ispow[y] * v;
757
+ }
758
+ else if(y) {
759
+ max[lwin] = cb;
760
+ if(get1bit())
761
+ *xrpnt = -ispow[y] * v;
762
+ else
763
+ *xrpnt = ispow[y] * v;
764
+ part2remain--;
765
+ }
766
+ else
767
+ *xrpnt = 0.0;
768
+ xrpnt += step;
769
+ }
770
+ }
771
+ for(;l3 && (part2remain > 0);l3--) {
772
+ struct newhuff *h = htc+gr_info->count1table_select;
773
+ register short *val = h->table,a;
774
+
775
+ while((a=*val++)<0) {
776
+ part2remain--;
777
+ if(part2remain < 0) {
778
+ part2remain++;
779
+ a = 0;
780
+ break;
781
+ }
782
+ if (get1bit())
783
+ val -= a;
784
+ }
785
+
786
+ for(i=0;i<4;i++) {
787
+ if(!(i & 1)) {
788
+ if(!mc) {
789
+ mc = *m++;
790
+ xrpnt = ((real *) xr) + (*m++);
791
+ lwin = *m++;
792
+ cb = *m++;
793
+ if(lwin == 3) {
794
+ v = gr_info->pow2gain[(*scf++) << shift];
795
+ step = 1;
796
+ }
797
+ else {
798
+ v = gr_info->full_gain[lwin][(*scf++) << shift];
799
+ step = 3;
800
+ }
801
+ }
802
+ mc--;
803
+ }
804
+ if( (a & (0x8>>i)) ) {
805
+ max[lwin] = cb;
806
+ part2remain--;
807
+ if(part2remain < 0) {
808
+ part2remain++;
809
+ break;
810
+ }
811
+ if(get1bit())
812
+ *xrpnt = -v;
813
+ else
814
+ *xrpnt = v;
815
+ }
816
+ else
817
+ *xrpnt = 0.0;
818
+ xrpnt += step;
819
+ }
820
+ }
821
+
822
+ while( m < me ) {
823
+ if(!mc) {
824
+ mc = *m++;
825
+ xrpnt = ((real *) xr) + *m++;
826
+ if( (*m++) == 3)
827
+ step = 1;
828
+ else
829
+ step = 3;
830
+ m++; /* cb */
831
+ }
832
+ mc--;
833
+ *xrpnt = 0.0;
834
+ xrpnt += step;
835
+ *xrpnt = 0.0;
836
+ xrpnt += step;
837
+ /* we could add a little opt. here:
838
+ * if we finished a band for window 3 or a long band
839
+ * further bands could copied in a simple loop without a
840
+ * special 'map' decoding
841
+ */
842
+ }
843
+
844
+ gr_info->maxband[0] = max[0]+1;
845
+ gr_info->maxband[1] = max[1]+1;
846
+ gr_info->maxband[2] = max[2]+1;
847
+ gr_info->maxbandl = max[3]+1;
848
+
849
+ {
850
+ int rmax = max[0] > max[1] ? max[0] : max[1];
851
+ rmax = (rmax > max[2] ? rmax : max[2]) + 1;
852
+ gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1];
853
+ }
854
+
855
+ }
856
+ else {
857
+ /*
858
+ * decoding with 'long' BandIndex table (block_type != 2)
859
+ */
860
+ int *pretab = gr_info->preflag ? pretab1 : pretab2;
861
+ int i,max = -1;
862
+ int cb = 0;
863
+ register int *m = map[sfreq][2];
864
+ register real v = 0.0;
865
+ register int mc = 0;
866
+ #if 0
867
+ me = mapend[sfreq][2];
868
+ #endif
869
+
870
+ /*
871
+ * long hash table values
872
+ */
873
+ for(i=0;i<3;i++) {
874
+ int lp = l[i];
875
+ struct newhuff *h = ht+gr_info->table_select[i];
876
+
877
+ for(;lp;lp--,mc--) {
878
+ int x,y;
879
+
880
+ if(!mc) {
881
+ mc = *m++;
882
+ v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
883
+ cb = *m++;
884
+ }
885
+ {
886
+ register short *val = h->table;
887
+ while((y=*val++)<0) {
888
+ if (get1bit())
889
+ val -= y;
890
+ part2remain--;
891
+ }
892
+ x = y >> 4;
893
+ y &= 0xf;
894
+ }
895
+ if (x == 15) {
896
+ max = cb;
897
+ part2remain -= h->linbits+1;
898
+ x += getbits(h->linbits);
899
+ if(get1bit())
900
+ *xrpnt++ = -ispow[x] * v;
901
+ else
902
+ *xrpnt++ = ispow[x] * v;
903
+ }
904
+ else if(x) {
905
+ max = cb;
906
+ if(get1bit())
907
+ *xrpnt++ = -ispow[x] * v;
908
+ else
909
+ *xrpnt++ = ispow[x] * v;
910
+ part2remain--;
911
+ }
912
+ else
913
+ *xrpnt++ = 0.0;
914
+
915
+ if (y == 15) {
916
+ max = cb;
917
+ part2remain -= h->linbits+1;
918
+ y += getbits(h->linbits);
919
+ if(get1bit())
920
+ *xrpnt++ = -ispow[y] * v;
921
+ else
922
+ *xrpnt++ = ispow[y] * v;
923
+ }
924
+ else if(y) {
925
+ max = cb;
926
+ if(get1bit())
927
+ *xrpnt++ = -ispow[y] * v;
928
+ else
929
+ *xrpnt++ = ispow[y] * v;
930
+ part2remain--;
931
+ }
932
+ else
933
+ *xrpnt++ = 0.0;
934
+ }
935
+ }
936
+
937
+ /*
938
+ * short (count1table) values
939
+ */
940
+ for(;l3 && (part2remain > 0);l3--) {
941
+ struct newhuff *h = htc+gr_info->count1table_select;
942
+ register short *val = h->table,a;
943
+
944
+ while((a=*val++)<0) {
945
+ part2remain--;
946
+ if(part2remain < 0) {
947
+ part2remain++;
948
+ a = 0;
949
+ break;
950
+ }
951
+ if (get1bit())
952
+ val -= a;
953
+ }
954
+
955
+ for(i=0;i<4;i++) {
956
+ if(!(i & 1)) {
957
+ if(!mc) {
958
+ mc = *m++;
959
+ cb = *m++;
960
+ v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
961
+ }
962
+ mc--;
963
+ }
964
+ if ( (a & (0x8>>i)) ) {
965
+ max = cb;
966
+ part2remain--;
967
+ if(part2remain < 0) {
968
+ part2remain++;
969
+ break;
970
+ }
971
+ if(get1bit())
972
+ *xrpnt++ = -v;
973
+ else
974
+ *xrpnt++ = v;
975
+ }
976
+ else
977
+ *xrpnt++ = 0.0;
978
+ }
979
+ }
980
+
981
+ /*
982
+ * zero part
983
+ */
984
+ for(i=(&xr[SBLIMIT][0]-xrpnt)>>1;i;i--) {
985
+ *xrpnt++ = 0.0;
986
+ *xrpnt++ = 0.0;
987
+ }
988
+
989
+ gr_info->maxbandl = max+1;
990
+ gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
991
+ }
992
+
993
+ while( part2remain > 16 ) {
994
+ getbits(16); /* Dismiss stuffing Bits */
995
+ part2remain -= 16;
996
+ }
997
+ if(part2remain > 0)
998
+ getbits(part2remain);
999
+ else if(part2remain < 0) {
1000
+ fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain);
1001
+ return 1; /* -> error */
1002
+ }
1003
+ return 0;
1004
+ }
1005
+
1006
+ #if 0
1007
+ static int III_dequantize_sample_ms(real xr[2][SBLIMIT][SSLIMIT],int *scf,
1008
+ struct gr_info_s *gr_info,int sfreq,int part2bits)
1009
+ {
1010
+ int shift = 1 + gr_info->scalefac_scale;
1011
+ real *xrpnt = (real *) xr[1];
1012
+ real *xr0pnt = (real *) xr[0];
1013
+ int l[3],l3;
1014
+ int part2remain = gr_info->part2_3_length - part2bits;
1015
+ int *me;
1016
+
1017
+ {
1018
+ int bv = gr_info->big_values;
1019
+ int region1 = gr_info->region1start;
1020
+ int region2 = gr_info->region2start;
1021
+
1022
+ l3 = ((576>>1)-bv)>>1;
1023
+ /*
1024
+ * we may lose the 'odd' bit here !!
1025
+ * check this later gain
1026
+ */
1027
+ if(bv <= region1) {
1028
+ l[0] = bv; l[1] = 0; l[2] = 0;
1029
+ }
1030
+ else {
1031
+ l[0] = region1;
1032
+ if(bv <= region2) {
1033
+ l[1] = bv - l[0]; l[2] = 0;
1034
+ }
1035
+ else {
1036
+ l[1] = region2 - l[0]; l[2] = bv - region2;
1037
+ }
1038
+ }
1039
+ }
1040
+
1041
+ if(gr_info->block_type == 2) {
1042
+ int i,max[4];
1043
+ int step=0,lwin=0,cb=0;
1044
+ register real v = 0.0;
1045
+ register int *m,mc = 0;
1046
+
1047
+ if(gr_info->mixed_block_flag) {
1048
+ max[3] = -1;
1049
+ max[0] = max[1] = max[2] = 2;
1050
+ m = map[sfreq][0];
1051
+ me = mapend[sfreq][0];
1052
+ }
1053
+ else {
1054
+ max[0] = max[1] = max[2] = max[3] = -1;
1055
+ /* max[3] not really needed in this case */
1056
+ m = map[sfreq][1];
1057
+ me = mapend[sfreq][1];
1058
+ }
1059
+
1060
+ for(i=0;i<2;i++) {
1061
+ int lp = l[i];
1062
+ struct newhuff *h = ht+gr_info->table_select[i];
1063
+ for(;lp;lp--,mc--) {
1064
+ int x,y;
1065
+
1066
+ if(!mc) {
1067
+ mc = *m++;
1068
+ xrpnt = ((real *) xr[1]) + *m;
1069
+ xr0pnt = ((real *) xr[0]) + *m++;
1070
+ lwin = *m++;
1071
+ cb = *m++;
1072
+ if(lwin == 3) {
1073
+ v = gr_info->pow2gain[(*scf++) << shift];
1074
+ step = 1;
1075
+ }
1076
+ else {
1077
+ v = gr_info->full_gain[lwin][(*scf++) << shift];
1078
+ step = 3;
1079
+ }
1080
+ }
1081
+ {
1082
+ register short *val = h->table;
1083
+ while((y=*val++)<0) {
1084
+ if (get1bit())
1085
+ val -= y;
1086
+ part2remain--;
1087
+ }
1088
+ x = y >> 4;
1089
+ y &= 0xf;
1090
+ }
1091
+ if(x == 15) {
1092
+ max[lwin] = cb;
1093
+ part2remain -= h->linbits+1;
1094
+ x += getbits(h->linbits);
1095
+ if(get1bit()) {
1096
+ real a = ispow[x] * v;
1097
+ *xrpnt = *xr0pnt + a;
1098
+ *xr0pnt -= a;
1099
+ }
1100
+ else {
1101
+ real a = ispow[x] * v;
1102
+ *xrpnt = *xr0pnt - a;
1103
+ *xr0pnt += a;
1104
+ }
1105
+ }
1106
+ else if(x) {
1107
+ max[lwin] = cb;
1108
+ if(get1bit()) {
1109
+ real a = ispow[x] * v;
1110
+ *xrpnt = *xr0pnt + a;
1111
+ *xr0pnt -= a;
1112
+ }
1113
+ else {
1114
+ real a = ispow[x] * v;
1115
+ *xrpnt = *xr0pnt - a;
1116
+ *xr0pnt += a;
1117
+ }
1118
+ part2remain--;
1119
+ }
1120
+ else
1121
+ *xrpnt = *xr0pnt;
1122
+ xrpnt += step;
1123
+ xr0pnt += step;
1124
+
1125
+ if(y == 15) {
1126
+ max[lwin] = cb;
1127
+ part2remain -= h->linbits+1;
1128
+ y += getbits(h->linbits);
1129
+ if(get1bit()) {
1130
+ real a = ispow[y] * v;
1131
+ *xrpnt = *xr0pnt + a;
1132
+ *xr0pnt -= a;
1133
+ }
1134
+ else {
1135
+ real a = ispow[y] * v;
1136
+ *xrpnt = *xr0pnt - a;
1137
+ *xr0pnt += a;
1138
+ }
1139
+ }
1140
+ else if(y) {
1141
+ max[lwin] = cb;
1142
+ if(get1bit()) {
1143
+ real a = ispow[y] * v;
1144
+ *xrpnt = *xr0pnt + a;
1145
+ *xr0pnt -= a;
1146
+ }
1147
+ else {
1148
+ real a = ispow[y] * v;
1149
+ *xrpnt = *xr0pnt - a;
1150
+ *xr0pnt += a;
1151
+ }
1152
+ part2remain--;
1153
+ }
1154
+ else
1155
+ *xrpnt = *xr0pnt;
1156
+ xrpnt += step;
1157
+ xr0pnt += step;
1158
+ }
1159
+ }
1160
+
1161
+ for(;l3 && (part2remain > 0);l3--) {
1162
+ struct newhuff *h = htc+gr_info->count1table_select;
1163
+ register short *val = h->table,a;
1164
+
1165
+ while((a=*val++)<0) {
1166
+ part2remain--;
1167
+ if(part2remain < 0) {
1168
+ part2remain++;
1169
+ a = 0;
1170
+ break;
1171
+ }
1172
+ if (get1bit())
1173
+ val -= a;
1174
+ }
1175
+
1176
+ for(i=0;i<4;i++) {
1177
+ if(!(i & 1)) {
1178
+ if(!mc) {
1179
+ mc = *m++;
1180
+ xrpnt = ((real *) xr[1]) + *m;
1181
+ xr0pnt = ((real *) xr[0]) + *m++;
1182
+ lwin = *m++;
1183
+ cb = *m++;
1184
+ if(lwin == 3) {
1185
+ v = gr_info->pow2gain[(*scf++) << shift];
1186
+ step = 1;
1187
+ }
1188
+ else {
1189
+ v = gr_info->full_gain[lwin][(*scf++) << shift];
1190
+ step = 3;
1191
+ }
1192
+ }
1193
+ mc--;
1194
+ }
1195
+ if( (a & (0x8>>i)) ) {
1196
+ max[lwin] = cb;
1197
+ part2remain--;
1198
+ if(part2remain < 0) {
1199
+ part2remain++;
1200
+ break;
1201
+ }
1202
+ if(get1bit()) {
1203
+ *xrpnt = *xr0pnt + v;
1204
+ *xr0pnt -= v;
1205
+ }
1206
+ else {
1207
+ *xrpnt = *xr0pnt - v;
1208
+ *xr0pnt += v;
1209
+ }
1210
+ }
1211
+ else
1212
+ *xrpnt = *xr0pnt;
1213
+ xrpnt += step;
1214
+ xr0pnt += step;
1215
+ }
1216
+ }
1217
+
1218
+ while( m < me ) {
1219
+ if(!mc) {
1220
+ mc = *m++;
1221
+ xrpnt = ((real *) xr[1]) + *m;
1222
+ xr0pnt = ((real *) xr[0]) + *m++;
1223
+ if(*m++ == 3)
1224
+ step = 1;
1225
+ else
1226
+ step = 3;
1227
+ m++; /* cb */
1228
+ }
1229
+ mc--;
1230
+ *xrpnt = *xr0pnt;
1231
+ xrpnt += step;
1232
+ xr0pnt += step;
1233
+ *xrpnt = *xr0pnt;
1234
+ xrpnt += step;
1235
+ xr0pnt += step;
1236
+ /* we could add a little opt. here:
1237
+ * if we finished a band for window 3 or a long band
1238
+ * further bands could copied in a simple loop without a
1239
+ * special 'map' decoding
1240
+ */
1241
+ }
1242
+
1243
+ gr_info->maxband[0] = max[0]+1;
1244
+ gr_info->maxband[1] = max[1]+1;
1245
+ gr_info->maxband[2] = max[2]+1;
1246
+ gr_info->maxbandl = max[3]+1;
1247
+
1248
+ {
1249
+ int rmax = max[0] > max[1] ? max[0] : max[1];
1250
+ rmax = (rmax > max[2] ? rmax : max[2]) + 1;
1251
+ gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1];
1252
+ }
1253
+ }
1254
+ else {
1255
+ int *pretab = gr_info->preflag ? pretab1 : pretab2;
1256
+ int i,max = -1;
1257
+ int cb = 0;
1258
+ register int mc=0,*m = map[sfreq][2];
1259
+ register real v = 0.0;
1260
+ #if 0
1261
+ me = mapend[sfreq][2];
1262
+ #endif
1263
+
1264
+ for(i=0;i<3;i++) {
1265
+ int lp = l[i];
1266
+ struct newhuff *h = ht+gr_info->table_select[i];
1267
+
1268
+ for(;lp;lp--,mc--) {
1269
+ int x,y;
1270
+ if(!mc) {
1271
+ mc = *m++;
1272
+ cb = *m++;
1273
+ v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
1274
+ }
1275
+ {
1276
+ register short *val = h->table;
1277
+ while((y=*val++)<0) {
1278
+ if (get1bit())
1279
+ val -= y;
1280
+ part2remain--;
1281
+ }
1282
+ x = y >> 4;
1283
+ y &= 0xf;
1284
+ }
1285
+ if (x == 15) {
1286
+ max = cb;
1287
+ part2remain -= h->linbits+1;
1288
+ x += getbits(h->linbits);
1289
+ if(get1bit()) {
1290
+ real a = ispow[x] * v;
1291
+ *xrpnt++ = *xr0pnt + a;
1292
+ *xr0pnt++ -= a;
1293
+ }
1294
+ else {
1295
+ real a = ispow[x] * v;
1296
+ *xrpnt++ = *xr0pnt - a;
1297
+ *xr0pnt++ += a;
1298
+ }
1299
+ }
1300
+ else if(x) {
1301
+ max = cb;
1302
+ if(get1bit()) {
1303
+ real a = ispow[x] * v;
1304
+ *xrpnt++ = *xr0pnt + a;
1305
+ *xr0pnt++ -= a;
1306
+ }
1307
+ else {
1308
+ real a = ispow[x] * v;
1309
+ *xrpnt++ = *xr0pnt - a;
1310
+ *xr0pnt++ += a;
1311
+ }
1312
+ part2remain--;
1313
+ }
1314
+ else
1315
+ *xrpnt++ = *xr0pnt++;
1316
+
1317
+ if (y == 15) {
1318
+ max = cb;
1319
+ part2remain -= h->linbits+1;
1320
+ y += getbits(h->linbits);
1321
+ if(get1bit()) {
1322
+ real a = ispow[y] * v;
1323
+ *xrpnt++ = *xr0pnt + a;
1324
+ *xr0pnt++ -= a;
1325
+ }
1326
+ else {
1327
+ real a = ispow[y] * v;
1328
+ *xrpnt++ = *xr0pnt - a;
1329
+ *xr0pnt++ += a;
1330
+ }
1331
+ }
1332
+ else if(y) {
1333
+ max = cb;
1334
+ if(get1bit()) {
1335
+ real a = ispow[y] * v;
1336
+ *xrpnt++ = *xr0pnt + a;
1337
+ *xr0pnt++ -= a;
1338
+ }
1339
+ else {
1340
+ real a = ispow[y] * v;
1341
+ *xrpnt++ = *xr0pnt - a;
1342
+ *xr0pnt++ += a;
1343
+ }
1344
+ part2remain--;
1345
+ }
1346
+ else
1347
+ *xrpnt++ = *xr0pnt++;
1348
+ }
1349
+ }
1350
+
1351
+ for(;l3 && (part2remain > 0);l3--) {
1352
+ struct newhuff *h = htc+gr_info->count1table_select;
1353
+ register short *val = h->table,a;
1354
+
1355
+ while((a=*val++)<0) {
1356
+ part2remain--;
1357
+ if(part2remain < 0) {
1358
+ part2remain++;
1359
+ a = 0;
1360
+ break;
1361
+ }
1362
+ if (get1bit())
1363
+ val -= a;
1364
+ }
1365
+
1366
+ for(i=0;i<4;i++) {
1367
+ if(!(i & 1)) {
1368
+ if(!mc) {
1369
+ mc = *m++;
1370
+ cb = *m++;
1371
+ v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
1372
+ }
1373
+ mc--;
1374
+ }
1375
+ if ( (a & (0x8>>i)) ) {
1376
+ max = cb;
1377
+ part2remain--;
1378
+ if(part2remain <= 0) {
1379
+ part2remain++;
1380
+ break;
1381
+ }
1382
+ if(get1bit()) {
1383
+ *xrpnt++ = *xr0pnt + v;
1384
+ *xr0pnt++ -= v;
1385
+ }
1386
+ else {
1387
+ *xrpnt++ = *xr0pnt - v;
1388
+ *xr0pnt++ += v;
1389
+ }
1390
+ }
1391
+ else
1392
+ *xrpnt++ = *xr0pnt++;
1393
+ }
1394
+ }
1395
+ for(i=(&xr[1][SBLIMIT][0]-xrpnt)>>1;i;i--) {
1396
+ *xrpnt++ = *xr0pnt++;
1397
+ *xrpnt++ = *xr0pnt++;
1398
+ }
1399
+
1400
+ gr_info->maxbandl = max+1;
1401
+ gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
1402
+ }
1403
+
1404
+ while ( part2remain > 16 ) {
1405
+ getbits(16); /* Dismiss stuffing Bits */
1406
+ part2remain -= 16;
1407
+ }
1408
+ if(part2remain > 0 )
1409
+ getbits(part2remain);
1410
+ else if(part2remain < 0) {
1411
+ fprintf(stderr,"mpg123_ms: Can't rewind stream by %d bits!\n",-part2remain);
1412
+ return 1; /* -> error */
1413
+ }
1414
+ return 0;
1415
+ }
1416
+ #endif
1417
+
1418
+ /*
1419
+ * III_stereo: calculate real channel values for Joint-I-Stereo-mode
1420
+ */
1421
+ static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
1422
+ struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf)
1423
+ {
1424
+ real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf;
1425
+ struct bandInfoStruct *bi = &bandInfo[sfreq];
1426
+ real *tab1,*tab2;
1427
+
1428
+ if(lsf) {
1429
+ int p = gr_info->scalefac_compress & 0x1;
1430
+ if(ms_stereo) {
1431
+ tab1 = pow1_2[p]; tab2 = pow2_2[p];
1432
+ }
1433
+ else {
1434
+ tab1 = pow1_1[p]; tab2 = pow2_1[p];
1435
+ }
1436
+ }
1437
+ else {
1438
+ if(ms_stereo) {
1439
+ tab1 = tan1_2; tab2 = tan2_2;
1440
+ }
1441
+ else {
1442
+ tab1 = tan1_1; tab2 = tan2_1;
1443
+ }
1444
+ }
1445
+
1446
+ if (gr_info->block_type == 2)
1447
+ {
1448
+ int lwin,do_l = 0;
1449
+ if( gr_info->mixed_block_flag )
1450
+ do_l = 1;
1451
+
1452
+ for (lwin=0;lwin<3;lwin++) /* process each window */
1453
+ {
1454
+ /* get first band with zero values */
1455
+ int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */
1456
+ if(sfb > 3)
1457
+ do_l = 0;
1458
+
1459
+ for(;sfb<12;sfb++)
1460
+ {
1461
+ is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
1462
+ if(is_p != 7) {
1463
+ real t1,t2;
1464
+ sb = bi->shortDiff[sfb];
1465
+ idx = bi->shortIdx[sfb] + lwin;
1466
+ t1 = tab1[is_p]; t2 = tab2[is_p];
1467
+ for (; sb > 0; sb--,idx+=3)
1468
+ {
1469
+ real v = xr[0][idx];
1470
+ xr[0][idx] = v * t1;
1471
+ xr[1][idx] = v * t2;
1472
+ }
1473
+ }
1474
+ }
1475
+
1476
+ #if 1
1477
+ /* in the original: copy 10 to 11 , here: copy 11 to 12
1478
+ maybe still wrong??? (copy 12 to 13?) */
1479
+ is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
1480
+ sb = bi->shortDiff[12];
1481
+ idx = bi->shortIdx[12] + lwin;
1482
+ #else
1483
+ is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
1484
+ sb = bi->shortDiff[11];
1485
+ idx = bi->shortIdx[11] + lwin;
1486
+ #endif
1487
+ if(is_p != 7)
1488
+ {
1489
+ real t1,t2;
1490
+ t1 = tab1[is_p]; t2 = tab2[is_p];
1491
+ for ( ; sb > 0; sb--,idx+=3 )
1492
+ {
1493
+ real v = xr[0][idx];
1494
+ xr[0][idx] = v * t1;
1495
+ xr[1][idx] = v * t2;
1496
+ }
1497
+ }
1498
+ } /* end for(lwin; .. ; . ) */
1499
+
1500
+ if (do_l)
1501
+ {
1502
+ /* also check l-part, if ALL bands in the three windows are 'empty'
1503
+ * and mode = mixed_mode
1504
+ */
1505
+ int sfb = gr_info->maxbandl;
1506
+ int idx = bi->longIdx[sfb];
1507
+
1508
+ for ( ; sfb<8; sfb++ )
1509
+ {
1510
+ int sb = bi->longDiff[sfb];
1511
+ int is_p = scalefac[sfb]; /* scale: 0-15 */
1512
+ if(is_p != 7) {
1513
+ real t1,t2;
1514
+ t1 = tab1[is_p]; t2 = tab2[is_p];
1515
+ for ( ; sb > 0; sb--,idx++)
1516
+ {
1517
+ real v = xr[0][idx];
1518
+ xr[0][idx] = v * t1;
1519
+ xr[1][idx] = v * t2;
1520
+ }
1521
+ }
1522
+ else
1523
+ idx += sb;
1524
+ }
1525
+ }
1526
+ }
1527
+ else /* ((gr_info->block_type != 2)) */
1528
+ {
1529
+ int sfb = gr_info->maxbandl;
1530
+ int is_p,idx = bi->longIdx[sfb];
1531
+ for ( ; sfb<21; sfb++)
1532
+ {
1533
+ int sb = bi->longDiff[sfb];
1534
+ is_p = scalefac[sfb]; /* scale: 0-15 */
1535
+ if(is_p != 7) {
1536
+ real t1,t2;
1537
+ t1 = tab1[is_p]; t2 = tab2[is_p];
1538
+ for ( ; sb > 0; sb--,idx++)
1539
+ {
1540
+ real v = xr[0][idx];
1541
+ xr[0][idx] = v * t1;
1542
+ xr[1][idx] = v * t2;
1543
+ }
1544
+ }
1545
+ else
1546
+ idx += sb;
1547
+ }
1548
+
1549
+ is_p = scalefac[20]; /* copy l-band 20 to l-band 21 */
1550
+ if(is_p != 7)
1551
+ {
1552
+ int sb;
1553
+ real t1 = tab1[is_p],t2 = tab2[is_p];
1554
+
1555
+ for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ )
1556
+ {
1557
+ real v = xr[0][idx];
1558
+ xr[0][idx] = v * t1;
1559
+ xr[1][idx] = v * t2;
1560
+ }
1561
+ }
1562
+ } /* ... */
1563
+ }
1564
+
1565
+ static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info)
1566
+ {
1567
+ int sblim;
1568
+
1569
+ if(gr_info->block_type == 2)
1570
+ {
1571
+ if(!gr_info->mixed_block_flag)
1572
+ return;
1573
+ sblim = 1;
1574
+ }
1575
+ else {
1576
+ sblim = gr_info->maxb-1;
1577
+ }
1578
+
1579
+ /* 31 alias-reduction operations between each pair of sub-bands */
1580
+ /* with 8 butterflies between each pair */
1581
+
1582
+ {
1583
+ int sb;
1584
+ real *xr1=(real *) xr[1];
1585
+
1586
+ for(sb=sblim;sb;sb--,xr1+=10)
1587
+ {
1588
+ int ss;
1589
+ real *cs=aa_cs,*ca=aa_ca;
1590
+ real *xr2 = xr1;
1591
+
1592
+ for(ss=7;ss>=0;ss--)
1593
+ { /* upper and lower butterfly inputs */
1594
+ register real bu = *--xr2,bd = *xr1;
1595
+ *xr2 = (bu * (*cs) ) - (bd * (*ca) );
1596
+ *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) );
1597
+ }
1598
+ }
1599
+ }
1600
+ }
1601
+
1602
+ /*
1603
+ DCT insipired by Jeff Tsay's DCT from the maplay package
1604
+ this is an optimized version with manual unroll.
1605
+
1606
+ References:
1607
+ [1] S. Winograd: "On Computing the Discrete Fourier Transform",
1608
+ Mathematics of Computation, Volume 32, Number 141, January 1978,
1609
+ Pages 175-199
1610
+ */
1611
+
1612
+ static void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
1613
+ {
1614
+ {
1615
+ register real *in = inbuf;
1616
+
1617
+ in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14];
1618
+ in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11];
1619
+ in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8];
1620
+ in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5];
1621
+ in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2];
1622
+ in[2] +=in[1]; in[1] +=in[0];
1623
+
1624
+ in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9];
1625
+ in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1];
1626
+
1627
+
1628
+ {
1629
+
1630
+ #define MACRO0(v) { \
1631
+ real tmp; \
1632
+ out2[9+(v)] = (tmp = sum0 + sum1) * w[27+(v)]; \
1633
+ out2[8-(v)] = tmp * w[26-(v)]; } \
1634
+ sum0 -= sum1; \
1635
+ ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
1636
+ ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)];
1637
+ #define MACRO1(v) { \
1638
+ real sum0,sum1; \
1639
+ sum0 = tmp1a + tmp2a; \
1640
+ sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \
1641
+ MACRO0(v); }
1642
+ #define MACRO2(v) { \
1643
+ real sum0,sum1; \
1644
+ sum0 = tmp2a - tmp1a; \
1645
+ sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \
1646
+ MACRO0(v); }
1647
+
1648
+ register const real *c = COS9;
1649
+ register real *out2 = o2;
1650
+ register real *w = wintab;
1651
+ register real *out1 = o1;
1652
+ register real *ts = tsbuf;
1653
+
1654
+ real ta33,ta66,tb33,tb66;
1655
+
1656
+ ta33 = in[2*3+0] * c[3];
1657
+ ta66 = in[2*6+0] * c[6];
1658
+ tb33 = in[2*3+1] * c[3];
1659
+ tb66 = in[2*6+1] * c[6];
1660
+
1661
+ {
1662
+ real tmp1a,tmp2a,tmp1b,tmp2b;
1663
+ tmp1a = in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7];
1664
+ tmp1b = in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7];
1665
+ tmp2a = in[2*0+0] + in[2*2+0] * c[2] + in[2*4+0] * c[4] + ta66 + in[2*8+0] * c[8];
1666
+ tmp2b = in[2*0+1] + in[2*2+1] * c[2] + in[2*4+1] * c[4] + tb66 + in[2*8+1] * c[8];
1667
+
1668
+ MACRO1(0);
1669
+ MACRO2(8);
1670
+ }
1671
+
1672
+ {
1673
+ real tmp1a,tmp2a,tmp1b,tmp2b;
1674
+ tmp1a = ( in[2*1+0] - in[2*5+0] - in[2*7+0] ) * c[3];
1675
+ tmp1b = ( in[2*1+1] - in[2*5+1] - in[2*7+1] ) * c[3];
1676
+ tmp2a = ( in[2*2+0] - in[2*4+0] - in[2*8+0] ) * c[6] - in[2*6+0] + in[2*0+0];
1677
+ tmp2b = ( in[2*2+1] - in[2*4+1] - in[2*8+1] ) * c[6] - in[2*6+1] + in[2*0+1];
1678
+
1679
+ MACRO1(1);
1680
+ MACRO2(7);
1681
+ }
1682
+
1683
+ {
1684
+ real tmp1a,tmp2a,tmp1b,tmp2b;
1685
+ tmp1a = in[2*1+0] * c[5] - ta33 - in[2*5+0] * c[7] + in[2*7+0] * c[1];
1686
+ tmp1b = in[2*1+1] * c[5] - tb33 - in[2*5+1] * c[7] + in[2*7+1] * c[1];
1687
+ tmp2a = in[2*0+0] - in[2*2+0] * c[8] - in[2*4+0] * c[2] + ta66 + in[2*8+0] * c[4];
1688
+ tmp2b = in[2*0+1] - in[2*2+1] * c[8] - in[2*4+1] * c[2] + tb66 + in[2*8+1] * c[4];
1689
+
1690
+ MACRO1(2);
1691
+ MACRO2(6);
1692
+ }
1693
+
1694
+ {
1695
+ real tmp1a,tmp2a,tmp1b,tmp2b;
1696
+ tmp1a = in[2*1+0] * c[7] - ta33 + in[2*5+0] * c[1] - in[2*7+0] * c[5];
1697
+ tmp1b = in[2*1+1] * c[7] - tb33 + in[2*5+1] * c[1] - in[2*7+1] * c[5];
1698
+ tmp2a = in[2*0+0] - in[2*2+0] * c[4] + in[2*4+0] * c[8] + ta66 - in[2*8+0] * c[2];
1699
+ tmp2b = in[2*0+1] - in[2*2+1] * c[4] + in[2*4+1] * c[8] + tb66 - in[2*8+1] * c[2];
1700
+
1701
+ MACRO1(3);
1702
+ MACRO2(5);
1703
+ }
1704
+
1705
+ {
1706
+ real sum0,sum1;
1707
+ sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
1708
+ sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4];
1709
+ MACRO0(4);
1710
+ }
1711
+ }
1712
+
1713
+ }
1714
+ }
1715
+
1716
+ /*
1717
+ * new DCT12
1718
+ */
1719
+ static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts)
1720
+ {
1721
+ #define DCT12_PART1 \
1722
+ in5 = in[5*3]; \
1723
+ in5 += (in4 = in[4*3]); \
1724
+ in4 += (in3 = in[3*3]); \
1725
+ in3 += (in2 = in[2*3]); \
1726
+ in2 += (in1 = in[1*3]); \
1727
+ in1 += (in0 = in[0*3]); \
1728
+ \
1729
+ in5 += in3; in3 += in1; \
1730
+ \
1731
+ in2 *= COS6_1; \
1732
+ in3 *= COS6_1; \
1733
+
1734
+ #define DCT12_PART2 \
1735
+ in0 += in4 * COS6_2; \
1736
+ \
1737
+ in4 = in0 + in2; \
1738
+ in0 -= in2; \
1739
+ \
1740
+ in1 += in5 * COS6_2; \
1741
+ \
1742
+ in5 = (in1 + in3) * tfcos12[0]; \
1743
+ in1 = (in1 - in3) * tfcos12[2]; \
1744
+ \
1745
+ in3 = in4 + in5; \
1746
+ in4 -= in5; \
1747
+ \
1748
+ in2 = in0 + in1; \
1749
+ in0 -= in1;
1750
+
1751
+
1752
+ {
1753
+ real in0,in1,in2,in3,in4,in5;
1754
+ register real *out1 = rawout1;
1755
+ ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
1756
+ ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
1757
+
1758
+ DCT12_PART1
1759
+
1760
+ {
1761
+ real tmp0,tmp1 = (in0 - in4);
1762
+ {
1763
+ real tmp2 = (in1 - in5) * tfcos12[1];
1764
+ tmp0 = tmp1 + tmp2;
1765
+ tmp1 -= tmp2;
1766
+ }
1767
+ ts[(17-1)*SBLIMIT] = out1[17-1] + tmp0 * wi[11-1];
1768
+ ts[(12+1)*SBLIMIT] = out1[12+1] + tmp0 * wi[6+1];
1769
+ ts[(6 +1)*SBLIMIT] = out1[6 +1] + tmp1 * wi[1];
1770
+ ts[(11-1)*SBLIMIT] = out1[11-1] + tmp1 * wi[5-1];
1771
+ }
1772
+
1773
+ DCT12_PART2
1774
+
1775
+ ts[(17-0)*SBLIMIT] = out1[17-0] + in2 * wi[11-0];
1776
+ ts[(12+0)*SBLIMIT] = out1[12+0] + in2 * wi[6+0];
1777
+ ts[(12+2)*SBLIMIT] = out1[12+2] + in3 * wi[6+2];
1778
+ ts[(17-2)*SBLIMIT] = out1[17-2] + in3 * wi[11-2];
1779
+
1780
+ ts[(6+0)*SBLIMIT] = out1[6+0] + in0 * wi[0];
1781
+ ts[(11-0)*SBLIMIT] = out1[11-0] + in0 * wi[5-0];
1782
+ ts[(6+2)*SBLIMIT] = out1[6+2] + in4 * wi[2];
1783
+ ts[(11-2)*SBLIMIT] = out1[11-2] + in4 * wi[5-2];
1784
+ }
1785
+
1786
+ in++;
1787
+
1788
+ {
1789
+ real in0,in1,in2,in3,in4,in5;
1790
+ register real *out2 = rawout2;
1791
+
1792
+ DCT12_PART1
1793
+
1794
+ {
1795
+ real tmp0,tmp1 = (in0 - in4);
1796
+ {
1797
+ real tmp2 = (in1 - in5) * tfcos12[1];
1798
+ tmp0 = tmp1 + tmp2;
1799
+ tmp1 -= tmp2;
1800
+ }
1801
+ out2[5-1] = tmp0 * wi[11-1];
1802
+ out2[0+1] = tmp0 * wi[6+1];
1803
+ ts[(12+1)*SBLIMIT] += tmp1 * wi[1];
1804
+ ts[(17-1)*SBLIMIT] += tmp1 * wi[5-1];
1805
+ }
1806
+
1807
+ DCT12_PART2
1808
+
1809
+ out2[5-0] = in2 * wi[11-0];
1810
+ out2[0+0] = in2 * wi[6+0];
1811
+ out2[0+2] = in3 * wi[6+2];
1812
+ out2[5-2] = in3 * wi[11-2];
1813
+
1814
+ ts[(12+0)*SBLIMIT] += in0 * wi[0];
1815
+ ts[(17-0)*SBLIMIT] += in0 * wi[5-0];
1816
+ ts[(12+2)*SBLIMIT] += in4 * wi[2];
1817
+ ts[(17-2)*SBLIMIT] += in4 * wi[5-2];
1818
+ }
1819
+
1820
+ in++;
1821
+
1822
+ {
1823
+ real in0,in1,in2,in3,in4,in5;
1824
+ register real *out2 = rawout2;
1825
+ out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0;
1826
+
1827
+ DCT12_PART1
1828
+
1829
+ {
1830
+ real tmp0,tmp1 = (in0 - in4);
1831
+ {
1832
+ real tmp2 = (in1 - in5) * tfcos12[1];
1833
+ tmp0 = tmp1 + tmp2;
1834
+ tmp1 -= tmp2;
1835
+ }
1836
+ out2[11-1] = tmp0 * wi[11-1];
1837
+ out2[6 +1] = tmp0 * wi[6+1];
1838
+ out2[0+1] += tmp1 * wi[1];
1839
+ out2[5-1] += tmp1 * wi[5-1];
1840
+ }
1841
+
1842
+ DCT12_PART2
1843
+
1844
+ out2[11-0] = in2 * wi[11-0];
1845
+ out2[6 +0] = in2 * wi[6+0];
1846
+ out2[6 +2] = in3 * wi[6+2];
1847
+ out2[11-2] = in3 * wi[11-2];
1848
+
1849
+ out2[0+0] += in0 * wi[0];
1850
+ out2[5-0] += in0 * wi[5-0];
1851
+ out2[0+2] += in4 * wi[2];
1852
+ out2[5-2] += in4 * wi[5-2];
1853
+ }
1854
+ }
1855
+
1856
+ /*
1857
+ * III_hybrid
1858
+ */
1859
+ static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT],
1860
+ int ch,struct gr_info_s *gr_info)
1861
+ {
1862
+ real *tspnt = (real *) tsOut;
1863
+ real (*block)[2][SBLIMIT*SSLIMIT] = gmp->hybrid_block;
1864
+ int *blc = gmp->hybrid_blc;
1865
+ real *rawout1,*rawout2;
1866
+ int bt;
1867
+ int sb = 0;
1868
+
1869
+ {
1870
+ int b = blc[ch];
1871
+ rawout1=block[b][ch];
1872
+ b=-b+1;
1873
+ rawout2=block[b][ch];
1874
+ blc[ch] = b;
1875
+ }
1876
+
1877
+
1878
+ if(gr_info->mixed_block_flag) {
1879
+ sb = 2;
1880
+ dct36(fsIn[0],rawout1,rawout2,win[0],tspnt);
1881
+ dct36(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
1882
+ rawout1 += 36; rawout2 += 36; tspnt += 2;
1883
+ }
1884
+
1885
+ bt = gr_info->block_type;
1886
+ if(bt == 2) {
1887
+ for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
1888
+ dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt);
1889
+ dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1);
1890
+ }
1891
+ }
1892
+ else {
1893
+ for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
1894
+ dct36(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
1895
+ dct36(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
1896
+ }
1897
+ }
1898
+
1899
+ for(;sb<SBLIMIT;sb++,tspnt++) {
1900
+ int i;
1901
+ for(i=0;i<SSLIMIT;i++) {
1902
+ tspnt[i*SBLIMIT] = *rawout1++;
1903
+ *rawout2++ = 0.0;
1904
+ }
1905
+ }
1906
+ }
1907
+
1908
+ /*
1909
+ * main layer3 handler
1910
+ */
1911
+ int do_layer3(struct frame *fr,unsigned char *pcm_sample,int *pcm_point)
1912
+ {
1913
+ int gr, ch, ss,clip=0;
1914
+ int scalefacs[39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
1915
+ struct III_sideinfo sideinfo;
1916
+ int stereo = fr->stereo;
1917
+ int single = fr->single;
1918
+ int ms_stereo,i_stereo;
1919
+ int sfreq = fr->sampling_frequency;
1920
+ int stereo1,granules;
1921
+
1922
+
1923
+
1924
+ if(stereo == 1) { /* stream is mono */
1925
+ stereo1 = 1;
1926
+ single = 0;
1927
+ }
1928
+ else if(single >= 0) /* stream is stereo, but force to mono */
1929
+ stereo1 = 1;
1930
+ else
1931
+ stereo1 = 2;
1932
+
1933
+ if(fr->mode == MPG_MD_JOINT_STEREO) {
1934
+ ms_stereo = fr->mode_ext & 0x2;
1935
+ i_stereo = fr->mode_ext & 0x1;
1936
+ }
1937
+ else
1938
+ ms_stereo = i_stereo = 0;
1939
+
1940
+
1941
+ if(fr->lsf) {
1942
+ granules = 1;
1943
+ III_get_side_info_2(&sideinfo,stereo,ms_stereo,sfreq,single);
1944
+ }
1945
+ else {
1946
+ granules = 2;
1947
+ #ifdef MPEG1
1948
+ III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single);
1949
+ #else
1950
+ fprintf(stderr,"Not supported\n");
1951
+ #endif
1952
+ }
1953
+
1954
+ if(set_pointer(sideinfo.main_data_begin) == MP3_ERR)
1955
+ return 0;
1956
+
1957
+
1958
+ for (gr=0;gr<granules;gr++)
1959
+ {
1960
+ static real hybridIn[2][SBLIMIT][SSLIMIT];
1961
+ static real hybridOut[2][SSLIMIT][SBLIMIT];
1962
+
1963
+ {
1964
+ struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
1965
+ long part2bits;
1966
+ if(fr->lsf)
1967
+ part2bits = III_get_scale_factors_2(scalefacs,gr_info,0);
1968
+ else {
1969
+ #ifdef MPEG1
1970
+ part2bits = III_get_scale_factors_1(scalefacs,gr_info);
1971
+ #else
1972
+ fprintf(stderr,"Not supported\n");
1973
+ #endif
1974
+ }
1975
+ if(III_dequantize_sample(hybridIn[0], scalefacs,gr_info,sfreq,part2bits))
1976
+ return clip;
1977
+ }
1978
+ if(stereo == 2) {
1979
+ struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
1980
+ long part2bits;
1981
+ if(fr->lsf)
1982
+ part2bits = III_get_scale_factors_2(scalefacs,gr_info,i_stereo);
1983
+ else {
1984
+ #ifdef MPEG1
1985
+ part2bits = III_get_scale_factors_1(scalefacs,gr_info);
1986
+ #else
1987
+ fprintf(stderr,"Not supported\n");
1988
+ #endif
1989
+ }
1990
+
1991
+ if(III_dequantize_sample(hybridIn[1],scalefacs,gr_info,sfreq,part2bits))
1992
+ return clip;
1993
+
1994
+ if(ms_stereo) {
1995
+ int i;
1996
+ for(i=0;i<SBLIMIT*SSLIMIT;i++) {
1997
+ real tmp0,tmp1;
1998
+ tmp0 = ((real *) hybridIn[0])[i];
1999
+ tmp1 = ((real *) hybridIn[1])[i];
2000
+ ((real *) hybridIn[1])[i] = tmp0 - tmp1;
2001
+ ((real *) hybridIn[0])[i] = tmp0 + tmp1;
2002
+ }
2003
+ }
2004
+
2005
+ if(i_stereo)
2006
+ III_i_stereo(hybridIn,scalefacs,gr_info,sfreq,ms_stereo,fr->lsf);
2007
+
2008
+ if(ms_stereo || i_stereo || (single == 3) ) {
2009
+ if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb)
2010
+ sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
2011
+ else
2012
+ gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
2013
+ }
2014
+
2015
+ switch(single) {
2016
+ case 3:
2017
+ {
2018
+ register int i;
2019
+ register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
2020
+ for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++)
2021
+ *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */
2022
+ }
2023
+ break;
2024
+ case 1:
2025
+ {
2026
+ register int i;
2027
+ register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
2028
+ for(i=0;i<SSLIMIT*gr_info->maxb;i++)
2029
+ *in0++ = *in1++;
2030
+ }
2031
+ break;
2032
+ }
2033
+ }
2034
+
2035
+ #ifdef HAVEGTK
2036
+ {
2037
+ extern int tabsel_123[2][3][16];
2038
+ int sb;
2039
+
2040
+ pinfo->bitrate =
2041
+ tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
2042
+ pinfo->sampfreq = freqs[sfreq];
2043
+ pinfo->emph = fr->emphasis;
2044
+ pinfo->stereo = fr->stereo;
2045
+ pinfo->js = (fr->mode == MPG_MD_JOINT_STEREO);
2046
+ pinfo->ms_stereo = ms_stereo;
2047
+ pinfo->i_stereo = i_stereo;
2048
+ pinfo->maindata = sideinfo.main_data_begin;
2049
+
2050
+ for(ch=0;ch<stereo1;ch++) {
2051
+ struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
2052
+ pinfo->mixed[gr][ch] = gr_info->mixed_block_flag;
2053
+ pinfo->mpg123blocktype[gr][ch]=gr_info->block_type;
2054
+ pinfo->mainbits[gr][ch] = gr_info->part2_3_length;
2055
+ pinfo->scfsi = gr_info->scfsi;
2056
+ }
2057
+ for(ch=0;ch<stereo1;ch++) {
2058
+ int j=0;
2059
+ for (sb=0;sb<SBLIMIT;sb++)
2060
+ for(ss=0;ss<SSLIMIT;ss++,j++)
2061
+ pinfo->mpg123xr[gr][ch][j]=hybridIn[ch][sb][ss];
2062
+ }
2063
+ }
2064
+
2065
+ #endif
2066
+
2067
+ for(ch=0;ch<stereo1;ch++) {
2068
+ struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
2069
+ III_antialias(hybridIn[ch],gr_info);
2070
+ III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info);
2071
+ }
2072
+
2073
+ for(ss=0;ss<SSLIMIT;ss++) {
2074
+ if(single >= 0) {
2075
+ clip += synth_1to1_mono(hybridOut[0][ss],pcm_sample,pcm_point);
2076
+ }
2077
+ else {
2078
+ int p1 = *pcm_point;
2079
+ clip += synth_1to1(hybridOut[0][ss],0,pcm_sample,&p1);
2080
+ clip += synth_1to1(hybridOut[1][ss],1,pcm_sample,pcm_point);
2081
+ }
2082
+ }
2083
+ }
2084
+
2085
+ return clip;
2086
+ }
2087
+
2088
+
2089
+ //#endif
2090
+