rfc_main.c 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 2010 */
  6. /* All Rights Reserved. */
  7. /* */
  8. /* Permission is hereby granted, free of charge, to use and distribute */
  9. /* this software and its documentation without restriction, including */
  10. /* without limitation the rights to use, copy, modify, merge, publish, */
  11. /* distribute, sublicense, and/or sell copies of this work, and to */
  12. /* permit persons to whom this work is furnished to do so, subject to */
  13. /* the following conditions: */
  14. /* 1. The code must retain the above copyright notice, this list of */
  15. /* conditions and the following disclaimer. */
  16. /* 2. Any modifications must be clearly marked as such. */
  17. /* 3. Original authors' names are not deleted. */
  18. /* 4. The authors' names are not used to endorse or promote products */
  19. /* derived from this software without specific prior written */
  20. /* permission. */
  21. /* */
  22. /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
  23. /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
  24. /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
  25. /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
  26. /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
  27. /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
  28. /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
  29. /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
  30. /* THIS SOFTWARE. */
  31. /* */
  32. /*************************************************************************/
  33. /* Author: Alan W Black (awb@cs.cmu.edu) */
  34. /* Date: April 2010 */
  35. /*************************************************************************/
  36. /* */
  37. /* Convert between lpc and rfc */
  38. /*************************************************************************/
  39. #include <stdio.h>
  40. #include "cst_track.h"
  41. #include "cst_tokenstream.h"
  42. #include "cst_args.h"
  43. #include "cst_math.h"
  44. void lpc2ref(const float *lpc, float *rfc, int order);
  45. void ref2lpc(const float *rfc, float *lpc, int order);
  46. int main(int argc, char **argv)
  47. {
  48. cst_track *t1, *t2;
  49. cst_val *files;
  50. cst_features *args;
  51. int i;
  52. int tolpc = 0;
  53. const char *f1, *f2;
  54. args = new_features();
  55. files =
  56. cst_args(argv,argc,
  57. "usage: rfc OPTIONS INTRACK1 OUTTRACK2\n"
  58. "Convert between LPC and RFC\n"
  59. "-tolpc from RFC to LPC\n"
  60. "-torfc from LPC to RFC\n",
  61. args);
  62. f1 = val_string(val_car(files));
  63. f2 = val_string(val_car(val_cdr(files)));
  64. t1 = new_track();
  65. if (cst_track_load_est(t1,f1) != CST_OK_FORMAT)
  66. {
  67. fprintf(stderr,
  68. "rfc: can't read file or wrong format \"%s\"\n",
  69. f1);
  70. return -1;
  71. }
  72. if (feat_present(args,"-tolpc"))
  73. tolpc = 1;
  74. if (feat_present(args,"-torfc"))
  75. tolpc = 0;
  76. t2 = cst_track_copy(t1);
  77. for (i=0; i<t2->num_frames; i++)
  78. {
  79. if (tolpc)
  80. ref2lpc(&(t1->frames[i][1]),&(t2->frames[i][1]),t2->num_channels-1);
  81. else
  82. lpc2ref(&(t1->frames[i][1]),&(t2->frames[i][1]),t2->num_channels-1);
  83. }
  84. cst_track_save_est(t2,f2);
  85. return 0;
  86. }