VOICE_clunits.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*************************************************************************/
  2. /* */
  3. /* Language Technologies Institute */
  4. /* Carnegie Mellon University */
  5. /* Copyright (c) 1999-2000 */
  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 2001 */
  35. /*************************************************************************/
  36. /* */
  37. /* A simple clunits/ldom voice defintion */
  38. /* */
  39. /*************************************************************************/
  40. #include <string.h>
  41. #include "flite.h"
  42. #include "cst_clunits.h"
  43. #include "__FLITELANG__.h"
  44. #include "__FLITELEX__.h"
  45. static char *__VOICENAME___unit_name(cst_item *s);
  46. extern cst_clunit_db __VOICENAME___db;
  47. cst_voice *__VOICENAME___clunits = NULL;
  48. extern const cst_cart __VOICENAME___dur_cart;
  49. extern const dur_stat * const __VOICENAME___dur_stats[];
  50. cst_voice *register___VOICENAME__(const char *voxdir)
  51. {
  52. cst_voice *v;
  53. cst_lexicon *lex;
  54. if (__VOICENAME___clunits)
  55. return __VOICENAME___clunits; /* Already registered */
  56. v = new_voice();
  57. v->name = "__NICKNAME__";
  58. /* Sets up language specific parameters in the __VOICENAME__. */
  59. __FLITELANG___init(v);
  60. /* Things that weren't filled in already. */
  61. flite_feat_set_string(v->features,"name","__VOICENAME__");
  62. /* Duration model */
  63. flite_feat_set(v->features,"dur_cart",cart_val(&__VOICENAME___dur_cart));
  64. flite_feat_set(v->features,"dur_stats",dur_stats_val((dur_stats *)__VOICENAME___dur_stats));
  65. /* Lexicon */
  66. lex = __FLITELEX___init();
  67. flite_feat_set(v->features,"lexicon",lexicon_val(lex));
  68. flite_feat_set(v->features,"postlex_func",uttfunc_val(lex->postlex));
  69. /* Waveform synthesis */
  70. flite_feat_set(v->features,"wave_synth_func",uttfunc_val(&clunits_synth));
  71. flite_feat_set(v->features,"clunit_db",clunit_db_val(&__VOICENAME___db));
  72. flite_feat_set_int(v->features,"sample_rate",__VOICENAME___db.sts->sample_rate);
  73. flite_feat_set_string(v->features,"join_type","simple_join");
  74. flite_feat_set_string(v->features,"resynth_type","fixed");
  75. if ((voxdir != NULL) &&
  76. (__VOICENAME___db.sts->sts == NULL) &&
  77. (__VOICENAME___db.sts->sts_paged == NULL) &&
  78. (__VOICENAME___db.sts->frames == NULL))
  79. flite_mmap_clunit_voxdata(voxdir,v);
  80. /* Unit selection */
  81. __VOICENAME___db.unit_name_func = __VOICENAME___unit_name;
  82. __VOICENAME___clunits = v;
  83. return __VOICENAME___clunits;
  84. }
  85. void unregister___VOICENAME__(cst_voice *vox)
  86. {
  87. if (vox != __VOICENAME___clunits)
  88. return;
  89. delete_voice(vox);
  90. __VOICENAME___clunits = NULL;
  91. }
  92. static const char *__VOICENAME___nextvoicing(cst_item *s)
  93. {
  94. if (cst_streq("+",flite_ffeature_string(s,"n.ph_vc")))
  95. return "V";
  96. else if (cst_streq("+",flite_ffeature_string(s,"n.ph_cvox")))
  97. return "CVox";
  98. else
  99. return "UV";
  100. }
  101. static char *__VOICENAME___unit_name(cst_item *s)
  102. {
  103. const char *name;
  104. /* This *is* long enough as long as you don't change external things */
  105. char cname[30];
  106. name = flite_ffeature_string(s,"name");
  107. /* Comment this out if you have more complex unit names */
  108. #if 1
  109. if (1 == 1)
  110. return cst_strdup(name);
  111. else
  112. #endif
  113. if (cst_streq("+",flite_ffeature_string(s,"ph_vc")))
  114. {
  115. cst_sprintf(cname,"%s_%s_%s",name,
  116. flite_ffeature_string(s,"R:SylStructure.parent.stress"),
  117. __VOICENAME___nextvoicing(s));
  118. }
  119. else
  120. {
  121. cst_sprintf(cname,"%s_%s",name,
  122. __VOICENAME___nextvoicing(s));
  123. }
  124. return cst_strdup(cname);
  125. }