00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifdef HAVE_CONFIG_H
00014 # include <config.h>
00015 #endif
00016
00017 #include <assert.h>
00018 #include "common.h"
00019 #include "decode_i386.h"
00020
00021 #ifdef WITH_DMALLOC
00022 #include <dmalloc.h>
00023 #endif
00024
00025 static void
00026 I_step_one(PMPSTR mp, unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],struct frame *fr)
00027 {
00028 unsigned int *ba=balloc;
00029 unsigned int *sca = (unsigned int *) scale_index;
00030
00031 assert ( fr->stereo == 1 || fr->stereo == 2 );
00032 if(fr->stereo==2) {
00033 int i;
00034 int jsbound = fr->jsbound;
00035 for (i=0;i<jsbound;i++) {
00036 *ba++ = getbits(mp,4);
00037 *ba++ = getbits(mp,4);
00038 }
00039 for (i=jsbound;i<SBLIMIT;i++)
00040 *ba++ = getbits(mp,4);
00041
00042 ba = balloc;
00043
00044 for (i=0;i<jsbound;i++) {
00045 if ((*ba++))
00046 *sca++ = getbits(mp,6);
00047 if ((*ba++))
00048 *sca++ = getbits(mp,6);
00049 }
00050 for (i=jsbound;i<SBLIMIT;i++)
00051 if ((*ba++)) {
00052 *sca++ = getbits(mp,6);
00053 *sca++ = getbits(mp,6);
00054 }
00055 }
00056 else {
00057 int i;
00058 for (i=0;i<SBLIMIT;i++)
00059 *ba++ = getbits(mp,4);
00060 ba = balloc;
00061 for (i=0;i<SBLIMIT;i++)
00062 if ((*ba++))
00063 *sca++ = getbits(mp,6);
00064 }
00065 }
00066
00067 static void
00068 I_step_two(PMPSTR mp, real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
00069 unsigned int scale_index[2][SBLIMIT],struct frame *fr)
00070 {
00071 int i,n;
00072 int smpb[2*SBLIMIT];
00073 int *sample;
00074 unsigned int *ba;
00075 unsigned int *sca = (unsigned int *) scale_index;
00076
00077 assert ( fr->stereo == 1 || fr->stereo == 2 );
00078 if(fr->stereo == 2) {
00079 int jsbound = fr->jsbound;
00080 real *f0 = fraction[0];
00081 real *f1 = fraction[1];
00082 ba = balloc;
00083 for (sample=smpb,i=0;i<jsbound;i++) {
00084 if ((n = *ba++))
00085 *sample++ = getbits(mp,n+1);
00086 if ((n = *ba++))
00087 *sample++ = getbits(mp,n+1);
00088 }
00089 for (i=jsbound;i<SBLIMIT;i++)
00090 if ((n = *ba++))
00091 *sample++ = getbits(mp,n+1);
00092
00093 ba = balloc;
00094 for (sample=smpb,i=0;i<jsbound;i++) {
00095 if((n=*ba++))
00096 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
00097 else
00098 *f0++ = 0.0;
00099 if((n=*ba++))
00100 *f1++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
00101 else
00102 *f1++ = 0.0;
00103 }
00104 for (i=jsbound;i<SBLIMIT;i++) {
00105 if ((n=*ba++)) {
00106 real samp = (real)( ((-1)<<n) + (*sample++) + 1);
00107 *f0++ = samp * muls[n+1][*sca++];
00108 *f1++ = samp * muls[n+1][*sca++];
00109 }
00110 else
00111 *f0++ = *f1++ = 0.0;
00112 }
00113 for(i=fr->down_sample_sblimit;i<32;i++)
00114 fraction[0][i] = fraction[1][i] = 0.0;
00115 }
00116 else {
00117 real *f0 = fraction[0];
00118 ba = balloc;
00119 for (sample=smpb,i=0;i<SBLIMIT;i++)
00120 if ((n = *ba++))
00121 *sample++ = getbits(mp,n+1);
00122 ba = balloc;
00123 for (sample=smpb,i=0;i<SBLIMIT;i++) {
00124 if((n=*ba++))
00125 *f0++ = (real) ( ((-1)<<n) + (*sample++) + 1) * muls[n+1][*sca++];
00126 else
00127 *f0++ = 0.0;
00128 }
00129 for(i=fr->down_sample_sblimit;i<32;i++)
00130 fraction[0][i] = 0.0;
00131 }
00132 }
00133
00134
00135 int do_layer1(PMPSTR mp, unsigned char *pcm_sample,int *pcm_point)
00136 {
00137 int clip=0;
00138 unsigned int balloc[2*SBLIMIT];
00139 unsigned int scale_index[2][SBLIMIT];
00140 real fraction[2][SBLIMIT];
00141 struct frame *fr=&(mp->fr);
00142 int i,stereo = fr->stereo;
00143 int single = fr->single;
00144
00145 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? (fr->mode_ext<<2)+4 : 32;
00146
00147 if (stereo == 1 || single == 3)
00148 single = 0;
00149
00150 I_step_one(mp,balloc,scale_index,fr);
00151
00152 for (i=0;i<SCALE_BLOCK;i++)
00153 {
00154 I_step_two(mp,fraction,balloc,scale_index,fr);
00155
00156 if(single >= 0)
00157 {
00158 clip += synth_1to1_mono( mp, (real *) fraction[single],pcm_sample,pcm_point);
00159 }
00160 else {
00161 int p1 = *pcm_point;
00162 clip += synth_1to1( mp, (real *) fraction[0],0,pcm_sample,&p1);
00163 clip += synth_1to1( mp, (real *) fraction[1],1,pcm_sample,pcm_point);
00164 }
00165 }
00166
00167 return clip;
00168 }
00169
00170