SyllableLabeler.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* ----------------------------------------------------------------- */
  2. /* The HMM-Based Singing Voice Synthesis System "Sinsy" */
  3. /* developed by Sinsy Working Group */
  4. /* http://sinsy.sourceforge.net/ */
  5. /* ----------------------------------------------------------------- */
  6. /* */
  7. /* Copyright (c) 2009-2015 Nagoya Institute of Technology */
  8. /* Department of Computer Science */
  9. /* */
  10. /* All rights reserved. */
  11. /* */
  12. /* Redistribution and use in source and binary forms, with or */
  13. /* without modification, are permitted provided that the following */
  14. /* conditions are met: */
  15. /* */
  16. /* - Redistributions of source code must retain the above copyright */
  17. /* notice, this list of conditions and the following disclaimer. */
  18. /* - Redistributions in binary form must reproduce the above */
  19. /* copyright notice, this list of conditions and the following */
  20. /* disclaimer in the documentation and/or other materials provided */
  21. /* with the distribution. */
  22. /* - Neither the name of the Sinsy working group nor the names of */
  23. /* its contributors may be used to endorse or promote products */
  24. /* derived from this software without specific prior written */
  25. /* permission. */
  26. /* */
  27. /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
  28. /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  29. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  30. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  31. /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
  32. /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
  33. /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
  34. /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
  35. /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
  36. /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
  37. /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
  38. /* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  39. /* POSSIBILITY OF SUCH DAMAGE. */
  40. /* ----------------------------------------------------------------- */
  41. #include <algorithm>
  42. #include <stdexcept>
  43. #include "SyllableLabeler.h"
  44. #include "PhonemeLabeler.h"
  45. #include "util_log.h"
  46. #include "Deleter.h"
  47. namespace sinsy
  48. {
  49. /*!
  50. constructor
  51. */
  52. SyllableLabeler::SyllableLabeler(const std::string& lang) : language(lang), idxInNote(0), numInNote(0)
  53. {
  54. }
  55. /*!
  56. destructor
  57. */
  58. SyllableLabeler::~SyllableLabeler()
  59. {
  60. std::for_each(children.begin(), children.end(), Deleter<PhonemeLabeler>());
  61. }
  62. /*!
  63. set label
  64. */
  65. void SyllableLabeler::setLabel(ISyllableLabel& label) const
  66. {
  67. label.setPhonemeNum(children.size());
  68. if (numInNote < idxInNote) {
  69. throw std::runtime_error("SyllableLabeler::setLabel() numInNote < idxInNote");
  70. }
  71. label.setPositionInNote(idxInNote, numInNote);
  72. if (!language.empty()) {
  73. label.setLanguage(language);
  74. }
  75. if (!langDependentInfo.empty()) {
  76. label.setLangDependentInfo(langDependentInfo);
  77. }
  78. }
  79. /*!
  80. add phoneme
  81. */
  82. void SyllableLabeler::addChild(PhonemeLabeler* l)
  83. {
  84. children.push_back(l);
  85. }
  86. /*!
  87. get begin interator of phonemes
  88. */
  89. SyllableLabeler::List::const_iterator SyllableLabeler::childBegin() const
  90. {
  91. return children.begin();
  92. }
  93. /*!
  94. get end interator of phonemes
  95. */
  96. SyllableLabeler::List::const_iterator SyllableLabeler::childEnd() const
  97. {
  98. return children.end();
  99. }
  100. /*!
  101. set index in note
  102. */
  103. void SyllableLabeler::setIdxInNote(size_t i)
  104. {
  105. idxInNote = i;
  106. }
  107. /*!
  108. set number in note
  109. */
  110. void SyllableLabeler::setNumInNote(size_t n)
  111. {
  112. numInNote = n;
  113. }
  114. /*!
  115. set language dependent information
  116. */
  117. void SyllableLabeler::setInfo(const std::string& str)
  118. {
  119. langDependentInfo = str;
  120. }
  121. /*!
  122. set phoneme positions
  123. */
  124. void SyllableLabeler::setPhonemePositions()
  125. {
  126. // position
  127. {
  128. const List::iterator itrEnd(children.end());
  129. size_t sz(children.size());
  130. size_t pos(0);
  131. for (List::iterator itr(children.begin()); itrEnd != itr; ++itr) {
  132. (*itr)->setIdxInSyllable(pos);
  133. ++pos;
  134. (*itr)->setNumInSyllable(sz);
  135. }
  136. }
  137. // count from prev vowel
  138. {
  139. size_t count(0);
  140. const List::iterator itrEnd(children.end());
  141. for (List::iterator itr(children.begin()); itrEnd != itr; ++itr) {
  142. const std::string& type((*itr)->getPhonemeType());
  143. if (0 == type.compare(PhonemeInfo::TYPE_VOWEL)) {
  144. count = 1;
  145. } else {
  146. if (0 == type.compare(PhonemeInfo::TYPE_CONSONANT)) {
  147. (*itr)->setCountFromPrevVowel(count);
  148. }
  149. if (0 < count) {
  150. ++count;
  151. }
  152. }
  153. }
  154. }
  155. // count from next vowel
  156. {
  157. size_t count(0);
  158. const List::reverse_iterator itrEnd(children.rend());
  159. for (List::reverse_iterator itr(children.rbegin()); itrEnd != itr; ++itr) {
  160. const std::string& type((*itr)->getPhonemeType());
  161. if (0 == type.compare(PhonemeInfo::TYPE_VOWEL)) {
  162. count = 1;
  163. } else {
  164. if (0 == type.compare(PhonemeInfo::TYPE_CONSONANT)) {
  165. (*itr)->setCountToNextVowel(count);
  166. }
  167. if (0 < count) {
  168. ++count;
  169. }
  170. }
  171. }
  172. }
  173. }
  174. }; // namespace sinsy