#include #include #include #include "mulaw.h" #define LC 5 #define LW 10 #define MT 10000000 #define HLEN 1024 unsigned char buff[MT]; static double marcoef(double *xin, int len, double *cret, int m); static double invfl(double *x, int np, double *cret, int m); static double residual(double *xin, int len, double *poly, int m); int main(int argc, char **argv) { int kt, nt, cc, kstart, ichan, k; double samp1, samp2, samp2x, samp3, d1, d2; double vec[2*LW+1], coef[LC+1], err1, err2; int mask = 0377; /*** read the whole file of bytes ***/ for (nt=0; nt -.2 && samp3< .2 && samp1 > -.2 && samp1< .2 && samp2< -.3){ /* d1 = difference samp2 and linear interpolated samp1 & samp3 */ d1 = samp2 - (samp1+samp3)/2; /* complement bits of mulaw and convert to double **/ samp2x = mu_2_float[buff[kt]^mask]; /* d2 = same thing after complementation */ d2 = samp2x - (samp1+samp3)/2; /** use absolute values **/ if(d1<0) d1= -d1; if(d2<0) d2= -d2; if(d2 < d1){ /*** complementation makes a smaller distance ********/ /*** point passes primary tests, compute LPC error ***/ /*** extract 2*LW+1 samples (some maybe modified by earlier steps)*/ for (k= -LW; k<=LW; k++) vec[k+LW] = mu_2_float[(int)buff[kt+2*k]]; /*** get LC long polynomial and error **/ (void)marcoef(vec,2*LW+1,coef,LC); err1= residual(vec,2*LW+1,coef,LC); /*** now try the same thing, but with the modified value **/ vec[LW]=samp2x; (void)marcoef(vec,2*LW+1,coef,LC); err2= residual(vec,2*LW+1,coef,LC); /*** if the modification is _MUCH_ better, accept it ***/ if(err2 < err1/10){ fprintf(stderr,"modified %d %g %g %g\n", (kt-HLEN)/2,samp2,samp2x,err1/err2); buff[kt] ^= mask; } } } } } /*** write out the modified data ***/ for (kt=0; kt