PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/project/jni/sdl_sound/decoders/mpglib/layer3.c

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