decode_i386.cpp
上传用户:lusi_8715
上传日期:2007-01-08
资源大小:199k
文件大小:5k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /**************************************************************************************
  2.  *                                                                                    *
  3.  * This application contains code from OpenDivX and is released as a "Larger Work"    *
  4.  * under that license. Consistant with that license, this application is released     *
  5.  * under the GNU General Public License.                                              *
  6.  *                                                                                    *
  7.  * The OpenDivX license can be found at: http://www.projectmayo.com/opendivx/docs.php *
  8.  * The GPL can be found at: http://www.gnu.org/copyleft/gpl.html                      *
  9.  *                                                                                    *
  10.  * Authors: Damien Chavarria <roy204 at projectmayo.com>                              *
  11.  *                                                                                    *
  12.  **************************************************************************************/
  13.  /* 
  14.  * Mpeg Layer-1,2,3 audio decoder 
  15.  * ------------------------------
  16.  * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
  17.  *
  18.  * slighlty optimized for machines without autoincrement/decrement.
  19.  * The performance is highly compiler dependend. Maybe
  20.  * the decode.c version for 'normal' processor may be faster
  21.  * even for Intel processors.
  22.  */
  23. #include <stdlib.h>
  24. #include <math.h>
  25. #include <string.h>
  26. #include "mpg123.h"
  27. #include "mpglib.h"
  28. extern struct mpstr *gmp;
  29.  /* old WRITE_SAMPLE */
  30. #define WRITE_SAMPLE(samples,sum,clip) 
  31.   if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } 
  32.   else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } 
  33.   else { *(samples) = sum; }
  34. int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
  35. {
  36.   short samples_tmp[64];
  37.   short *tmp1 = samples_tmp;
  38.   int i,ret;
  39.   int pnt1 = 0;
  40.   ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
  41.   samples += *pnt;
  42.   for(i=0;i<32;i++) {
  43.     *( (short *) samples) = *tmp1;
  44.     samples += 2;
  45.     tmp1 += 2;
  46.   }
  47.   *pnt += 64;
  48.   return ret;
  49. }
  50. int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
  51. {
  52.   static const int step = 2;
  53.   int bo;
  54.   short *samples = (short *) (out + *pnt);
  55.   real *b0,(*buf)[0x110];
  56.   int clip = 0; 
  57.   int bo1;
  58.   bo = gmp->synth_bo;
  59.   if(!channel) {
  60.     bo--;
  61.     bo &= 0xf;
  62.     buf = gmp->synth_buffs[0];
  63.   }
  64.   else {
  65.     samples++;
  66.     buf = gmp->synth_buffs[1];
  67.   }
  68.   if(bo & 0x1) {
  69.     b0 = buf[0];
  70.     bo1 = bo;
  71.     dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
  72.   }
  73.   else {
  74.     b0 = buf[1];
  75.     bo1 = bo+1;
  76.     dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
  77.   }
  78.   gmp->synth_bo = bo;
  79.   
  80.   {
  81.     register int j;
  82.     real *window = decwin + 16 - bo1;
  83.     for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step)
  84.     {
  85.       real sum;
  86.       sum  = window[0x0] * b0[0x0];
  87.       sum -= window[0x1] * b0[0x1];
  88.       sum += window[0x2] * b0[0x2];
  89.       sum -= window[0x3] * b0[0x3];
  90.       sum += window[0x4] * b0[0x4];
  91.       sum -= window[0x5] * b0[0x5];
  92.       sum += window[0x6] * b0[0x6];
  93.       sum -= window[0x7] * b0[0x7];
  94.       sum += window[0x8] * b0[0x8];
  95.       sum -= window[0x9] * b0[0x9];
  96.       sum += window[0xA] * b0[0xA];
  97.       sum -= window[0xB] * b0[0xB];
  98.       sum += window[0xC] * b0[0xC];
  99.       sum -= window[0xD] * b0[0xD];
  100.       sum += window[0xE] * b0[0xE];
  101.       sum -= window[0xF] * b0[0xF];
  102.       WRITE_SAMPLE(samples,sum,clip);
  103.     }
  104.     {
  105.       real sum;
  106.       sum  = window[0x0] * b0[0x0];
  107.       sum += window[0x2] * b0[0x2];
  108.       sum += window[0x4] * b0[0x4];
  109.       sum += window[0x6] * b0[0x6];
  110.       sum += window[0x8] * b0[0x8];
  111.       sum += window[0xA] * b0[0xA];
  112.       sum += window[0xC] * b0[0xC];
  113.       sum += window[0xE] * b0[0xE];
  114.       WRITE_SAMPLE(samples,sum,clip);
  115.       b0-=0x10,window-=0x20,samples+=step;
  116.     }
  117.     window += bo1<<1;
  118.     for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step)
  119.     {
  120.       real sum;
  121.       sum = -window[-0x1] * b0[0x0];
  122.       sum -= window[-0x2] * b0[0x1];
  123.       sum -= window[-0x3] * b0[0x2];
  124.       sum -= window[-0x4] * b0[0x3];
  125.       sum -= window[-0x5] * b0[0x4];
  126.       sum -= window[-0x6] * b0[0x5];
  127.       sum -= window[-0x7] * b0[0x6];
  128.       sum -= window[-0x8] * b0[0x7];
  129.       sum -= window[-0x9] * b0[0x8];
  130.       sum -= window[-0xA] * b0[0x9];
  131.       sum -= window[-0xB] * b0[0xA];
  132.       sum -= window[-0xC] * b0[0xB];
  133.       sum -= window[-0xD] * b0[0xC];
  134.       sum -= window[-0xE] * b0[0xD];
  135.       sum -= window[-0xF] * b0[0xE];
  136.       sum -= window[-0x0] * b0[0xF];
  137.       WRITE_SAMPLE(samples,sum,clip);
  138.     }
  139.   }
  140.   *pnt += 128;
  141.   return clip;
  142. }