de.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. de.c
  3. David Rowe
  4. Sep 26 2012
  5. Takes audio from a file, de-emphasises, and sends to output file.
  6. */
  7. #include <assert.h>
  8. #include <errno.h>
  9. #include <math.h>
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include "lpc.h"
  14. #define N 80
  15. int main(int argc, char *argv[]) {
  16. FILE *fin, *fout;
  17. short buf[N];
  18. float Sn[N], Sn_de[N];
  19. float de_mem = 0.0;
  20. int i;
  21. if (argc != 3) {
  22. printf("usage: de InputRawSpeechFile OutputRawSpeechFile\n");
  23. printf("e.g de input.raw output.raw");
  24. exit(1);
  25. }
  26. if (strcmp(argv[1], "-") == 0) fin = stdin;
  27. else if ( (fin = fopen(argv[1],"rb")) == NULL ) {
  28. fprintf(stderr, "Error opening input speech file: %s: %s.\n",
  29. argv[1], strerror(errno));
  30. exit(1);
  31. }
  32. if (strcmp(argv[2], "-") == 0) fout = stdout;
  33. else if ( (fout = fopen(argv[2],"wb")) == NULL ) {
  34. fprintf(stderr, "Error opening output speech file: %s: %s.\n",
  35. argv[2], strerror(errno));
  36. exit(1);
  37. }
  38. while(fread(buf, sizeof(short), N, fin) == N) {
  39. for(i=0; i<N; i++)
  40. Sn[i] = buf[i];
  41. de_emp(Sn_de, Sn, &de_mem, N);
  42. for(i=0; i<N; i++)
  43. buf[i] = Sn_de[i];
  44. fwrite(buf, sizeof(short), N, fout);
  45. }
  46. fclose(fin);
  47. fclose(fout);
  48. return 0;
  49. }