lpc_test_main.c 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 2001 */
  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: August 2000 */
  35. /*************************************************************************/
  36. /* */
  37. /* Resynthesize from lpc coefficients plus a residual */
  38. /* */
  39. /*************************************************************************/
  40. #include <stdio.h>
  41. #include "cst_wave.h"
  42. #include "cst_track.h"
  43. #include "cst_sigpr.h"
  44. int main(int argc, char **argv)
  45. {
  46. /* need that cool argument parser */
  47. cst_wave *w,*res;
  48. cst_track *lpc;
  49. cst_lpcres *lpcres;
  50. int i,j;
  51. float lpcmin = -2.709040;
  52. float lpcrange = 2.328840+2.709040;
  53. unsigned short *bbb;
  54. if (argc != 4)
  55. {
  56. fprintf(stderr,"usage: lpc_test LPC RESIDUAL WAVEFILE\n");
  57. return 1;
  58. }
  59. lpc = new_track();
  60. cst_track_load_est(lpc,argv[1]);
  61. res = new_wave();
  62. cst_wave_load_riff(res,argv[2]);
  63. lpcres = new_lpcres();
  64. lpcres_resize_frames(lpcres,lpc->num_frames);
  65. lpcres->num_channels = lpc->num_channels-1;
  66. for (i=0; i<lpc->num_frames; i++)
  67. {
  68. bbb = cst_alloc(unsigned short,lpc->num_channels-1);
  69. for (j=1; j<lpc->num_channels; j++)
  70. bbb[j-1] = (unsigned short)
  71. (((lpc->frames[i][j]-lpcmin)/lpcrange)*65535);
  72. lpcres->frames[i] = bbb;
  73. lpcres->sizes[i] = track_frame_shift(lpc,i)*res->sample_rate;
  74. }
  75. lpcres_resize_samples(lpcres,res->num_samples);
  76. lpcres->lpc_min = lpcmin;
  77. lpcres->lpc_range = lpcrange;
  78. lpcres->sample_rate = res->sample_rate;
  79. for (i=0; i<res->num_samples; i++)
  80. lpcres->residual[i] = cst_short_to_ulaw(res->samples[i]);
  81. w = lpc_resynth(lpcres);
  82. cst_wave_save_riff(w,argv[3]);
  83. return 0;
  84. }