Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
7.6 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include "tier0/dbg.h"
  11. struct PhonemeMap_t
  12. {
  13. const char *string;
  14. int code;
  15. unsigned char byteCode; // needs to be unique
  16. float weight;
  17. bool isStandard;
  18. const char *desc;
  19. };
  20. static PhonemeMap_t g_Phonemes[] =
  21. {
  22. { "b", 'b', 0x01, 0.8f, true, "Big : voiced alveolar stop" },
  23. { "m", 'm', 0x02, 1.0f, true, "Mat : voiced bilabial nasal" },
  24. { "p", 'p', 0x03, 0.8f, true, "Put; voiceless alveolar stop" },
  25. { "w", 'w', 0x04, 1.0f, true, "With : voiced labial-velar approximant" },
  26. { "f", 'f', 0x05, 0.8f, true, "Fork : voiceless labiodental fricative" },
  27. { "v", 'v', 0x06, 0.8f, true, "Val : voiced labialdental fricative" },
  28. { "r", 0x0279, 0x07, 1.0f, true, "Red : voiced alveolar approximant" },
  29. { "r2", 'r', 0x08, 1.0f, true, "Red : voiced alveolar trill" },
  30. { "r3", 0x027b, 0x09, 1.0f, true, "Red : voiced retroflex approximant" },
  31. { "er", 0x025a, 0x0A, 1.2f, true, "URn : rhotacized schwa" },
  32. { "er2", 0x025d, 0x0B, 1.2f, true, "URn : rhotacized lower-mid central vowel" },
  33. { "dh", 0x00f0, 0x0C, 1.0f, true, "THen : voiced dental fricative" },
  34. { "th", 0x03b8, 0x0D, 1.0f, true, "THin : voiceless dental fricative" },
  35. { "sh", 0x0283, 0x0E, 1.0f, true, "SHe : voiceless postalveolar fricative" },
  36. { "jh", 0x02a4, 0x0F, 1.0f, true, "Joy : voiced postalveolar afficate" },
  37. { "ch", 0x02a7, 0x10, 1.0f, true, "CHin : voiceless postalveolar affricate" },
  38. { "s", 's', 0x11, 0.8f, true, "Sit : voiceless alveolar fricative" },
  39. { "z", 'z', 0x12, 0.8f, true, "Zap : voiced alveolar fricative" },
  40. { "d", 'd', 0x13, 0.8f, true, "Dig : voiced bilabial stop" },
  41. { "d2", 0x027e, 0x14, 0.8f, true, "Dig : voiced alveolar flap or tap" },
  42. { "l", 'l', 0x15, 0.8f, true, "Lid : voiced alveolar lateral approximant" },
  43. { "l2", 0x026b, 0x16, 0.8f, true, "Lid : velarized voiced alveolar lateral approximant" },
  44. { "n", 'n', 0x17, 0.8f, true, "No : voiced alveolar nasal" },
  45. { "t", 't', 0x18, 0.8f, true, "Talk : voiceless bilabial stop" },
  46. { "ow", 'o', 0x19, 1.2f, true, "gO : upper-mid back rounded vowel" },
  47. { "uw", 'u', 0x1A, 1.2f, true, "tOO : high back rounded vowel" },
  48. { "ey", 'e', 0x1B, 1.0f, true, "Ate : upper-mid front unrounded vowel" },
  49. { "ae", 0x00e6, 0x1C, 1.0f, true, "cAt : semi-low front unrounded vowel" },
  50. { "aa", 0x0251, 0x1D, 1.0f, true, "fAther : low back unrounded vowel" },
  51. { "aa2", 'a', 0x1E, 1.0f, true, "fAther : low front unrounded vowel" },
  52. { "iy", 'i', 0x1F, 1.0f, true, "fEEl : high front unrounded vowel" },
  53. { "y", 'j', 0x20, 0.7f, true, "Yacht : voiced palatal approximant" },
  54. { "ah", 0x028c, 0x21, 1.0f, true, "cUt : lower-mid back unrounded vowel" },
  55. { "ao", 0x0254, 0x22, 1.2f, true, "dOg : lower-mid back rounded vowel" },
  56. { "ax", 0x0259, 0x23, 1.0f, true, "Ago : mid-central unrounded vowel" },
  57. { "ax2", 0x025c, 0x24, 1.0f, true, "Ago : lower-mid central unrounded vowel" },
  58. { "eh", 0x025b, 0x25, 1.0f, true, "pEt : lower-mid front unrounded vowel"},
  59. { "ih", 0x026a, 0x26, 1.0f, true, "fIll : semi-high front unrounded vowel" },
  60. { "ih2", 0x0268, 0x27, 1.0f, true, "fIll : high central unrounded vowel" },
  61. { "uh", 0x028a, 0x28, 1.0f, true, "bOOk : semi-high back rounded vowel" },
  62. { "g", 'g', 0x29, 0.8f, true, "taG : voiced velar stop" },
  63. { "g2", 0x0261, 0x2A, 1.0f, true, "taG : voiced velar stop" },
  64. { "hh", 'h', 0x2B, 0.8f, true, "Help : voiceless glottal fricative" },
  65. { "hh2", 0x0266, 0x2C, 0.8f, true, "Help : breathy-voiced glottal fricative" },
  66. { "c", 'k', 0x2D, 0.6f, true, "Cut : voiceless velar stop" },
  67. { "nx", 0x014b, 0x2E, 1.0f, true, "siNG : voiced velar nasal" },
  68. { "zh", 0x0292, 0x2F, 1.0f, true, "aZure : voiced postalveolar fricative" },
  69. // Added
  70. { "h", 'h', 0x30, 0.8f, false, "Help : voiceless glottal fricative" },
  71. { "k", 'k', 0x31, 0.6f, false, "Cut : voiceless velar stop" },
  72. { "ay", 0x0251, 0x32, 1.0f, false, "fAther : low back unrounded vowel" }, // or possibly +0x026a (ih)
  73. { "ng", 0x014b, 0x33, 1.0f, false, "siNG : voiced velar nasal" }, // nx
  74. { "aw", 0x0251, 0x34, 1.2f, false, "fAther : low back unrounded vowel" }, // // vOWel, // aa + uh???
  75. { "oy", 'u', 0x35, 1.2f, false, "tOO : high back rounded vowel" },
  76. // Silence
  77. { "<sil>", '_', 0x00, 1.0f, true, "silence" },
  78. };
  79. //-----------------------------------------------------------------------------
  80. // Purpose:
  81. // Input : code -
  82. // Output : const char
  83. //-----------------------------------------------------------------------------
  84. const char *ConvertPhoneme( int code )
  85. {
  86. for ( int i = 0; i < ARRAYSIZE( g_Phonemes ); ++i )
  87. {
  88. PhonemeMap_t *test = &g_Phonemes[ i ];
  89. if ( test->code == code )
  90. return test->string;
  91. }
  92. Warning( "Unrecognized phoneme code %i\n", code );
  93. return "<sil>";
  94. }
  95. //-----------------------------------------------------------------------------
  96. // Purpose:
  97. // Input : *text -
  98. // Output : int
  99. //-----------------------------------------------------------------------------
  100. int TextToPhoneme( const char *text )
  101. {
  102. for ( int i = 0; i < ARRAYSIZE( g_Phonemes ); ++i )
  103. {
  104. PhonemeMap_t *test = &g_Phonemes[ i ];
  105. if ( !stricmp( test->string, text ) )
  106. return test->code;
  107. }
  108. Warning( "Unrecognized phoneme %s\n", text );
  109. return '_';
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose:
  113. // Input : code -
  114. // Output : float
  115. //-----------------------------------------------------------------------------
  116. float WeightForPhonemeCode( int code )
  117. {
  118. for ( int i = 0; i < ARRAYSIZE( g_Phonemes ); ++i )
  119. {
  120. PhonemeMap_t *test = &g_Phonemes[ i ];
  121. if ( test->code == code )
  122. return test->weight;
  123. }
  124. Warning( "Unrecognized phoneme code %i\n", code );
  125. return 1.0f;
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose:
  129. // Input : *text -
  130. // Output : float
  131. //-----------------------------------------------------------------------------
  132. float WeightForPhoneme( char *text )
  133. {
  134. for ( int i = 0; i < ARRAYSIZE( g_Phonemes ); ++i )
  135. {
  136. PhonemeMap_t *test = &g_Phonemes[ i ];
  137. if ( !stricmp( test->string, text ) )
  138. return test->weight;
  139. }
  140. Warning( "WeightForPhoneme:: Unrecognized phoneme %s\n", text );
  141. return 1.0f;
  142. }
  143. int NumPhonemes()
  144. {
  145. return ARRAYSIZE( g_Phonemes );
  146. }
  147. const char *NameForPhonemeByIndex( int index )
  148. {
  149. Assert( index >= 0 && index < NumPhonemes() );
  150. return g_Phonemes[ index ].string;
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Purpose:
  154. // Input : *text -
  155. // Output : int
  156. //-----------------------------------------------------------------------------
  157. int TextToPhonemeIndex( const char *text )
  158. {
  159. for ( int i = 0; i < ARRAYSIZE( g_Phonemes ); ++i )
  160. {
  161. PhonemeMap_t *test = &g_Phonemes[ i ];
  162. if ( !stricmp( test->string, text ) )
  163. return i;
  164. }
  165. return -1;
  166. }
  167. int CodeForPhonemeByIndex( int index )
  168. {
  169. if ( index < 0 || index >= NumPhonemes() )
  170. return '_';
  171. return g_Phonemes[ index ].code;
  172. }
  173. bool IsStandardPhoneme( int index )
  174. {
  175. if ( index < 0 || index >= NumPhonemes() )
  176. return false;
  177. return g_Phonemes[ index ].isStandard;
  178. }
  179. const char *DescForPhonemeByIndex( int index )
  180. {
  181. if ( index < 0 || index >= NumPhonemes() )
  182. return NULL;
  183. return g_Phonemes[ index ].desc;
  184. }
  185. unsigned char CodeToByteCode( int code )
  186. {
  187. for ( int i = 0; i < ARRAYSIZE( g_Phonemes ); ++i )
  188. {
  189. if ( g_Phonemes[ i ].code == code )
  190. {
  191. return g_Phonemes[ i ].byteCode;
  192. }
  193. }
  194. return 0x00;
  195. }
  196. int ByteCodeToCode( unsigned char byteCode )
  197. {
  198. for ( int i = 0; i < ARRAYSIZE( g_Phonemes ); ++i )
  199. {
  200. if ( g_Phonemes[ i ].byteCode == byteCode )
  201. {
  202. return g_Phonemes[ i ].code;
  203. }
  204. }
  205. return '_';
  206. }