cst_sts.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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: January 2001 */
  35. /*************************************************************************/
  36. /* */
  37. /* Short term signals */
  38. /* */
  39. /*************************************************************************/
  40. #ifndef _CST_STS_H__
  41. #define _CST_STS_H__
  42. /* Need some lower level functions in case we are doing streaming */
  43. #include "cst_wave.h"
  44. #include "cst_audio.h"
  45. /* The short term signal (sts) structure is the basic unit data info */
  46. /* it may be diphones or general units. Indexes and names are held */
  47. /* else where, this information plus the indexes in the Unit relation */
  48. /* allow reconstruction of the signal itself */
  49. struct cst_sts_struct {
  50. const unsigned short *frame;
  51. const int size; /* in samples */
  52. const unsigned char *residual;
  53. };
  54. typedef struct cst_sts_struct cst_sts;
  55. /* Because many C compilers can't compile when there are 100Ks of symbols */
  56. /* We store the sts in pages. Each page of stss gets compiled into an */
  57. /* array in separate files thus reducing the number of symbols -- but */
  58. /* introducing an extra dereference */
  59. struct cst_sts_paged_struct {
  60. /* const unsigned short frame_offset; */
  61. const unsigned int frame_offset;
  62. const unsigned short res_size;
  63. const unsigned int res_offset;
  64. const unsigned short *frame_page;
  65. const unsigned char *res_page;
  66. };
  67. typedef struct cst_sts_paged_struct cst_sts_paged;
  68. /* This represents a database of short-term signals. */
  69. struct cst_sts_list_struct {
  70. /* If the sts are compiled in, this will point to them. */
  71. const cst_sts *sts;
  72. /* Or if the data is paged in different structures */
  73. const cst_sts_paged *sts_paged;
  74. /* Or we could have these set (or set later) */
  75. const unsigned short *frames;
  76. const unsigned char *residuals;
  77. const unsigned int *resoffs;
  78. const unsigned char *ressizes;
  79. int num_sts; /* But I don't think you need that number */
  80. int num_channels; /* typically lpc order */
  81. int sample_rate;
  82. float coeff_min; /* used for decoding the short representation */
  83. float coeff_range; /* for coefficients */
  84. const char *codec; /* encoding type for residual */
  85. };
  86. typedef struct cst_sts_list_struct cst_sts_list;
  87. /* This is used to represent a newly constructed waveform to be synthed */
  88. struct cst_lpcres_struct {
  89. const unsigned short **frames;
  90. int *times;
  91. int num_frames;
  92. int num_channels;
  93. float lpc_min;
  94. float lpc_range;
  95. int num_samples;
  96. int sample_rate;
  97. int *sizes;
  98. unsigned char *residual;
  99. /* Optional call back function */
  100. cst_audio_streaming_info *asi;
  101. /* Expensive decoding can be delayed until resynthesis, hence */
  102. /* streaming will be more useful as the decoding will happen */
  103. /* during playback time */
  104. const unsigned char **packed_residuals;
  105. int delayed_decoding; /* 1 if decoding happens at streaming time */
  106. };
  107. typedef struct cst_lpcres_struct cst_lpcres;
  108. cst_lpcres *new_lpcres();
  109. void delete_lpcres(cst_lpcres *l);
  110. float lpcres_frame_shift(cst_lpcres *t, int frame);
  111. void lpcres_resize_frames(cst_lpcres *l,int num_frames);
  112. void lpcres_resize_samples(cst_lpcres *l,int num_samples);
  113. cst_sts_list *new_sts_list();
  114. void delete_sts_list(cst_sts_list *l);
  115. const unsigned short * get_sts_frame(const cst_sts_list *sts_list, int frame);
  116. const unsigned char * get_sts_residual(const cst_sts_list *sts_list, int frame);
  117. const unsigned char * get_sts_residual_fixed(const cst_sts_list *sts_list, int frame);
  118. int get_frame_size(const cst_sts_list *sts_list, int frame);
  119. int get_unit_size(const cst_sts_list *s,int start, int end);
  120. CST_VAL_USER_TYPE_DCLS(lpcres,cst_lpcres)
  121. CST_VAL_USER_TYPE_DCLS(sts_list,cst_sts_list)
  122. #endif