sinsy.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. #ifndef SINSY_H_
  42. #define SINSY_H_
  43. #ifdef __cplusplus
  44. #include <string>
  45. #include <vector>
  46. namespace sinsy
  47. {
  48. typedef size_t SuddenDynamicsType;
  49. const SuddenDynamicsType SUDDENDYNAMICSTYPE_PPPP = 0;
  50. const SuddenDynamicsType SUDDENDYNAMICSTYPE_PPP = 1;
  51. const SuddenDynamicsType SUDDENDYNAMICSTYPE_PP = 2;
  52. const SuddenDynamicsType SUDDENDYNAMICSTYPE_P = 3;
  53. const SuddenDynamicsType SUDDENDYNAMICSTYPE_MP = 4;
  54. const SuddenDynamicsType SUDDENDYNAMICSTYPE_N = 5;
  55. const SuddenDynamicsType SUDDENDYNAMICSTYPE_MF = 6;
  56. const SuddenDynamicsType SUDDENDYNAMICSTYPE_F = 7;
  57. const SuddenDynamicsType SUDDENDYNAMICSTYPE_FF = 8;
  58. const SuddenDynamicsType SUDDENDYNAMICSTYPE_FFF = 9;
  59. const SuddenDynamicsType SUDDENDYNAMICSTYPE_FFFF = 10;
  60. typedef size_t GradualDynamicsType;
  61. const GradualDynamicsType GRADUALDYNAMICSTYPE_CRESCENDO_BEGIN = 0;
  62. const GradualDynamicsType GRADUALDYNAMICSTYPE_CRESCENDO_END = 1;
  63. const GradualDynamicsType GRADUALDYNAMICSTYPE_DIMINUENDO_BEGIN = 2;
  64. const GradualDynamicsType GRADUALDYNAMICSTYPE_DIMINUENDO_END = 3;
  65. typedef size_t TieType;
  66. const TieType TIETYPE_NONE = 0;
  67. const TieType TIETYPE_BEGIN = 1;
  68. const TieType TIETYPE_END = 2;
  69. typedef size_t SlurType;
  70. const SlurType SLURTYPE_NONE = 0;
  71. const SlurType SLURTYPE_BEGIN = 1;
  72. const SlurType SLURTYPE_END = 2;
  73. typedef size_t SyllabicType;
  74. const SyllabicType SYLLABICTYPE_SINGLE = 0;
  75. const SyllabicType SYLLABICTYPE_BEGIN = 1;
  76. const SyllabicType SYLLABICTYPE_MIDDLE = 2;
  77. const SyllabicType SYLLABICTYPE_END = 3;
  78. typedef size_t ModeType;
  79. const ModeType MODETYPE_MAJOR = 0;
  80. const ModeType MODETYPE_MINOR = 1;
  81. typedef size_t ClefType;
  82. const ClefType CLEFTYPE_DEFAULT = 0;
  83. const ClefType CLEFTYPE_G = 1;
  84. const ClefType CLEFTYPE_F = 2;
  85. const ClefType CLEFTYPE_C = 3;
  86. class SynthConditionImpl;
  87. class SinsyImpl;
  88. class IScore
  89. {
  90. public:
  91. //! destructor
  92. virtual ~IScore() {}
  93. //! set encoding
  94. virtual bool setEncoding(const std::string& encoding) = 0;
  95. //! add key mark
  96. virtual bool addKeyMark(ModeType modeType, int fifths) = 0;
  97. //! add beat mark (beats/beatType) to end of score: default beat mark is 4/4
  98. virtual bool addBeatMark(size_t beats, size_t beatType) = 0;
  99. //! add tempo mark to end of score: default tempo is 100bps
  100. virtual bool addTempoMark(double tempo) = 0;
  101. //! add dynamics mark (sudden changes) to end of score
  102. virtual bool addSuddenDynamicsMark(SuddenDynamicsType suddenDynamicsType) = 0;
  103. //! add dynamics mark (gradual changes) to end of score
  104. virtual bool addGradualDynamicsMark(GradualDynamicsType gradualDynamicsType) = 0;
  105. //! add note to end of score
  106. virtual bool addNote(size_t duration, const std::string& lyric, size_t pitch, bool accent, bool staccato, TieType tieType, SlurType slurType, SyllabicType syllabicType, bool breath = false) = 0;
  107. //! add rest to end of score
  108. virtual bool addRest(size_t duration) = 0;
  109. };
  110. class SynthCondition
  111. {
  112. public:
  113. //! constructor
  114. SynthCondition();
  115. //! destructor
  116. virtual ~SynthCondition();
  117. //! set play flag
  118. void setPlayFlag();
  119. //! unset play flag
  120. void unsetPlayFlag();
  121. //! set file path to save RIFF format file
  122. void setSaveFilePath(const std::string& filePath);
  123. //! unset file path to save RIFF format file
  124. void unsetSaveFilePath();
  125. //! set waveform buffer
  126. void setWaveformBuffer(std::vector<double>& waveform);
  127. //! unset waveform buffer
  128. void unsetWaveformBuffer();
  129. private:
  130. //! copy constructor (donot use)
  131. SynthCondition(const SynthCondition&);
  132. //! assignment operator (donot use)
  133. SynthCondition& operator=(const SynthCondition&);
  134. //! implementation
  135. SynthConditionImpl* impl;
  136. friend class Sinsy;
  137. };
  138. class Sinsy
  139. {
  140. public:
  141. //! constructor
  142. Sinsy();
  143. //! destructor
  144. virtual ~Sinsy();
  145. //! set languages
  146. bool setLanguages(const std::string& languages, const std::string& configs);
  147. //! load voice files
  148. bool loadVoices(const std::vector<std::string>& voices);
  149. //! set encoding
  150. virtual bool setEncoding(const std::string& encoding);
  151. //! add key mark
  152. virtual bool addKeyMark(ModeType modeType, int fifths);
  153. //! add beat mark (beats/beattype) to end of score: default beat mark is 4/4
  154. virtual bool addBeatMark(size_t beats, size_t beattype);
  155. //! add tempo mark to end of score: default tempo is 100bps
  156. virtual bool addTempoMark(double tempo);
  157. //! add dynamics mark (sudden changes) to end of score
  158. virtual bool addSuddenDynamicsMark(SuddenDynamicsType suddenDynamicsType);
  159. //! add dynamics mark (gradual changes) to end of score
  160. virtual bool addGradualDynamicsMark(GradualDynamicsType gradualDynamicsType);
  161. //! add note to end of score
  162. virtual bool addNote(size_t duration, const std::string& lyric, size_t pitch, bool accent, bool staccato, TieType tieType, SlurType slurType, SyllabicType syllabicType, bool breath = false);
  163. //! add rest to end of score
  164. virtual bool addRest(size_t duration);
  165. //! set score to given IScore object
  166. bool toScore(IScore&) const;
  167. //! set alpha for synthesis
  168. bool setAlpha(double alpha);
  169. //! set volume for synthesis
  170. bool setVolume(double volume);
  171. //! set interpolation weight for synthesis
  172. bool setInterpolationWeight(size_t index, double weight);
  173. //! synthesize
  174. bool synthesize(SynthCondition& consition);
  175. //! stop synthesizing
  176. bool stop();
  177. //! reset stop flag
  178. bool resetStopFlag();
  179. //! clear score
  180. bool clearScore();
  181. //! load score from MusicXML
  182. bool loadScoreFromMusicXML(const std::string& xml);
  183. //! save score to MusicXML
  184. bool saveScoreToMusicXML(const std::string& xml, ClefType clefType = CLEFTYPE_DEFAULT);
  185. private:
  186. //! copy constructor (donot use)
  187. Sinsy(const Sinsy&);
  188. //! assignment operator (donot use)
  189. Sinsy& operator=(const Sinsy&);
  190. //! implementation
  191. SinsyImpl* impl;
  192. };
  193. };
  194. #endif /* __cplusplus */
  195. #endif /* SINSY_H_ */