www.pudn.com > wav_mp3_recorder.rar > coder.c
/*
* coder.c
*
* 22/02/01
* Calculation of coefficient tables for sub band windowing
* analysis filters and mdct.
*/
#include "types.h"
#include "table1.h"
long int
x[2][HAN_SIZE],
z[512];
/*
* L3_window_filter_subband:
* -------------------------
* Overlapping window on PCM samples
* 32 16-bit pcm samples are scaled to fractional 2's complement and
* concatenated to the end of the window buffer #x#. The updated window
* buffer #x# is then windowed by the analysis window #enwindow# to produce
* the windowed sample #z#
* The windowed samples #z# is filtered by the digital filter matrix #filter#
* to produce the subband samples #s#. This done by first selectively
* picking out values from the windowed samples, and then multiplying
* them by the filter matrix, producing 32 subband samples.
*/
void L3_window_filter_subband(unsigned long **buffer, long s[SBLIMIT] , int k)
{
static int off[2];
long y[64],s1,s2;
int i,j;
/* replace 32 oldest samples with 32 new samples */
/* data format depends on mode */
if(config.mpeg.channels == 1)
if(config.wave.channels == 2)
{ /* mono from stereo, sum upper and lower */
for (i=31;i>=0;i--)
{
x[k][i+off[k]] = (((**buffer) >> 16) + (((**buffer) << 16)>>16)) << 15;
(*buffer)++;
}
}
else
{ /* mono data, use upper then lower */
for (i=15;i>=0;i--)
{
x[k][(2*i)+off[k]+1] = (**buffer) << 16;
x[k][(2*i)+off[k]] = ((*(*buffer)++) >> 16) << 16;
}
}
else if(k)
{ /* stereo left, use upper */
for (i=31;i>=0;i--)
x[k][i+off[k]] = (*(*buffer)++) & 0xffff0000;
}
else
{ /* stereo right, use lower */
for (i=31;i>=0;i--)
x[k][i+off[k]] = (*(*buffer)++) << 16;
}
/* shift samples into proper window positions, and window data */
for (i=HAN_SIZE; i--; )
z[i] = mul(x[k][(i+off[k])&(HAN_SIZE-1)],ew[i]);
off[k] = (off[k] + 480) & (HAN_SIZE-1); /* offset is modulo (HAN_SIZE)*/
/* sub sample the windowed data */
for (i=64; i--; )
for (j=8, y[i] = 0; j--; )
y[i] += z[i+(j<<6)];
/* combine sub samples for the simplified matrix calculation */
for (i=0; i<16; i++)
y[i+17] += y[15-i];
for (i=0; i<15; i++)
y[i+33] -= y[63-i];
/* simlplified polyphase filter matrix multiplication */
for (i=16; i--; )
for (j=0, s[i]= 0, s[31-i]=0; j<32; j += 2)
{
s1 = mul(fl[i][j],y[j+16]);
s2 = mul(fl[i][j+1],y[j+17]);
s[i] += s1 + s2;
s[31-i] += s1 - s2;
}
}
/*
* L3_mdct_sub:
* ------------
*/
void L3_mdct_sub(long sb_sample[2][18][SBLIMIT],
long mdct_freq[samp_per_frame2])
{
/* note. we wish to access the array 'mdct_freq[2][2][576]' as
* [2][2][32][18]. (32*18=576),
*/
long (*mdct_enc)[18];
int ch,gr,band,j,k;
long mdct_in[36];
long bu,bd,*m;
//for(gr=0; gr