Subversion Repositories Kolibri OS

Rev

Rev 165 | Blame | Last modification | View Log | Download | RSS feed

  1. #include <math.h>
  2.  
  3. /* "fdct.c" */
  4. void fdct32(float *, float *);
  5. void fdct32_dual(float *, float *);
  6. void fdct32_dual_mono(float *, float *);
  7. void fdct16(float *, float *);
  8. void fdct16_dual(float *, float *);
  9. void fdct16_dual_mono(float *, float *);
  10. void fdct8(float *, float *);
  11. void fdct8_dual(float *, float *);
  12. void fdct8_dual_mono(float *, float *);
  13.  
  14. /* "window.c" */
  15. void window(float *vbuf, int vb_ptr, short *pcm);
  16. void window_dual(float *vbuf, int vb_ptr, short *pcm);
  17. void window16(float *vbuf, int vb_ptr, short *pcm);
  18. void window16_dual(float *vbuf, int vb_ptr, short *pcm);
  19. void window8(float *vbuf, int vb_ptr, short *pcm);
  20. void window8_dual(float *vbuf, int vb_ptr, short *pcm);
  21.  
  22. /* circular window buffers */
  23. int vb_ptr;
  24. int vb2_ptr;
  25. float vbuf[512];
  26. float vbuf2[512];
  27.  
  28. void sbt_init()
  29. {
  30.    int i;
  31.  
  32.    /* clear window vbuf */
  33.    for (i = 0; i < 512; i++)
  34.    {
  35.       vbuf[i] = 0.0F;
  36.       vbuf2[i] = 0.0F;
  37.    }
  38.    vb2_ptr = vb_ptr = 0;
  39. }
  40.  
  41. void sbt_mono(float *sample, short *pcm, int n)
  42. {
  43.    int i;
  44.  
  45.    for (i = 0; i < n; i++)
  46.    {
  47.       fdct32(sample, vbuf + vb_ptr);
  48.       window(vbuf, vb_ptr, pcm);
  49.       sample += 64;
  50.       vb_ptr = (vb_ptr - 32) & 511;
  51.       pcm += 32;
  52.    }
  53.  
  54. }
  55.  
  56. void sbt_dual(float *sample, short *pcm, int n)
  57. {
  58.    int i;
  59.  
  60.    for (i = 0; i < n; i++)
  61.    {
  62.       fdct32_dual(sample, vbuf + vb_ptr);
  63.       fdct32_dual(sample + 1, vbuf2 + vb_ptr);
  64.       window_dual(vbuf, vb_ptr, pcm);
  65.       window_dual(vbuf2, vb_ptr, pcm + 1);
  66.       sample += 64;
  67.       vb_ptr = (vb_ptr - 32) & 511;
  68.       pcm += 64;
  69.    }
  70. }
  71.  
  72. void sbt_dual_mono(float *sample, short *pcm, int n)
  73. {
  74.    int i;
  75.  
  76.    for (i = 0; i < n; i++)
  77.    {
  78.       fdct32_dual_mono(sample, vbuf + vb_ptr);
  79.       window(vbuf, vb_ptr, pcm);
  80.       sample += 64;
  81.       vb_ptr = (vb_ptr - 32) & 511;
  82.       pcm += 32;
  83.    }
  84.  
  85. }
  86.  
  87. void sbt_dual_left(float *sample, short *pcm, int n)
  88. {
  89.    int i;
  90.  
  91.    for (i = 0; i < n; i++)
  92.    {
  93.       fdct32_dual(sample, vbuf + vb_ptr);
  94.       window(vbuf, vb_ptr, pcm);
  95.       sample += 64;
  96.       vb_ptr = (vb_ptr - 32) & 511;
  97.       pcm += 32;
  98.    }
  99. }
  100.  
  101. void sbt_dual_right(float *sample, short *pcm, int n)
  102. {
  103.    int i;
  104.  
  105.    sample++;                    /* point to right chan */
  106.    for (i = 0; i < n; i++)
  107.    {
  108.       fdct32_dual(sample, vbuf + vb_ptr);
  109.       window(vbuf, vb_ptr, pcm);
  110.       sample += 64;
  111.       vb_ptr = (vb_ptr - 32) & 511;
  112.       pcm += 32;
  113.    }
  114. }
  115.  
  116. void sbt16_mono(float *sample, short *pcm, int n)
  117. {
  118.    int i;
  119.  
  120.    for (i = 0; i < n; i++)
  121.    {
  122.       fdct16(sample, vbuf + vb_ptr);
  123.       window16(vbuf, vb_ptr, pcm);
  124.       sample += 64;
  125.       vb_ptr = (vb_ptr - 16) & 255;
  126.       pcm += 16;
  127.    }
  128. }
  129.  
  130. void sbt16_dual(float *sample, short *pcm, int n)
  131. {
  132.    int i;
  133.  
  134.    for (i = 0; i < n; i++)
  135.    {
  136.       fdct16_dual(sample, vbuf + vb_ptr);
  137.       fdct16_dual(sample + 1, vbuf2 + vb_ptr);
  138.       window16_dual(vbuf, vb_ptr, pcm);
  139.       window16_dual(vbuf2, vb_ptr, pcm + 1);
  140.       sample += 64;
  141.       vb_ptr = (vb_ptr - 16) & 255;
  142.       pcm += 32;
  143.    }
  144. }
  145.  
  146. void sbt16_dual_mono(float *sample, short *pcm, int n)
  147. {
  148.    int i;
  149.  
  150.    for (i = 0; i < n; i++)
  151.    {
  152.       fdct16_dual_mono(sample, vbuf + vb_ptr);
  153.       window16(vbuf, vb_ptr, pcm);
  154.       sample += 64;
  155.       vb_ptr = (vb_ptr - 16) & 255;
  156.       pcm += 16;
  157.    }
  158. }
  159.  
  160. void sbt16_dual_left(float *sample, short *pcm, int n)
  161. {
  162.    int i;
  163.  
  164.    for (i = 0; i < n; i++)
  165.    {
  166.       fdct16_dual(sample, vbuf + vb_ptr);
  167.       window16(vbuf, vb_ptr, pcm);
  168.       sample += 64;
  169.       vb_ptr = (vb_ptr - 16) & 255;
  170.       pcm += 16;
  171.    }
  172. }
  173.  
  174. void sbt16_dual_right(float *sample, short *pcm, int n)
  175. {
  176.    int i;
  177.  
  178.    sample++;
  179.    for (i = 0; i < n; i++)
  180.    {
  181.       fdct16_dual(sample, vbuf + vb_ptr);
  182.       window16(vbuf, vb_ptr, pcm);
  183.       sample += 64;
  184.       vb_ptr = (vb_ptr - 16) & 255;
  185.       pcm += 16;
  186.    }
  187. }
  188.  
  189. void sbt8_mono(float *sample, short *pcm, int n)
  190. {
  191.    int i;
  192.  
  193.    for (i = 0; i < n; i++)
  194.    {
  195.       fdct8(sample, vbuf + vb_ptr);
  196.       window8(vbuf, vb_ptr, pcm);
  197.       sample += 64;
  198.       vb_ptr = (vb_ptr - 8) & 127;
  199.       pcm += 8;
  200.    }
  201.  
  202. }
  203.  
  204. void sbt8_dual(float *sample, short *pcm, int n)
  205. {
  206.    int i;
  207.  
  208.    for (i = 0; i < n; i++)
  209.    {
  210.       fdct8_dual(sample, vbuf + vb_ptr);
  211.       fdct8_dual(sample + 1, vbuf2 + vb_ptr);
  212.       window8_dual(vbuf, vb_ptr, pcm);
  213.       window8_dual(vbuf2, vb_ptr, pcm + 1);
  214.       sample += 64;
  215.       vb_ptr = (vb_ptr - 8) & 127;
  216.       pcm += 16;
  217.    }
  218. }
  219.  
  220. void sbt8_dual_mono(float *sample, short *pcm, int n)
  221. {
  222.    int i;
  223.  
  224.    for (i = 0; i < n; i++)
  225.    {
  226.       fdct8_dual_mono(sample, vbuf + vb_ptr);
  227.       window8(vbuf, vb_ptr, pcm);
  228.       sample += 64;
  229.       vb_ptr = (vb_ptr - 8) & 127;
  230.       pcm += 8;
  231.    }
  232. }
  233.  
  234. void sbt8_dual_left(float *sample, short *pcm, int n)
  235. {
  236.    int i;
  237.  
  238.    for (i = 0; i < n; i++)
  239.    {
  240.       fdct8_dual(sample, vbuf + vb_ptr);
  241.       window8(vbuf, vb_ptr, pcm);
  242.       sample += 64;
  243.       vb_ptr = (vb_ptr - 8) & 127;
  244.       pcm += 8;
  245.    }
  246. }
  247.  
  248. void sbt8_dual_right(float *sample, short *pcm, int n)
  249. {
  250.    int i;
  251.  
  252.    sample++;
  253.    for (i = 0; i < n; i++)
  254.    {
  255.       fdct8_dual(sample, vbuf + vb_ptr);
  256.       window8(vbuf, vb_ptr, pcm);
  257.       sample += 64;
  258.       vb_ptr = (vb_ptr - 8) & 127;
  259.       pcm += 8;
  260.    }
  261. }
  262.  
  263. void sbt_mono_L3(float *sample, short *pcm, int ch)
  264. {
  265.    int i;
  266.  
  267.    ch = 0;
  268.    for (i = 0; i < 18; i++)
  269.    {
  270.       fdct32(sample, vbuf + vb_ptr);
  271.       window(vbuf, vb_ptr, pcm);
  272.       sample += 32;
  273.       vb_ptr = (vb_ptr - 32) & 511;
  274.       pcm += 32;
  275.    }
  276.  
  277. }
  278.  
  279. void sbt_dual_L3(float *sample, short *pcm, int ch)
  280. {
  281.         int i;
  282.  
  283.         if (ch == 0)
  284.                 for (i = 0; i < 18; i++) {
  285.                         fdct32(sample, vbuf + vb_ptr);
  286.                         window_dual(vbuf, vb_ptr, pcm);
  287.                         sample += 32;
  288.                         vb_ptr = (vb_ptr - 32) & 511;
  289.                         pcm += 64;
  290.                 }
  291.         else
  292.                 for (i = 0; i < 18; i++) {
  293.                         fdct32(sample, vbuf2 + vb2_ptr);
  294.                         window_dual(vbuf2, vb2_ptr, pcm + 1);
  295.                         sample += 32;
  296.                         vb2_ptr = (vb2_ptr - 32) & 511;
  297.                         pcm += 64;
  298.                 }
  299. }
  300.  
  301. void sbt16_mono_L3(float *sample, short *pcm, int ch)
  302. {
  303.    int i;
  304.  
  305.    ch = 0;
  306.    for (i = 0; i < 18; i++)
  307.    {
  308.       fdct16(sample, vbuf + vb_ptr);
  309.       window16(vbuf, vb_ptr, pcm);
  310.       sample += 32;
  311.       vb_ptr = (vb_ptr - 16) & 255;
  312.       pcm += 16;
  313.    }
  314.  
  315.  
  316. }
  317.  
  318. void sbt16_dual_L3(float *sample, short *pcm, int ch)
  319. {
  320.    int i;
  321.  
  322.  
  323.    if (ch == 0)
  324.    {
  325.       for (i = 0; i < 18; i++)
  326.       {
  327.          fdct16(sample, vbuf + vb_ptr);
  328.          window16_dual(vbuf, vb_ptr, pcm);
  329.          sample += 32;
  330.          vb_ptr = (vb_ptr - 16) & 255;
  331.          pcm += 32;
  332.       }
  333.    }
  334.    else
  335.    {
  336.       for (i = 0; i < 18; i++)
  337.       {
  338.          fdct16(sample, vbuf2 + vb2_ptr);
  339.          window16_dual(vbuf2, vb2_ptr, pcm + 1);
  340.          sample += 32;
  341.          vb2_ptr = (vb2_ptr - 16) & 255;
  342.          pcm += 32;
  343.       }
  344.    }
  345.  
  346. }
  347.  
  348. void sbt8_mono_L3(float *sample, short *pcm, int ch)
  349. {
  350.    int i;
  351.  
  352.    ch = 0;
  353.    for (i = 0; i < 18; i++)
  354.    {
  355.       fdct8(sample, vbuf + vb_ptr);
  356.       window8(vbuf, vb_ptr, pcm);
  357.       sample += 32;
  358.       vb_ptr = (vb_ptr - 8) & 127;
  359.       pcm += 8;
  360.    }
  361.  
  362. }
  363.  
  364. void sbt8_dual_L3(float *sample, short *pcm, int ch)
  365. {
  366.    int i;
  367.  
  368.    if (ch == 0)
  369.    {
  370.       for (i = 0; i < 18; i++)
  371.       {
  372.          fdct8(sample, vbuf + vb_ptr);
  373.          window8_dual(vbuf, vb_ptr, pcm);
  374.          sample += 32;
  375.          vb_ptr = (vb_ptr - 8) & 127;
  376.          pcm += 16;
  377.       }
  378.    }
  379.    else
  380.    {
  381.       for (i = 0; i < 18; i++)
  382.       {
  383.          fdct8(sample, vbuf2 + vb2_ptr);
  384.          window8_dual(vbuf2, vb2_ptr, pcm + 1);
  385.          sample += 32;
  386.          vb2_ptr = (vb2_ptr - 8) & 127;
  387.          pcm += 16;
  388.       }
  389.    }
  390.  
  391.  
  392.  
  393. }
  394.  
  395.