KlattGrid.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #ifndef _KlattGrid_h_
  2. #define _KlattGrid_h_
  3. /* KlattGrid.h
  4. *
  5. * Copyright (C) 2008-2017 David Weenink, 2015 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "Collection.h"
  21. #include "PointProcess.h"
  22. #include "Sound.h"
  23. #include "IntensityTier.h"
  24. #include "PitchTier.h"
  25. #include "FormantGrid.h"
  26. #include "KlattTable.h"
  27. Thing_declare (Interpreter);
  28. #include "KlattGrid_def.h"
  29. /******************** PhonationPoint & Tier ************************************/
  30. autoPhonationPoint PhonationPoint_create (double time, double period, double openPhase, double collisionPhase, double te,
  31. double power1, double power2, double pulseScale);
  32. autoPhonationTier PhonationTier_create (double tmin, double tmax);
  33. autoPointProcess PhonationTier_to_PointProcess_closures (PhonationTier me);
  34. /************************ PhonationGrid *********************************************/
  35. autoPhonationGrid PhonationGrid_create (double tmin, double tmax);
  36. autoPhonationGridPlayOptions PhonationGridPlayOptions_create ();
  37. void PhonationGrid_setNames (PhonationGrid me);
  38. autoSound PhonationGrid_to_Sound_aspiration (PhonationGrid me, double samplingFrequency);
  39. void PhonationGrid_draw (PhonationGrid me, Graphics g);
  40. double PhonationGrid_getMaximumPeriod (PhonationGrid me);
  41. autoPhonationTier PhonationGrid_to_PhonationTier (PhonationGrid me);
  42. /************************ VocalTractGrid *********************************************/
  43. autoVocalTractGrid VocalTractGrid_create (double tmin, double tmax, integer numberOfFormants,
  44. integer numberOfNasalFormants, integer numberOfNasalAntiFormants);
  45. autoVocalTractGridPlayOptions VocalTractGridPlayOptions_create ();
  46. void VocalTractGrid_setNames (VocalTractGrid me);
  47. void VocalTractGrid_draw (VocalTractGrid me, Graphics g, int filterModel);
  48. /************************ CouplingGrid *********************************************/
  49. autoCouplingGrid CouplingGrid_create (double tmin, double tmax, integer numberOfTrachealFormants, integer numberOfTrachealAntiFormants, integer numberOfDeltaFormants);
  50. autoCouplingGridPlayOptions CouplingGridPlayOptions_create ();
  51. void CouplingGrid_setNames (CouplingGrid me);
  52. double CouplingGrid_getDeltaFormantAtTime (CouplingGrid me, integer iformant, double t);
  53. double CouplingGrid_getDeltaBandwidthAtTime (CouplingGrid me, integer iformant, double t);
  54. /********************** FormantGrid & CouplingGrid *************************************/
  55. void FormantGrid_CouplingGrid_updateOpenPhases (FormantGrid me, CouplingGrid thee);
  56. /********************** Sound & FormantGrid (& IntensityTier) *************************************/
  57. void Sound_FormantGrid_filterWithOneFormant_inplace (Sound me, FormantGrid thee, integer iformant);
  58. void Sound_FormantGrid_filterWithOneAntiFormant_inplace (Sound me, FormantGrid thee, integer iformant);
  59. void Sound_FormantGrid_Intensities_filterWithOneFormant_inplace (Sound me, FormantGrid thee, OrderedOf<structIntensityTier>* amplitudes, integer iformant);
  60. autoSound Sound_FormantGrid_Intensities_filter (Sound me, FormantGrid thee, OrderedOf<structIntensityTier>* amplitudes, integer iformantb, integer iformante, int alternatingSign);
  61. /************************ FricationGrid *********************************************/
  62. autoFricationGrid FricationGrid_create (double tmin, double tmax, integer numberOfFormants);
  63. autoFricationGridPlayOptions FricationGridPlayOptions_create ();
  64. void FricationGrid_setNames (FricationGrid me);
  65. void FricationGrid_draw (FricationGrid me, Graphics g);
  66. autoSound FricationGrid_to_Sound (FricationGrid me, double samplingFrequency);
  67. autoSound Sound_FricationGrid_filter (Sound me, FricationGrid thee);
  68. /************************ Sound & VocalTractGrid & CouplingGrid *********************************************/
  69. autoSound Sound_VocalTractGrid_CouplingGrid_filter (Sound me, VocalTractGrid thee, CouplingGrid coupling);
  70. /************************ KlattGrid *********************************************/
  71. autoKlattGrid KlattGrid_create (double tmin, double tmax, integer numberOfFormants,
  72. integer numberOfNasalFormants, integer numberOfNasalAntiFormants,
  73. integer numberOfTrachealFormants, integer numberOfTrachealAntiFormants,
  74. integer numberOfFricationFormants, integer numberOfDeltaFormants);
  75. autoKlattGrid KlattGrid_createExample ();
  76. autoKlattGridPlayOptions KlattGridPlayOptions_create ();
  77. void KlattGrid_setNames (KlattGrid me);
  78. autoKlattGrid KlattTable_to_KlattGrid (KlattTable me, double frameDuration);
  79. void KlattGrid_draw (KlattGrid me, Graphics g, int filterModel);
  80. void klattGrid_drawPhonation (KlattGrid me, Graphics g);
  81. void KlattGrid_drawVocalTract (KlattGrid me, Graphics g, int filterModel, int withTrachea);
  82. #define KlattGrid_FILTER_CASCADE 0
  83. #define KlattGrid_FILTER_PARALLEL 1
  84. #define KlattGrid_ORAL_FORMANTS 1
  85. #define KlattGrid_NASAL_FORMANTS 2
  86. #define KlattGrid_FRICATION_FORMANTS 3
  87. #define KlattGrid_TRACHEAL_FORMANTS 4
  88. #define KlattGrid_NASAL_ANTIFORMANTS 5
  89. #define KlattGrid_TRACHEAL_ANTIFORMANTS 6
  90. #define KlattGrid_DELTA_FORMANTS 7
  91. // Add, Remove, Extract, Replace from PhonationGrid
  92. #define PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO(Name,tierType) \
  93. double KlattGrid_get##Name##AtTime (KlattGrid me, double t); \
  94. void KlattGrid_add##Name##Point (KlattGrid me, double t, double value); \
  95. void KlattGrid_remove##Name##Points (KlattGrid me, double t1, double t2); \
  96. auto##tierType KlattGrid_extract##Name##Tier (KlattGrid me); \
  97. void KlattGrid_replace##Name##Tier (KlattGrid me, tierType thee);
  98. // Generate 55 prototypes
  99. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (Pitch, PitchTier)
  100. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (Flutter, RealTier)
  101. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (DoublePulsing, RealTier)
  102. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (OpenPhase, RealTier)
  103. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (CollisionPhase, RealTier)
  104. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (SpectralTilt, IntensityTier)
  105. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (Power1, RealTier)
  106. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (Power2, RealTier)
  107. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (VoicingAmplitude, IntensityTier)
  108. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (AspirationAmplitude, IntensityTier)
  109. PhonationGrid_QUERY_ADD_REMOVE_EXTRACT_REPLACE_PROTO (BreathinessAmplitude, IntensityTier)
  110. #define KlattGrid_QUERY_ADD_REMOVE_PROTO(Name) \
  111. double KlattGrid_get##Name##AtTime (KlattGrid me, int formantType, integer iformant, double t); \
  112. void KlattGrid_add##Name##Point (KlattGrid me, int formantType, integer iformant, double t, double value); \
  113. void KlattGrid_remove##Name##Points (KlattGrid me, int formantType, integer iformant, double t1, double t2); \
  114. double KlattGrid_getDelta##Name##AtTime (KlattGrid me, integer iformant, double t); \
  115. void KlattGrid_addDelta##Name##Point (KlattGrid me, integer iformant, double t, double value); \
  116. void KlattGrid_removeDelta##Name##Points (KlattGrid me, integer iformant, double t1, double t2);
  117. // 12 prototypes
  118. KlattGrid_QUERY_ADD_REMOVE_PROTO(Formant)
  119. KlattGrid_QUERY_ADD_REMOVE_PROTO(Bandwidth)
  120. void KlattGrid_formula_frequencies (KlattGrid me, int formantType, conststring32 expression, Interpreter interpreter);
  121. void KlattGrid_formula_bandwidths (KlattGrid me, int formantType, conststring32 expression, Interpreter interpreter);
  122. void KlattGrid_formula_amplitudes (KlattGrid me, int formantType, conststring32 expression, Interpreter interpreter);
  123. autoFormantGrid KlattGrid_extractFormantGrid (KlattGrid me, int formantType);
  124. void KlattGrid_replaceFormantGrid (KlattGrid me, int formantType, FormantGrid thee);
  125. autoFormantGrid KlattGrid_extractDeltaFormantGrid (KlattGrid me);
  126. void KlattGrid_replaceDeltaFormantGrid (KlattGrid me, FormantGrid thee);
  127. autoFormantGrid KlattGrid_to_oralFormantGrid_openPhases (KlattGrid me, double fadeFraction);
  128. autoPointProcess KlattGrid_extractPointProcess_glottalClosures (KlattGrid me);
  129. double KlattGrid_getAmplitudeAtTime (KlattGrid me, int formantType, integer iformant, double t);
  130. void KlattGrid_addAmplitudePoint (KlattGrid me, int formantType, integer iformant, double t, double value);
  131. void KlattGrid_removeAmplitudePoints (KlattGrid me, int formantType, integer iformant, double t1, double t2);
  132. autoIntensityTier KlattGrid_extractAmplitudeTier (KlattGrid me, int formantType, integer iformant);
  133. void KlattGrid_replaceAmplitudeTier (KlattGrid me, int formantType, integer iformant, IntensityTier thee);
  134. double KlattGrid_getFricationAmplitudeAtTime (KlattGrid me, double t);
  135. void KlattGrid_addFricationAmplitudePoint (KlattGrid me, double t, double value);
  136. void KlattGrid_removeFricationAmplitudePoints (KlattGrid me, double t1, double t2);
  137. autoIntensityTier KlattGrid_extractFricationAmplitudeTier (KlattGrid me);
  138. void KlattGrid_replaceFricationAmplitudeTier (KlattGrid me, IntensityTier thee);
  139. double KlattGrid_getFricationBypassAtTime (KlattGrid me, double t);
  140. void KlattGrid_addFricationBypassPoint (KlattGrid me, double t, double value);
  141. void KlattGrid_removeFricationBypassPoints (KlattGrid me, double t1, double t2);
  142. autoIntensityTier KlattGrid_extractFricationBypassTier (KlattGrid me);
  143. void KlattGrid_replaceFricationBypassTier (KlattGrid me, IntensityTier thee);
  144. void KlattGrid_setGlottisCoupling (KlattGrid me);
  145. autoFormantGrid * KlattGrid_getAddressOfFormantGrid (KlattGrid me, int formantType);
  146. OrderedOf<structIntensityTier>* KlattGrid_getAddressOfAmplitudes (KlattGrid me, int formantType);
  147. /*
  148. One can add (or remove) formant frequency tiers, formant bandwidth tiers and formant amplitude tiers.
  149. The first two types are handled together, the third type is handled separately.
  150. */
  151. void KlattGrid_addFormantFrequencyAndBandwidthTiers (KlattGrid me, int formantType, integer position);
  152. void KlattGrid_removeFormantFrequencyAndBandwidthTiers (KlattGrid me, int formantType, integer position);
  153. void KlattGrid_addFormantAmplitudeTier (KlattGrid me, int formantType, integer position);
  154. void KlattGrid_removeFormantAmplitudeTier (KlattGrid me, int formantType, integer position);
  155. /*
  156. The following two functions are deprecated;
  157. they combine the actions of the above functions,
  158. i.e. they add (or remove) a formant frequency tier, a formant bandwidth tier,
  159. and a formant amplitude tier in one go.
  160. Use instead the above division of these actions into two steps.
  161. */
  162. void KlattGrid_addFormant (KlattGrid me, int formantType, integer position);
  163. void KlattGrid_removeFormant (KlattGrid me, int formantType, integer position);
  164. /***************** KlattGrid & Sound *************************************/
  165. // reset PlayOptions to defaults
  166. void KlattGrid_play (KlattGrid me);
  167. // use playOptions
  168. void KlattGrid_playSpecial (KlattGrid me);
  169. void KlattGrid_setDefaultPlayOptions (KlattGrid me);
  170. autoSound KlattGrid_to_Sound (KlattGrid me);
  171. autoSound KlattGrid_to_Sound_phonation (KlattGrid me);
  172. int KlattGrid_synthesize (KlattGrid me, double t1, double t2, double samplingFrequency, double maximumPeriod);
  173. /*
  174. glottal: phonation+aspiration, before entering the filter
  175. frication: noise before entering the parallel frication filter section.
  176. */
  177. autoSound Sound_KlattGrid_filterByVocalTract (Sound me, KlattGrid thee, int filterModel);
  178. autoSound Sound_KlattGrid_filter_frication (Sound me, KlattGrid thee);
  179. autoKlattGrid Sound_to_KlattGrid_simple (Sound me, double timeStep, integer maximumNumberOfFormants, double maximumFormantFrequency, double windowLength, double preEmphasisFrequency, double minimumPitch, double maximumPitch, double minimumPitchIntensity, int subtractMean);
  180. #endif /* _KlattGrid_h_ */