decode_i386.c

Go to the documentation of this file.
00001 /*
00002  * Mpeg Layer-1,2,3 audio decoder
00003  * ------------------------------
00004  * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
00005  * modified by Aleksander Korzynski (Olcios) '2003
00006  * See also 'README'
00007  *
00008  * slighlty optimized for machines without autoincrement/decrement.
00009  * The performance is highly compiler dependend. Maybe
00010  * the decode.c version for 'normal' processor may be faster
00011  * even for Intel processors.
00012  */
00013 
00014 /* $Id: decode_i386.c,v 1.17 2004/04/14 22:15:44 robert Exp $ */
00015 
00016 #ifdef HAVE_CONFIG_H
00017 #include <config.h>
00018 #endif
00019 
00020 #ifdef STDC_HEADERS
00021 # include <stdlib.h>
00022 # include <string.h>
00023 #else
00024 # ifndef HAVE_STRCHR
00025 #  define strchr index
00026 #  define strrchr rindex
00027 # endif
00028 char *strchr (), *strrchr ();
00029 # ifndef HAVE_MEMCPY
00030 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
00031 #  define memmove(d, s, n) bcopy ((s), (d), (n))
00032 # endif
00033 #endif
00034 
00035 #if defined(__riscos__) && defined(FPA10)
00036 #include        "ymath.h"
00037 #else
00038 #include        <math.h>
00039 #endif
00040 
00041 #include "decode_i386.h"
00042 #include "dct64_i386.h"
00043 #include "tabinit.h"
00044 
00045 #ifdef WITH_DMALLOC
00046 #include <dmalloc.h>
00047 #endif
00048 
00049 
00050  /* old WRITE_SAMPLE_CLIPPED */
00051 #define WRITE_SAMPLE_CLIPPED(samples,sum,clip) \
00052   if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
00053   else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
00054   else { *(samples) = ((sum)>0 ? (sum)+0.5 : (sum)-0.5) ; }
00055 
00056 #define WRITE_SAMPLE_UNCLIPPED(samples,sum,clip) \
00057   *samples = sum;
00058 
00059 
00060  /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1_mono* functions */
00061 #define SYNTH_1TO1_MONO_CLIPCHOICE(TYPE,SYNTH_1TO1)                    \
00062   TYPE samples_tmp[64];                                                \
00063   TYPE *tmp1 = samples_tmp;                                            \
00064   int i,ret;                                                           \
00065   int pnt1 = 0;                                                        \
00066                                                                        \
00067   ret = SYNTH_1TO1 (mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1); \
00068   out += *pnt;                                                         \
00069                                                                        \
00070   for(i=0;i<32;i++) {                                                  \
00071     *( (TYPE *) out) = *tmp1;                                          \
00072     out += sizeof(TYPE);                                               \
00073     tmp1 += 2;                                                         \
00074   }                                                                    \
00075   *pnt += 32*sizeof(TYPE);                                             \
00076                                                                        \
00077   return ret; 
00078 
00079 
00080 int synth_1to1_mono(PMPSTR mp, real *bandPtr,unsigned char *out,int *pnt)
00081 {
00082   SYNTH_1TO1_MONO_CLIPCHOICE(short,synth_1to1)
00083 }
00084 
00085 int synth_1to1_mono_unclipped(PMPSTR mp, real *bandPtr, unsigned char *out,int *pnt)
00086 {
00087   SYNTH_1TO1_MONO_CLIPCHOICE(real,synth_1to1_unclipped)
00088 }
00089 
00090 /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1* functions */
00091 #define SYNTH_1TO1_CLIPCHOICE(TYPE,WRITE_SAMPLE)         \
00092   static const int step = 2;                             \
00093   int bo;                                                \
00094   TYPE *samples = (TYPE *) (out + *pnt);                 \
00095                                                          \
00096   real *b0,(*buf)[0x110];                                \
00097   int clip = 0;                                          \
00098   int bo1;                                               \
00099                                                          \
00100   bo = mp->synth_bo;                                     \
00101                                                          \
00102   if(!channel) {                                         \
00103     bo--;                                                \
00104     bo &= 0xf;                                           \
00105     buf = mp->synth_buffs[0];                            \
00106   }                                                      \
00107   else {                                                 \
00108     samples++;                                           \
00109     buf = mp->synth_buffs[1];                            \
00110   }                                                      \
00111                                                          \
00112   if(bo & 0x1) {                                         \
00113     b0 = buf[0];                                         \
00114     bo1 = bo;                                            \
00115     dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);        \
00116   }                                                      \
00117   else {                                                 \
00118     b0 = buf[1];                                         \
00119     bo1 = bo+1;                                          \
00120     dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);                \
00121   }                                                      \
00122                                                          \
00123   mp->synth_bo = bo;                                     \
00124                                                          \
00125   {                                                      \
00126     int j;                                               \
00127     real *window = decwin + 16 - bo1;                    \
00128                                                          \
00129     for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) \
00130     {                                                    \
00131       real sum;                                          \
00132       sum  = window[0x0] * b0[0x0];                      \
00133       sum -= window[0x1] * b0[0x1];                      \
00134       sum += window[0x2] * b0[0x2];                      \
00135       sum -= window[0x3] * b0[0x3];                      \
00136       sum += window[0x4] * b0[0x4];                      \
00137       sum -= window[0x5] * b0[0x5];                      \
00138       sum += window[0x6] * b0[0x6];                      \
00139       sum -= window[0x7] * b0[0x7];                      \
00140       sum += window[0x8] * b0[0x8];                      \
00141       sum -= window[0x9] * b0[0x9];                      \
00142       sum += window[0xA] * b0[0xA];                      \
00143       sum -= window[0xB] * b0[0xB];                      \
00144       sum += window[0xC] * b0[0xC];                      \
00145       sum -= window[0xD] * b0[0xD];                      \
00146       sum += window[0xE] * b0[0xE];                      \
00147       sum -= window[0xF] * b0[0xF];                      \
00148                                                          \
00149       WRITE_SAMPLE (samples,sum,clip);                   \
00150     }                                                    \
00151                                                          \
00152     {                                                    \
00153       real sum;                                          \
00154       sum  = window[0x0] * b0[0x0];                      \
00155       sum += window[0x2] * b0[0x2];                      \
00156       sum += window[0x4] * b0[0x4];                      \
00157       sum += window[0x6] * b0[0x6];                      \
00158       sum += window[0x8] * b0[0x8];                      \
00159       sum += window[0xA] * b0[0xA];                      \
00160       sum += window[0xC] * b0[0xC];                      \
00161       sum += window[0xE] * b0[0xE];                      \
00162       WRITE_SAMPLE (samples,sum,clip);                   \
00163       b0-=0x10,window-=0x20,samples+=step;               \
00164     }                                                    \
00165     window += bo1<<1;                                    \
00166                                                          \
00167     for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) \
00168     {                                                    \
00169       real sum;                                          \
00170       sum = -window[-0x1] * b0[0x0];                     \
00171       sum -= window[-0x2] * b0[0x1];                     \
00172       sum -= window[-0x3] * b0[0x2];                     \
00173       sum -= window[-0x4] * b0[0x3];                     \
00174       sum -= window[-0x5] * b0[0x4];                     \
00175       sum -= window[-0x6] * b0[0x5];                     \
00176       sum -= window[-0x7] * b0[0x6];                     \
00177       sum -= window[-0x8] * b0[0x7];                     \
00178       sum -= window[-0x9] * b0[0x8];                     \
00179       sum -= window[-0xA] * b0[0x9];                     \
00180       sum -= window[-0xB] * b0[0xA];                     \
00181       sum -= window[-0xC] * b0[0xB];                     \
00182       sum -= window[-0xD] * b0[0xC];                     \
00183       sum -= window[-0xE] * b0[0xD];                     \
00184       sum -= window[-0xF] * b0[0xE];                     \
00185       sum -= window[-0x0] * b0[0xF];                     \
00186                                                          \
00187       WRITE_SAMPLE (samples,sum,clip);                   \
00188     }                                                    \
00189   }                                                      \
00190   *pnt += 64*sizeof(TYPE);                               \
00191                                                          \
00192   return clip;                                           
00193 
00194 
00195 int synth_1to1(PMPSTR mp, real *bandPtr,int channel,unsigned char *out, int *pnt)
00196 {
00197   SYNTH_1TO1_CLIPCHOICE(short,WRITE_SAMPLE_CLIPPED)
00198 }
00199 
00200 int synth_1to1_unclipped(PMPSTR mp, real *bandPtr,int channel, unsigned char *out, int *pnt)
00201 {
00202   SYNTH_1TO1_CLIPCHOICE(real,WRITE_SAMPLE_UNCLIPPED)
00203 }
00204 
00205 

Generated on Sun Dec 2 11:34:21 2007 for LAME by  doxygen 1.5.2