int main(int argc, char *argv[]) { FILE *fin; /* input speech files */ short buf[N]; /* buffer of 16 bit speech samples */ float Sn[P+N]; /* input speech samples */ float E; float ak[P+1]; /* LP coeffs */ float ak_[P+1]; /* quantised LP coeffs */ float lsp[P]; float lsp_[P]; /* quantised LSPs */ int roots; /* number of LSP roots found */ int frames; /* frames processed so far */ int i; /* loop variables */ SpeexBits bits; float sd; /* SD for this frame */ float totsd; /* accumulated SD so far */ int gt2,gt4; /* number of frames > 2 and 4 dB SD */ int unstables; /* number of unstable LSP frames */ if (argc < 2) { printf("usage: %s InputFile\n", argv[0]); exit(0); } /* Open files */ if ((fin = fopen(argv[1],"rb")) == NULL) { printf("Error opening input file: %s\n",argv[1]); exit(0); } /* Initialise */ frames = 0; for(i=0; i<P; i++) { Sn[i] = 0.0; } ak_[0] = 1.0; speex_bits_init(&bits); totsd = 0.0; unstables = 0; gt2 = 0; gt4 = 0; /* Main loop */ while( (fread(buf,sizeof(short),N,fin)) == N) { frames++; for(i=0; i<N; i++) Sn[P+i] = (float)buf[i]; /* convert to LSP domain and back */ find_aks(&Sn[P], ak, N, P, &E); roots = lpc_to_lsp(&ak[1], P , lsp, 10, LSP_DELTA1, NULL); if (roots == P) { speex_bits_reset(&bits); lsp_quant_lbr(lsp, lsp_, P, &bits); lsp_to_lpc(lsp_, &ak_[1], P, NULL); /* measure spectral distortion */ sd = spectral_dist(ak, ak_, P, NDFT); if (sd > 2.0) gt2++; if (sd > 4.0) gt4++; totsd += sd; } else unstables++; } fclose(fin); printf("frames = %d Av sd = %3.2f dB", frames, totsd/frames); printf(" >2 dB %3.2f%% >4 dB %3.2f%% unstables: %d\n",gt2*100.0/frames, gt4*100.0/frames, unstables); return 0; }
int main(int argc, char *argv[]) { FILE *fin,*fres; /* input and output files */ short buf[N]; /* buffer of 16 bit speech samples */ float Sn[P+N]; /* input speech samples */ float res[N]; /* residual after LPC filtering */ float E; float ak[P+1]; /* LP coeffs */ int frames; /* frames processed so far */ int i; /* loop variables */ if (argc < 3) { printf("usage: %s InputFile ResidualFile\n", argv[0]); exit(1); } /* Open files */ if (strcmp(argv[1], "-") == 0) fin = stdin; else if ((fin = fopen(argv[1],"rb")) == NULL) { printf("Error opening input file: %s\n",argv[1]); exit(0); } if (strcmp(argv[2], "-") == 0) fres = stdout; else if ((fres = fopen(argv[2],"wb")) == NULL) { printf("Error opening output residual file: %s\n",argv[2]); exit(0); } /* Initialise */ frames = 0; for(i=0; i<P; i++) { Sn[i] = 0.0; } /* Main loop */ while( (fread(buf,sizeof(short),N,fin)) == N) { frames++; for(i=0; i<P; i++) Sn[i] = Sn[i+N]; for(i=0; i<N; i++) Sn[P+i] = (float)buf[i]; /* Determine {ak} and filter to find residual */ find_aks(&Sn[P], ak, N, P, &E); inverse_filter(&Sn[P], ak, N, res, P); for(i=0; i<N; i++) buf[i] = (short)res[i]; fwrite(buf,sizeof(short),N,fres); if (fres == stdout) fflush(stdout); if (fin == stdin) fflush(stdin); } fclose(fin); fclose(fres); return 0; }