source: gs3-extensions/web-audio/trunk/js-mad/jsmad-master/experiments/src/synth.js@ 28388

Last change on this file since 28388 was 28388, checked in by davidb, 11 years ago

Set of JS, CSS, PNG etc web resources to support a mixture of audio player/document display capabilities

File size: 30.9 KB
Line 
1/*
2 * NAME: synth.init()
3 * DESCRIPTION: initialize synth struct
4 */
5Mad.Synth = function () {
6 this.filter = [];
7 this.mute();
8 this.phase = 0;
9
10 this.pcm = {
11 samplerate: 0,
12 channels: 0,
13 length: 0,
14 samples: [
15 // new Float64Array(new ArrayBuffer(8 * 1152)),
16 // new Float64Array(new ArrayBuffer(8 * 1152))
17 [],
18 []
19 ]
20 };
21
22 // this.pcm.clone = function() {
23 // var copy = {};
24 // copy.samplerate = this.samplerate;
25 // copy.channels = this.channels;
26 // copy.length = this.length;
27 // copy.samples = [
28 // // new Float64Array(new ArrayBuffer(8 * 1152)),
29 // // new Float64Array(new ArrayBuffer(8 * 1152))
30 // [],
31 // []
32 // ];
33 // copy.samples[0].set(this.samples[0]);
34 // copy.samples[1].set(this.samples[1]);
35 // return copy;
36 // };
37}
38
39/*
40 * NAME: synth.mute()
41 * DESCRIPTION: zero all polyphase filterbank values, resetting synthesis
42 */
43Mad.Synth.prototype.mute = function () {
44 for (var ch = 0; ch < 2; ++ch) {
45 this.filter[ch] = [ [ [], [] ], [ [], [] ] ];
46
47 for (var s = 0; s < 16; ++s) {
48 this.filter[ch][0][0][s] = [];
49 this.filter[ch][0][1][s] = [];
50 this.filter[ch][1][0][s] = [];
51 this.filter[ch][1][1][s] = [];
52
53 for (var v = 0; v < 8; ++v) {
54 this.filter[ch][0][0][s][v] = 0;
55 this.filter[ch][0][1][s][v] = 0;
56 this.filter[ch][1][0][s][v] = 0;
57 this.filter[ch][1][1][s][v] = 0;
58 }
59 }
60 }
61};
62
63/* costab[i] = cos(PI / (2 * 32) * i) */
64var costab1 = 0.998795456;
65var costab2 = 0.995184727;
66var costab3 = 0.989176510;
67var costab4 = 0.980785280;
68var costab5 = 0.970031253;
69var costab6 = 0.956940336;
70var costab7 = 0.941544065;
71var costab8 = 0.923879533;
72var costab9 = 0.903989293;
73var costab10 = 0.881921264;
74var costab11 = 0.857728610;
75var costab12 = 0.831469612;
76var costab13 = 0.803207531;
77var costab14 = 0.773010453;
78var costab15 = 0.740951125;
79var costab16 = 0.707106781;
80var costab17 = 0.671558955;
81var costab18 = 0.634393284;
82var costab19 = 0.595699304;
83var costab20 = 0.555570233;
84var costab21 = 0.514102744;
85var costab22 = 0.471396737;
86var costab23 = 0.427555093;
87var costab24 = 0.382683432;
88var costab25 = 0.336889853;
89var costab26 = 0.290284677;
90var costab27 = 0.242980180;
91var costab28 = 0.195090322;
92var costab29 = 0.146730474;
93var costab30 = 0.098017140;
94var costab31 = 0.049067674;
95
96/*
97 * NAME: dct32()
98 * DESCRIPTION: perform fast in[32].out[32] DCT
99 */
100Mad.Synth.dct32 = function (_in /* [32] */, slot, lo /* [16][8] */, hi /* [16][8] */) {
101 var t0, t1, t2, t3, t4, t5, t6, t7;
102 var t8, t9, t10, t11, t12, t13, t14, t15;
103 var t16, t17, t18, t19, t20, t21, t22, t23;
104 var t24, t25, t26, t27, t28, t29, t30, t31;
105 var t32, t33, t34, t35, t36, t37, t38, t39;
106 var t40, t41, t42, t43, t44, t45, t46, t47;
107 var t48, t49, t50, t51, t52, t53, t54, t55;
108 var t56, t57, t58, t59, t60, t61, t62, t63;
109 var t64, t65, t66, t67, t68, t69, t70, t71;
110 var t72, t73, t74, t75, t76, t77, t78, t79;
111 var t80, t81, t82, t83, t84, t85, t86, t87;
112 var t88, t89, t90, t91, t92, t93, t94, t95;
113 var t96, t97, t98, t99, t100, t101, t102, t103;
114 var t104, t105, t106, t107, t108, t109, t110, t111;
115 var t112, t113, t114, t115, t116, t117, t118, t119;
116 var t120, t121, t122, t123, t124, t125, t126, t127;
117 var t128, t129, t130, t131, t132, t133, t134, t135;
118 var t136, t137, t138, t139, t140, t141, t142, t143;
119 var t144, t145, t146, t147, t148, t149, t150, t151;
120 var t152, t153, t154, t155, t156, t157, t158, t159;
121 var t160, t161, t162, t163, t164, t165, t166, t167;
122 var t168, t169, t170, t171, t172, t173, t174, t175;
123 var t176;
124
125
126 // var sys = require('sys');
127 // for (i = 0; i < 32; i++) {
128 // sys.print(_in[i].toFixed(8) + "\t");
129 // if (i % 8 === 7) sys.print("\n");
130 // }
131
132 t0 = _in[0] + _in[31]; t16 = ((_in[0] - _in[31]) * (costab1));
133 t1 = _in[15] + _in[16]; t17 = ((_in[15] - _in[16]) * (costab31));
134
135 t41 = t16 + t17;
136 t59 = ((t16 - t17) * (costab2));
137 t33 = t0 + t1;
138 t50 = ((t0 - t1) * ( costab2));
139
140 t2 = _in[7] + _in[24]; t18 = ((_in[7] - _in[24]) * (costab15));
141 t3 = _in[8] + _in[23]; t19 = ((_in[8] - _in[23]) * (costab17));
142
143 t42 = t18 + t19;
144 t60 = ((t18 - t19) * (costab30));
145 t34 = t2 + t3;
146 t51 = ((t2 - t3) * ( costab30));
147
148 t4 = _in[3] + _in[28]; t20 = ((_in[3] - _in[28]) * (costab7));
149 t5 = _in[12] + _in[19]; t21 = ((_in[12] - _in[19]) * (costab25));
150
151 t43 = t20 + t21;
152 t61 = ((t20 - t21) * (costab14));
153 t35 = t4 + t5;
154 t52 = ((t4 - t5) * ( costab14));
155
156 t6 = _in[4] + _in[27]; t22 = ((_in[4] - _in[27]) * (costab9));
157 t7 = _in[11] + _in[20]; t23 = ((_in[11] - _in[20]) * (costab23));
158
159 t44 = t22 + t23;
160 t62 = ((t22 - t23) * (costab18));
161 t36 = t6 + t7;
162 t53 = ((t6 - t7) * ( costab18));
163
164 t8 = _in[1] + _in[30]; t24 = ((_in[1] - _in[30]) * (costab3));
165 t9 = _in[14] + _in[17]; t25 = ((_in[14] - _in[17]) * (costab29));
166
167 t45 = t24 + t25;
168 t63 = ((t24 - t25) * (costab6));
169 t37 = t8 + t9;
170 t54 = ((t8 - t9) * ( costab6));
171
172 t10 = _in[6] + _in[25]; t26 = ((_in[6] - _in[25]) * (costab13));
173 t11 = _in[9] + _in[22]; t27 = ((_in[9] - _in[22]) * (costab19));
174
175 t46 = t26 + t27;
176 t64 = ((t26 - t27) * (costab26));
177 t38 = t10 + t11;
178 t55 = ((t10 - t11) * (costab26));
179
180 t12 = _in[2] + _in[29]; t28 = ((_in[2] - _in[29]) * (costab5));
181 t13 = _in[13] + _in[18]; t29 = ((_in[13] - _in[18]) * (costab27));
182
183 t47 = t28 + t29;
184 t65 = ((t28 - t29) * (costab10));
185 t39 = t12 + t13;
186 t56 = ((t12 - t13) * (costab10));
187
188 t14 = _in[5] + _in[26]; t30 = ((_in[5] - _in[26]) * (costab11));
189 t15 = _in[10] + _in[21]; t31 = ((_in[10] - _in[21]) * (costab21));
190
191 t48 = t30 + t31;
192 t66 = ((t30 - t31) * (costab22));
193 t40 = t14 + t15;
194 t57 = ((t14 - t15) * (costab22));
195
196 t69 = t33 + t34; t89 = ((t33 - t34) * (costab4));
197 t70 = t35 + t36; t90 = ((t35 - t36) * (costab28));
198 t71 = t37 + t38; t91 = ((t37 - t38) * (costab12));
199 t72 = t39 + t40; t92 = ((t39 - t40) * (costab20));
200 t73 = t41 + t42; t94 = ((t41 - t42) * (costab4));
201 t74 = t43 + t44; t95 = ((t43 - t44) * (costab28));
202 t75 = t45 + t46; t96 = ((t45 - t46) * (costab12));
203 t76 = t47 + t48; t97 = ((t47 - t48) * (costab20));
204
205 t78 = t50 + t51; t100 = ((t50 - t51) * (costab4));
206 t79 = t52 + t53; t101 = ((t52 - t53) * (costab28));
207 t80 = t54 + t55; t102 = ((t54 - t55) * (costab12));
208 t81 = t56 + t57; t103 = ((t56 - t57) * (costab20));
209
210 t83 = t59 + t60; t106 = ((t59 - t60) * (costab4));
211 t84 = t61 + t62; t107 = ((t61 - t62) * (costab28));
212 t85 = t63 + t64; t108 = ((t63 - t64) * (costab12));
213 t86 = t65 + t66; t109 = ((t65 - t66) * (costab20));
214
215 t113 = t69 + t70;
216 t114 = t71 + t72;
217
218 /* 0 */ hi[15][slot] = t113 + t114;
219 /* 16 */ lo[ 0][slot] = ((t113 - t114) * (costab16));
220
221 t115 = t73 + t74;
222 t116 = t75 + t76;
223
224 t32 = t115 + t116;
225
226 /* 1 */ hi[14][slot] = t32;
227
228 t118 = t78 + t79;
229 t119 = t80 + t81;
230
231 t58 = t118 + t119;
232
233 /* 2 */ hi[13][slot] = t58;
234
235 t121 = t83 + t84;
236 t122 = t85 + t86;
237
238 t67 = t121 + t122;
239
240 t49 = (t67 * 2) - t32;
241
242 /* 3 */ hi[12][slot] = t49;
243
244 t125 = t89 + t90;
245 t126 = t91 + t92;
246
247 t93 = t125 + t126;
248
249 /* 4 */ hi[11][slot] = t93;
250
251 t128 = t94 + t95;
252 t129 = t96 + t97;
253
254 t98 = t128 + t129;
255
256 t68 = (t98 * 2) - t49;
257
258 /* 5 */ hi[10][slot] = t68;
259
260 t132 = t100 + t101;
261 t133 = t102 + t103;
262
263 t104 = t132 + t133;
264
265 t82 = (t104 * 2) - t58;
266
267 /* 6 */ hi[ 9][slot] = t82;
268
269 t136 = t106 + t107;
270 t137 = t108 + t109;
271
272 t110 = t136 + t137;
273
274 t87 = (t110 * 2) - t67;
275
276 t77 = (t87 * 2) - t68;
277
278 /* 7 */ hi[ 8][slot] = t77;
279
280 t141 = ((t69 - t70) * (costab8));
281 t142 = ((t71 - t72) * (costab24));
282 t143 = t141 + t142;
283
284 /* 8 */ hi[ 7][slot] = t143;
285 /* 24 */ lo[ 8][slot] =
286 (((t141 - t142) * (costab16) * 2)) - t143;
287
288 t144 = ((t73 - t74) * (costab8));
289 t145 = ((t75 - t76) * (costab24));
290 t146 = t144 + t145;
291
292 t88 = (t146 * 2) - t77;
293
294 /* 9 */ hi[ 6][slot] = t88;
295
296 t148 = ((t78 - t79) * (costab8));
297 t149 = ((t80 - t81) * (costab24));
298 t150 = t148 + t149;
299
300 t105 = (t150 * 2) - t82;
301
302 /* 10 */ hi[ 5][slot] = t105;
303
304 t152 = ((t83 - t84) * (costab8));
305 t153 = ((t85 - t86) * (costab24));
306 t154 = t152 + t153;
307
308 t111 = (t154 * 2) - t87;
309
310 t99 = (t111 * 2) - t88;
311
312 /* 11 */ hi[ 4][slot] = t99;
313
314 t157 = ((t89 - t90) * (costab8));
315 t158 = ((t91 - t92) * (costab24));
316 t159 = t157 + t158;
317
318 t127 = (t159 * 2) - t93;
319
320 /* 12 */ hi[ 3][slot] = t127;
321
322 t160 = (((t125 - t126) * (costab16) * 2)) - t127;
323
324 /* 20 */ lo[ 4][slot] = t160;
325 /* 28 */ lo[12][slot] =
326 (((((t157 - t158) * (costab16) * 2) - t159) * 2)) - t160;
327
328 t161 = ((t94 - t95) * (costab8));
329 t162 = ((t96 - t97) * (costab24));
330 t163 = t161 + t162;
331
332 t130 = (t163 * 2) - t98;
333
334 t112 = (t130 * 2) - t99;
335
336 /* 13 */ hi[ 2][slot] = t112;
337
338 t164 = (((t128 - t129) * (costab16) * 2)) - t130;
339
340 t166 = ((t100 - t101) * (costab8));
341 t167 = ((t102 - t103) * (costab24));
342 t168 = t166 + t167;
343
344 t134 = (t168 * 2) - t104;
345
346 t120 = (t134 * 2) - t105;
347
348 /* 14 */ hi[ 1][slot] = t120;
349
350 t135 = (((t118 - t119) * (costab16) * 2)) - t120;
351
352 /* 18 */ lo[ 2][slot] = t135;
353
354 t169 = (((t132 - t133) * (costab16) * 2)) - t134;
355
356 t151 = (t169 * 2) - t135;
357
358 /* 22 */ lo[ 6][slot] = t151;
359
360 t170 = (((((t148 - t149) * (costab16) * 2) - t150) * 2)) - t151;
361
362 /* 26 */ lo[10][slot] = t170;
363 /* 30 */ lo[14][slot] =
364 (((((((t166 - t167) * (costab16)) * 2 -
365 t168) * 2) - t169) * 2) - t170);
366
367 t171 = ((t106 - t107) * (costab8));
368 t172 = ((t108 - t109) * (costab24));
369 t173 = t171 + t172;
370
371 t138 = (t173 * 2) - t110;
372
373 t123 = (t138 * 2) - t111;
374
375 t139 = (((t121 - t122) * (costab16) * 2)) - t123;
376
377 t117 = (t123 * 2) - t112;
378
379 /* 15 */ hi[ 0][slot] = t117;
380
381 t124 = (((t115 - t116) * (costab16) * 2)) - t117;
382
383 /* 17 */ lo[ 1][slot] = t124;
384
385 t131 = (t139 * 2) - t124;
386
387 /* 19 */ lo[ 3][slot] = t131;
388
389 t140 = (t164 * 2) - t131;
390
391 /* 21 */ lo[ 5][slot] = t140;
392
393 t174 = (((t136 - t137) * (costab16) * 2)) - t138;
394
395 t155 = (t174 * 2) - t139;
396
397 t147 = (t155 * 2) - t140;
398
399 /* 23 */ lo[ 7][slot] = t147;
400
401 t156 = (((((t144 - t145) * (costab16) * 2) - t146) * 2)) - t147;
402
403 /* 25 */ lo[ 9][slot] = t156;
404
405 t175 = (((((t152 - t153) * (costab16) * 2) - t154) * 2)) - t155;
406
407 t165 = (t175 * 2) - t156;
408
409 /* 27 */ lo[11][slot] = t165;
410
411 t176 = (((((((t161 - t162) * (costab16) * 2)) -
412 t163) * 2) - t164) * 2) - t165;
413
414 /* 29 */ lo[13][slot] = t176;
415 /* 31 */ lo[15][slot] =
416 (((((((((t171 - t172) * (costab16)) * 2 -
417 t173) * 2) - t174) * 2) - t175) * 2) - t176);
418
419 /*
420 * Totals:
421 * 80 multiplies
422 * 80 additions
423 * 119 subtractions
424 * 49 shifts (not counting SSO)
425 */
426}
427
428var D /* [17][32] */ = [
429 /*
430 * These are the coefficients for the subband synthesis window. This is a
431 * reordered version of Table B.3 from ISO/IEC 11172-3.
432 */
433 [ 0.000000000, /* 0 */
434 -0.000442505,
435 0.003250122,
436 -0.007003784,
437 0.031082153,
438 -0.078628540,
439 0.100311279,
440 -0.572036743,
441 1.144989014,
442 0.572036743,
443 0.100311279,
444 0.078628540,
445 0.031082153,
446 0.007003784,
447 0.003250122,
448 0.000442505,
449
450 0.000000000,
451 -0.000442505,
452 0.003250122,
453 -0.007003784,
454 0.031082153,
455 -0.078628540,
456 0.100311279,
457 -0.572036743,
458 1.144989014,
459 0.572036743,
460 0.100311279,
461 0.078628540,
462 0.031082153,
463 0.007003784,
464 0.003250122,
465 0.000442505 ],
466
467 [ -0.000015259, /* 1 */
468 -0.000473022,
469 0.003326416,
470 -0.007919312,
471 0.030517578,
472 -0.084182739,
473 0.090927124,
474 -0.600219727,
475 1.144287109,
476 0.543823242,
477 0.108856201,
478 0.073059082,
479 0.031478882,
480 0.006118774,
481 0.003173828,
482 0.000396729,
483
484 -0.000015259,
485 -0.000473022,
486 0.003326416,
487 -0.007919312,
488 0.030517578,
489 -0.084182739,
490 0.090927124,
491 -0.600219727,
492 1.144287109,
493 0.543823242,
494 0.108856201,
495 0.073059082,
496 0.031478882,
497 0.006118774,
498 0.003173828,
499 0.000396729 ],
500
501 [ -0.000015259, /* 2 */
502 -0.000534058,
503 0.003387451,
504 -0.008865356,
505 0.029785156,
506 -0.089706421,
507 0.080688477,
508 -0.628295898,
509 1.142211914,
510 0.515609741,
511 0.116577148,
512 0.067520142,
513 0.031738281,
514 0.005294800,
515 0.003082275,
516 0.000366211,
517
518 -0.000015259,
519 -0.000534058,
520 0.003387451,
521 -0.008865356,
522 0.029785156,
523 -0.089706421,
524 0.080688477,
525 -0.628295898,
526 1.142211914,
527 0.515609741,
528 0.116577148,
529 0.067520142,
530 0.031738281,
531 0.005294800,
532 0.003082275,
533 0.000366211 ],
534
535 [ -0.000015259, /* 3 */
536 -0.000579834,
537 0.003433228,
538 -0.009841919,
539 0.028884888,
540 -0.095169067,
541 0.069595337,
542 -0.656219482,
543 1.138763428,
544 0.487472534,
545 0.123474121,
546 0.061996460,
547 0.031845093,
548 0.004486084,
549 0.002990723,
550 0.000320435,
551
552 -0.000015259,
553 -0.000579834,
554 0.003433228,
555 -0.009841919,
556 0.028884888,
557 -0.095169067,
558 0.069595337,
559 -0.656219482,
560 1.138763428,
561 0.487472534,
562 0.123474121,
563 0.061996460,
564 0.031845093,
565 0.004486084,
566 0.002990723,
567 0.000320435 ],
568
569 [ -0.000015259, /* 4 */
570 -0.000625610,
571 0.003463745,
572 -0.010848999,
573 0.027801514,
574 -0.100540161,
575 0.057617187,
576 -0.683914185,
577 1.133926392,
578 0.459472656,
579 0.129577637,
580 0.056533813,
581 0.031814575,
582 0.003723145,
583 0.002899170,
584 0.000289917,
585
586 -0.000015259,
587 -0.000625610,
588 0.003463745,
589 -0.010848999,
590 0.027801514,
591 -0.100540161,
592 0.057617187,
593 -0.683914185,
594 1.133926392,
595 0.459472656,
596 0.129577637,
597 0.056533813,
598 0.031814575,
599 0.003723145,
600 0.002899170,
601 0.000289917 ],
602
603 [ -0.000015259, /* 5 */
604 -0.000686646,
605 0.003479004,
606 -0.011886597,
607 0.026535034,
608 -0.105819702,
609 0.044784546,
610 -0.711318970,
611 1.127746582,
612 0.431655884,
613 0.134887695,
614 0.051132202,
615 0.031661987,
616 0.003005981,
617 0.002792358,
618 0.000259399,
619
620 -0.000015259,
621 -0.000686646,
622 0.003479004,
623 -0.011886597,
624 0.026535034,
625 -0.105819702,
626 0.044784546,
627 -0.711318970,
628 1.127746582,
629 0.431655884,
630 0.134887695,
631 0.051132202,
632 0.031661987,
633 0.003005981,
634 0.002792358,
635 0.000259399 ],
636
637 [ -0.000015259, /* 6 */
638 -0.000747681,
639 0.003479004,
640 -0.012939453,
641 0.025085449,
642 -0.110946655,
643 0.031082153,
644 -0.738372803,
645 1.120223999,
646 0.404083252,
647 0.139450073,
648 0.045837402,
649 0.031387329,
650 0.002334595,
651 0.002685547,
652 0.000244141,
653
654 -0.000015259,
655 -0.000747681,
656 0.003479004,
657 -0.012939453,
658 0.025085449,
659 -0.110946655,
660 0.031082153,
661 -0.738372803,
662 1.120223999,
663 0.404083252,
664 0.139450073,
665 0.045837402,
666 0.031387329,
667 0.002334595,
668 0.002685547,
669 0.000244141 ],
670
671 [ -0.000030518, /* 7 */
672 -0.000808716,
673 0.003463745,
674 -0.014022827,
675 0.023422241,
676 -0.115921021,
677 0.016510010,
678 -0.765029907,
679 1.111373901,
680 0.376800537,
681 0.143264771,
682 0.040634155,
683 0.031005859,
684 0.001693726,
685 0.002578735,
686 0.000213623,
687
688 -0.000030518,
689 -0.000808716,
690 0.003463745,
691 -0.014022827,
692 0.023422241,
693 -0.115921021,
694 0.016510010,
695 -0.765029907,
696 1.111373901,
697 0.376800537,
698 0.143264771,
699 0.040634155,
700 0.031005859,
701 0.001693726,
702 0.002578735,
703 0.000213623 ],
704
705 [ -0.000030518, /* 8 */
706 -0.000885010,
707 0.003417969,
708 -0.015121460,
709 0.021575928,
710 -0.120697021,
711 0.001068115,
712 -0.791213989,
713 1.101211548,
714 0.349868774,
715 0.146362305,
716 0.035552979,
717 0.030532837,
718 0.001098633,
719 0.002456665,
720 0.000198364,
721
722 -0.000030518,
723 -0.000885010,
724 0.003417969,
725 -0.015121460,
726 0.021575928,
727 -0.120697021,
728 0.001068115,
729 -0.791213989,
730 1.101211548,
731 0.349868774,
732 0.146362305,
733 0.035552979,
734 0.030532837,
735 0.001098633,
736 0.002456665,
737 0.000198364 ],
738
739 [ -0.000030518, /* 9 */
740 -0.000961304,
741 0.003372192,
742 -0.016235352,
743 0.019531250,
744 -0.125259399,
745 -0.015228271,
746 -0.816864014,
747 1.089782715,
748 0.323318481,
749 0.148773193,
750 0.030609131,
751 0.029937744,
752 0.000549316,
753 0.002349854,
754 0.000167847,
755
756 -0.000030518,
757 -0.000961304,
758 0.003372192,
759 -0.016235352,
760 0.019531250,
761 -0.125259399,
762 -0.015228271,
763 -0.816864014,
764 1.089782715,
765 0.323318481,
766 0.148773193,
767 0.030609131,
768 0.029937744,
769 0.000549316,
770 0.002349854,
771 0.000167847 ],
772
773 [ -0.000030518, /* 10 */
774 -0.001037598,
775 0.003280640,
776 -0.017349243,
777 0.017257690,
778 -0.129562378,
779 -0.032379150,
780 -0.841949463,
781 1.077117920,
782 0.297210693,
783 0.150497437,
784 0.025817871,
785 0.029281616,
786 0.000030518,
787 0.002243042,
788 0.000152588,
789
790 -0.000030518,
791 -0.001037598,
792 0.003280640,
793 -0.017349243,
794 0.017257690,
795 -0.129562378,
796 -0.032379150,
797 -0.841949463,
798 1.077117920,
799 0.297210693,
800 0.150497437,
801 0.025817871,
802 0.029281616,
803 0.000030518,
804 0.002243042,
805 0.000152588 ],
806
807 [ -0.000045776, /* 11 */
808 -0.001113892,
809 0.003173828,
810 -0.018463135,
811 0.014801025,
812 -0.133590698,
813 -0.050354004,
814 -0.866363525,
815 1.063217163,
816 0.271591187,
817 0.151596069,
818 0.021179199,
819 0.028533936,
820 -0.000442505,
821 0.002120972,
822 0.000137329,
823
824 -0.000045776,
825 -0.001113892,
826 0.003173828,
827 -0.018463135,
828 0.014801025,
829 -0.133590698,
830 -0.050354004,
831 -0.866363525,
832 1.063217163,
833 0.271591187,
834 0.151596069,
835 0.021179199,
836 0.028533936,
837 -0.000442505,
838 0.002120972,
839 0.000137329 ],
840
841 [ -0.000045776, /* 12 */
842 -0.001205444,
843 0.003051758,
844 -0.019577026,
845 0.012115479,
846 -0.137298584,
847 -0.069168091,
848 -0.890090942,
849 1.048156738,
850 0.246505737,
851 0.152069092,
852 0.016708374,
853 0.027725220,
854 -0.000869751,
855 0.002014160,
856 0.000122070,
857
858 -0.000045776,
859 -0.001205444,
860 0.003051758,
861 -0.019577026,
862 0.012115479,
863 -0.137298584,
864 -0.069168091,
865 -0.890090942,
866 1.048156738,
867 0.246505737,
868 0.152069092,
869 0.016708374,
870 0.027725220,
871 -0.000869751,
872 0.002014160,
873 0.000122070 ],
874
875 [ -0.000061035, /* 13 */
876 -0.001296997,
877 0.002883911,
878 -0.020690918,
879 0.009231567,
880 -0.140670776,
881 -0.088775635,
882 -0.913055420,
883 1.031936646,
884 0.221984863,
885 0.151962280,
886 0.012420654,
887 0.026840210,
888 -0.001266479,
889 0.001907349,
890 0.000106812,
891
892 -0.000061035,
893 -0.001296997,
894 0.002883911,
895 -0.020690918,
896 0.009231567,
897 -0.140670776,
898 -0.088775635,
899 -0.913055420,
900 1.031936646,
901 0.221984863,
902 0.151962280,
903 0.012420654,
904 0.026840210,
905 -0.001266479,
906 0.001907349,
907 0.000106812 ],
908
909 [ -0.000061035, /* 14 */
910 -0.001388550,
911 0.002700806,
912 -0.021789551,
913 0.006134033,
914 -0.143676758,
915 -0.109161377,
916 -0.935195923,
917 1.014617920,
918 0.198059082,
919 0.151306152,
920 0.008316040,
921 0.025909424,
922 -0.001617432,
923 0.001785278,
924 0.000106812,
925
926 -0.000061035,
927 -0.001388550,
928 0.002700806,
929 -0.021789551,
930 0.006134033,
931 -0.143676758,
932 -0.109161377,
933 -0.935195923,
934 1.014617920,
935 0.198059082,
936 0.151306152,
937 0.008316040,
938 0.025909424,
939 -0.001617432,
940 0.001785278,
941 0.000106812 ],
942
943 [ -0.000076294, /* 15 */
944 -0.001480103,
945 0.002487183,
946 -0.022857666,
947 0.002822876,
948 -0.146255493,
949 -0.130310059,
950 -0.956481934,
951 0.996246338,
952 0.174789429,
953 0.150115967,
954 0.004394531,
955 0.024932861,
956 -0.001937866,
957 0.001693726,
958 0.000091553,
959
960 -0.000076294,
961 -0.001480103,
962 0.002487183,
963 -0.022857666,
964 0.002822876,
965 -0.146255493,
966 -0.130310059,
967 -0.956481934,
968 0.996246338,
969 0.174789429,
970 0.150115967,
971 0.004394531,
972 0.024932861,
973 -0.001937866,
974 0.001693726,
975 0.000091553 ],
976
977 [ -0.000076294, /* 16 */
978 -0.001586914,
979 0.002227783,
980 -0.023910522,
981 -0.000686646,
982 -0.148422241,
983 -0.152206421,
984 -0.976852417,
985 0.976852417,
986 0.152206421,
987 0.148422241,
988 0.000686646,
989 0.023910522,
990 -0.002227783,
991 0.001586914,
992 0.000076294,
993
994 -0.000076294,
995 -0.001586914,
996 0.002227783,
997 -0.023910522,
998 -0.000686646,
999 -0.148422241,
1000 -0.152206421,
1001 -0.976852417,
1002 0.976852417,
1003 0.152206421,
1004 0.148422241,
1005 0.000686646,
1006 0.023910522,
1007 -0.002227783,
1008 0.001586914,
1009 0.000076294 ]
1010];
1011
1012/*
1013 * NAME: synth.full()
1014 * DESCRIPTION: perform full frequency PCM synthesis
1015 */
1016Mad.Synth.prototype.full = function(frame, nch, ns) {
1017 var Dptr, hi, lo, ptr;
1018
1019 for (var ch = 0; ch < nch; ++ch) {
1020 var sbsample /* [36][32] */ = frame.sbsample[ch];
1021 var filter = this.filter[ch] /* [2][2][16][8] */;
1022 var phase = this.phase;
1023 var pcm = this.pcm.samples[ch];
1024 var pcm1Ptr = 0;
1025 var pcm2Ptr = 0;
1026
1027 for (var s = 0; s < ns; ++s) {
1028 Mad.Synth.dct32(sbsample[s], phase >> 1, filter[0][phase & 1], filter[1][phase & 1]);
1029
1030 var pe = phase & ~1;
1031 var po = ((phase - 1) & 0xf) | 1;
1032
1033 /* calculate 32 samples */
1034 var fe = filter[0][ phase & 1];
1035 var fx = filter[0][~phase & 1];
1036 var fo = filter[1][~phase & 1];
1037
1038 var fePtr = 0;
1039 var fxPtr = 0;
1040 var foPtr = 0;
1041
1042 Dptr = 0;
1043
1044 ptr = D[Dptr];
1045 _fx = fx[fxPtr];
1046 _fe = fe[fePtr];
1047
1048 lo = _fx[0] * ptr[po + 0];
1049 lo += _fx[1] * ptr[po + 14];
1050 lo += _fx[2] * ptr[po + 12];
1051 lo += _fx[3] * ptr[po + 10];
1052 lo += _fx[4] * ptr[po + 8];
1053 lo += _fx[5] * ptr[po + 6];
1054 lo += _fx[6] * ptr[po + 4];
1055 lo += _fx[7] * ptr[po + 2];
1056 lo = -lo;
1057
1058 lo += _fe[0] * ptr[pe + 0];
1059 lo += _fe[1] * ptr[pe + 14];
1060 lo += _fe[2] * ptr[pe + 12];
1061 lo += _fe[3] * ptr[pe + 10];
1062 lo += _fe[4] * ptr[pe + 8];
1063 lo += _fe[5] * ptr[pe + 6];
1064 lo += _fe[6] * ptr[pe + 4];
1065 lo += _fe[7] * ptr[pe + 2];
1066
1067 pcm[pcm1Ptr++] = lo;
1068 pcm2Ptr = pcm1Ptr + 30;
1069
1070 for (var sb = 1; sb < 16; ++sb) {
1071 ++fePtr;
1072 ++Dptr;
1073
1074 /* D[32 - sb][i] === -D[sb][31 - i] */
1075
1076 ptr = D[Dptr];
1077 _fo = fo[foPtr];
1078 _fe = fe[fePtr];
1079
1080 lo = _fo[0] * ptr[po + 0];
1081 lo += _fo[1] * ptr[po + 14];
1082 lo += _fo[2] * ptr[po + 12];
1083 lo += _fo[3] * ptr[po + 10];
1084 lo += _fo[4] * ptr[po + 8];
1085 lo += _fo[5] * ptr[po + 6];
1086 lo += _fo[6] * ptr[po + 4];
1087 lo += _fo[7] * ptr[po + 2];
1088 lo = -lo;
1089
1090 lo += _fe[7] * ptr[pe + 2];
1091 lo += _fe[6] * ptr[pe + 4];
1092 lo += _fe[5] * ptr[pe + 6];
1093 lo += _fe[4] * ptr[pe + 8];
1094 lo += _fe[3] * ptr[pe + 10];
1095 lo += _fe[2] * ptr[pe + 12];
1096 lo += _fe[1] * ptr[pe + 14];
1097 lo += _fe[0] * ptr[pe + 0];
1098
1099 pcm[pcm1Ptr++] = lo;
1100
1101 lo = _fe[0] * ptr[-pe + 31 - 16];
1102 lo += _fe[1] * ptr[-pe + 31 - 14];
1103 lo += _fe[2] * ptr[-pe + 31 - 12];
1104 lo += _fe[3] * ptr[-pe + 31 - 10];
1105 lo += _fe[4] * ptr[-pe + 31 - 8];
1106 lo += _fe[5] * ptr[-pe + 31 - 6];
1107 lo += _fe[6] * ptr[-pe + 31 - 4];
1108 lo += _fe[7] * ptr[-pe + 31 - 2];
1109
1110 lo += _fo[7] * ptr[-po + 31 - 2];
1111 lo += _fo[6] * ptr[-po + 31 - 4];
1112 lo += _fo[5] * ptr[-po + 31 - 6];
1113 lo += _fo[4] * ptr[-po + 31 - 8];
1114 lo += _fo[3] * ptr[-po + 31 - 10];
1115 lo += _fo[2] * ptr[-po + 31 - 12];
1116 lo += _fo[1] * ptr[-po + 31 - 14];
1117 lo += _fo[0] * ptr[-po + 31 - 16];
1118
1119 pcm[pcm2Ptr--] = lo;
1120 ++foPtr;
1121 }
1122
1123 ++Dptr;
1124
1125 ptr = D[Dptr];
1126 _fo = fo[foPtr];
1127
1128 lo = _fo[0] * ptr[po + 0];
1129 lo += _fo[1] * ptr[po + 14];
1130 lo += _fo[2] * ptr[po + 12];
1131 lo += _fo[3] * ptr[po + 10];
1132 lo += _fo[4] * ptr[po + 8];
1133 lo += _fo[5] * ptr[po + 6];
1134 lo += _fo[6] * ptr[po + 4];
1135 lo += _fo[7] * ptr[po + 2];
1136
1137 pcm[pcm1Ptr] = -lo;
1138 pcm1Ptr += 16;
1139 phase = (phase + 1) % 16;
1140 }
1141 }
1142}
1143
1144
1145/*
1146 * NAME: synth.half()
1147 * DESCRIPTION: perform half frequency PCM synthesis
1148 */
1149
1150// Yeah, I don't think so
1151
1152//static
1153//void synth_half(struct mad_synth *synth, struct mad_frame const *frame,
1154// unsigned int nch, unsigned int ns)
1155//{
1156// unsigned int phase, ch, s, sb, pe, po;
1157// mad_fixed_t *pcm1, *pcm2, filter[2][2][16][8];
1158// mad_fixed_t const (*sbsample)[36][32];
1159// register mad_fixed_t (*fe)[8], (*fx)[8], (*fo)[8];
1160// register mad_fixed_t const (*Dptr)[32], *ptr;
1161// register mad_fixed64hi_t hi;
1162// register mad_fixed64lo_t lo;
1163//
1164// for (ch = 0; ch < nch; ++ch) {
1165// sbsample = &frame.sbsample[ch];
1166// filter = &synth.filter[ch];
1167// phase = synth.phase;
1168// pcm1 = synth.pcm.samples[ch];
1169//
1170// for (s = 0; s < ns; ++s) {
1171// dct32((*sbsample)[s], phase >> 1,
1172// filter[0][phase & 1], filter[1][phase & 1]);
1173//
1174// pe = phase & ~1;
1175// po = ((phase - 1) & 0xf) | 1;
1176//
1177// /* calculate 16 samples */
1178//
1179// fe = &filter[0][ phase & 1][0];
1180// fx = &filter[0][~phase & 1][0];
1181// fo = &filter[1][~phase & 1][0];
1182//
1183// Dptr = &D[0];
1184//
1185// ptr = *Dptr + po;
1186// ML0(hi, lo, (*fx)[0], ptr[ 0]);
1187// MLA(hi, lo, (*fx)[1], ptr[14]);
1188// MLA(hi, lo, (*fx)[2], ptr[12]);
1189// MLA(hi, lo, (*fx)[3], ptr[10]);
1190// MLA(hi, lo, (*fx)[4], ptr[ 8]);
1191// MLA(hi, lo, (*fx)[5], ptr[ 6]);
1192// MLA(hi, lo, (*fx)[6], ptr[ 4]);
1193// MLA(hi, lo, (*fx)[7], ptr[ 2]);
1194// MLN(hi, lo);
1195//
1196// ptr = *Dptr + pe;
1197// MLA(hi, lo, (*fe)[0], ptr[ 0]);
1198// MLA(hi, lo, (*fe)[1], ptr[14]);
1199// MLA(hi, lo, (*fe)[2], ptr[12]);
1200// MLA(hi, lo, (*fe)[3], ptr[10]);
1201// MLA(hi, lo, (*fe)[4], ptr[ 8]);
1202// MLA(hi, lo, (*fe)[5], ptr[ 6]);
1203// MLA(hi, lo, (*fe)[6], ptr[ 4]);
1204// MLA(hi, lo, (*fe)[7], ptr[ 2]);
1205//
1206// *pcm1++ = MLZ(hi, lo);
1207//
1208// pcm2 = pcm1 + 14;
1209//
1210// for (sb = 1; sb < 16; ++sb) {
1211// ++fe;
1212// ++Dptr;
1213//
1214// /* D[32 - sb][i] === -D[sb][31 - i] */
1215//
1216// if (!(sb & 1)) {
1217// ptr = *Dptr + po;
1218// ML0(hi, lo, (*fo)[0], ptr[ 0]);
1219// MLA(hi, lo, (*fo)[1], ptr[14]);
1220// MLA(hi, lo, (*fo)[2], ptr[12]);
1221// MLA(hi, lo, (*fo)[3], ptr[10]);
1222// MLA(hi, lo, (*fo)[4], ptr[ 8]);
1223// MLA(hi, lo, (*fo)[5], ptr[ 6]);
1224// MLA(hi, lo, (*fo)[6], ptr[ 4]);
1225// MLA(hi, lo, (*fo)[7], ptr[ 2]);
1226// MLN(hi, lo);
1227//
1228// ptr = *Dptr + pe;
1229// MLA(hi, lo, (*fe)[7], ptr[ 2]);
1230// MLA(hi, lo, (*fe)[6], ptr[ 4]);
1231// MLA(hi, lo, (*fe)[5], ptr[ 6]);
1232// MLA(hi, lo, (*fe)[4], ptr[ 8]);
1233// MLA(hi, lo, (*fe)[3], ptr[10]);
1234// MLA(hi, lo, (*fe)[2], ptr[12]);
1235// MLA(hi, lo, (*fe)[1], ptr[14]);
1236// MLA(hi, lo, (*fe)[0], ptr[ 0]);
1237//
1238// *pcm1++ = MLZ(hi, lo);
1239//
1240// ptr = *Dptr - po;
1241// ML0(hi, lo, (*fo)[7], ptr[31 - 2]);
1242// MLA(hi, lo, (*fo)[6], ptr[31 - 4]);
1243// MLA(hi, lo, (*fo)[5], ptr[31 - 6]);
1244// MLA(hi, lo, (*fo)[4], ptr[31 - 8]);
1245// MLA(hi, lo, (*fo)[3], ptr[31 - 10]);
1246// MLA(hi, lo, (*fo)[2], ptr[31 - 12]);
1247// MLA(hi, lo, (*fo)[1], ptr[31 - 14]);
1248// MLA(hi, lo, (*fo)[0], ptr[31 - 16]);
1249//
1250// ptr = *Dptr - pe;
1251// MLA(hi, lo, (*fe)[0], ptr[31 - 16]);
1252// MLA(hi, lo, (*fe)[1], ptr[31 - 14]);
1253// MLA(hi, lo, (*fe)[2], ptr[31 - 12]);
1254// MLA(hi, lo, (*fe)[3], ptr[31 - 10]);
1255// MLA(hi, lo, (*fe)[4], ptr[31 - 8]);
1256// MLA(hi, lo, (*fe)[5], ptr[31 - 6]);
1257// MLA(hi, lo, (*fe)[6], ptr[31 - 4]);
1258// MLA(hi, lo, (*fe)[7], ptr[31 - 2]);
1259//
1260// *pcm2-- = MLZ(hi, lo);
1261// }
1262//
1263// ++fo;
1264// }
1265//
1266// ++Dptr;
1267//
1268// ptr = *Dptr + po;
1269// ML0(hi, lo, (*fo)[0], ptr[ 0]);
1270// MLA(hi, lo, (*fo)[1], ptr[14]);
1271// MLA(hi, lo, (*fo)[2], ptr[12]);
1272// MLA(hi, lo, (*fo)[3], ptr[10]);
1273// MLA(hi, lo, (*fo)[4], ptr[ 8]);
1274// MLA(hi, lo, (*fo)[5], ptr[ 6]);
1275// MLA(hi, lo, (*fo)[6], ptr[ 4]);
1276// MLA(hi, lo, (*fo)[7], ptr[ 2]);
1277//
1278// *pcm1 = -MLZ(hi, lo);
1279// pcm1 += 8;
1280//
1281// phase = (phase + 1) % 16;
1282// }
1283// }
1284//}
1285
1286/*
1287 * NAME: synth.frame()
1288 * DESCRIPTION: perform PCM synthesis of frame subband samples
1289 */
1290Mad.Synth.prototype.frame = function (frame) {
1291 var nch = frame.header.nchannels();
1292 var ns = frame.header.nbsamples();
1293
1294 this.pcm.samplerate = frame.header.samplerate;
1295 this.pcm.channels = nch;
1296 this.pcm.length = 32 * ns;
1297
1298 // console.log("ns: " + ns);
1299
1300 /*
1301 if (frame.options & Mad.Option.HALFSAMPLERATE) {
1302 this.pcm.samplerate /= 2;
1303 this.pcm.length /= 2;
1304
1305 throw new Error("HALFSAMPLERATE is not supported. What do you think? As if I have the time for this");
1306 }
1307 */
1308
1309 this.full(frame, nch, ns);
1310 this.phase = (this.phase + ns) % 16;
1311}
Note: See TracBrowser for help on using the repository browser.