vdecode.c 1.3 KB
#include "vadpcm.h"

void
vdecodeframe(FILE *ifile, int *outp, int order, int ***coefTable)

{
    int
        optimalp,
        scale,
        maxlevel = (1<<(SAMPLEBITS-1))-1,
        i,
        j,
        in_vec[FRAMESIZE],
        ix[FRAMESIZE];

    unsigned char
        header,
        c;
    
    
    fread(&header, 1, 1, ifile);
    scale = 1<<(header>>4);
    optimalp = header & 0xf;
    for (i=0; i<FRAMESIZE; i+=2){
        fread(&c, 1, 1, ifile);
        ix[i] = c>>4;
        ix[i+1] = c & 0xf;
        
        if (ix[i]<=maxlevel)
            ix[i] = scale*ix[i];
        else
            ix[i] = -((1<<SAMPLEBITS) - ix[i])*scale;
        
        if (ix[i+1]<=maxlevel)
            ix[i+1] = scale*ix[i+1];
        else
            ix[i+1] = -((1<<SAMPLEBITS) - ix[i+1])*scale;
    }

    for (j=0; j<FRAMESIZE/VECTORSIZE; j++){
        for (i=0; i<VECTORSIZE; i++)
            in_vec[i+order] = ix[j*VECTORSIZE+i];
        if (j==0){
            for (i=0; i<order; i++)
                in_vec[i] = outp[FRAMESIZE-order+i];
        } else {
            for (i=0; i<order; i++)
                in_vec[i] = outp[j*VECTORSIZE-order+i];
        }
        for (i=0; i<VECTORSIZE; i++){
            outp[i+j*VECTORSIZE] =
                inner_product(VECTORSIZE+order, coefTable[optimalp][i], in_vec);
        }
    }
}