All pastes #905488 Raw Edit

Miscellany

public text v1 · immutable
·published 2008-02-15 20:27 UTC
rendered paste body
int VAGdecodebuffer(unsigned char * input, short * out, short * hist1p, short * hist2p) {
    int predict_nr, shift_factor, flags;
    short hist1=*hist1p, hist2=*hist2p;
	int sample;

    int s;
    int i;
    predict_nr = input[0] >> 4;
    shift_factor = input[0] & 0xf;
    flags = input[1];
    for (i=0;i<28;i+=2) {
	s = (short)((input[i/2+2]&0xf)<<12)-1; //+2;
	sample=((s >> shift_factor)+hist1*VAG_f[predict_nr][0]+hist2*VAG_f[predict_nr][1]+0.5);

    if (sample >= 32767)
        sample =  32767;

    else if (sample <= -32768)
        sample = -32768;

	out[i]=sample;

	hist2=hist1;
	hist1=sample;
	s = (short)((input[i/2+2]>>4)<<12)-1; //+2;

	sample=((s >> shift_factor)+hist1*VAG_f[predict_nr][0]+hist2*VAG_f[predict_nr][1]+0.5);

	if (sample >= 32767)
        sample =  32767;

    else if (sample <= -32768)
        sample = -32768;

	out[i+1]=sample;

	hist2=hist1;
	hist1=sample;
    }

    *hist1p=hist1;
    *hist2p=hist2;

    return 0;
}