klatt.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (C) 2008 by Jonathan Duddington
  3. * email: jonsd@users.sourceforge.net
  4. * Copyright (C) 2015-2017 Reece H. Dunn
  5. *
  6. * Based on a re-implementation by:
  7. * (c) 1993,94 Jon Iles and Nick Ing-Simmons
  8. * of the Klatt cascade-parallel formant synthesizer
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, see: <http://www.gnu.org/licenses/>.
  22. */
  23. #include "synthesize.h"
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. #define CASCADE_PARALLEL 1 /* Type of synthesis model */
  29. #define ALL_PARALLEL 2
  30. #define IMPULSIVE 1 /* Type of voicing source */
  31. #define NATURAL 2
  32. #define SAMPLED 3
  33. #define SAMPLED2 4
  34. /* typedef's that need to be exported */
  35. typedef long flag;
  36. /* Resonator Structure */
  37. typedef struct {
  38. double a;
  39. double b;
  40. double c;
  41. double p1;
  42. double p2;
  43. double a_inc;
  44. double b_inc;
  45. double c_inc;
  46. } resonator_t, *resonator_ptr;
  47. /* Structure for Klatt Globals */
  48. typedef struct {
  49. flag synthesis_model; /* cascade-parallel or all-parallel */
  50. flag outsl; /* Output waveform selector */
  51. long samrate; /* Number of output samples per second */
  52. long FLPhz; /* Frequeny of glottal downsample low-pass filter */
  53. long BLPhz; /* Bandwidth of glottal downsample low-pass filter */
  54. flag glsource; /* Type of glottal source */
  55. int f0_flutter; /* Percentage of f0 flutter 0-100 */
  56. long nspfr; /* number of samples per frame */
  57. long nper; /* Counter for number of samples in a pitch period */
  58. long ns;
  59. long T0; /* Fundamental period in output samples times 4 */
  60. long nopen; /* Number of samples in open phase of period */
  61. long nmod; /* Position in period to begin noise amp. modul */
  62. long nrand; /* Varible used by random number generator */
  63. double pulse_shape_a; /* Makes waveshape of glottal pulse when open */
  64. double pulse_shape_b; /* Makes waveshape of glottal pulse when open */
  65. double minus_pi_t;
  66. double two_pi_t;
  67. double onemd;
  68. double decay;
  69. double amp_bypas; /* AB converted to linear gain */
  70. double amp_voice; /* AVdb converted to linear gain */
  71. double par_amp_voice; /* AVpdb converted to linear gain */
  72. double amp_aspir; /* AP converted to linear gain */
  73. double amp_frica; /* AF converted to linear gain */
  74. double amp_breth; /* ATURB converted to linear gain */
  75. double amp_gain0; /* G0 converted to linear gain */
  76. int num_samples; /* number of glottal samples */
  77. double sample_factor; /* multiplication factor for glottal samples */
  78. short *natural_samples; /* pointer to an array of glottal samples */
  79. long original_f0; /* original value of f0 not modified by flutter */
  80. int fadeout; // set to 64 to cause fadeout over 64 samples
  81. int scale_wav; // depends on the voicing source
  82. #define N_RSN 20
  83. #define Rnz 0 // nasal zero, anti-resonator
  84. #define R1c 1
  85. #define R2c 2
  86. #define R3c 3
  87. #define R4c 4
  88. #define R5c 5
  89. #define R6c 6
  90. #define R7c 7
  91. #define R8c 8
  92. #define Rnpc 9 // nasal pole
  93. #define Rparallel 10
  94. #define Rnpp 10
  95. #define R1p 11
  96. #define R2p 12
  97. #define R3p 13
  98. #define R4p 14
  99. #define R5p 15
  100. #define R6p 16
  101. #define RGL 17
  102. #define RLP 18
  103. #define Rout 19
  104. resonator_t rsn[N_RSN]; // internal storage for resonators
  105. resonator_t rsn_next[N_RSN];
  106. } klatt_global_t, *klatt_global_ptr;
  107. /* Structure for Klatt Parameters */
  108. #define F_NZ 0 // nasal zero formant
  109. #define F1 1
  110. #define F2 2
  111. #define F3 3
  112. #define F4 4
  113. #define F5 5
  114. #define F6 6
  115. #define F_NP 9 // nasal pole formant
  116. typedef struct {
  117. int F0hz10; /* Voicing fund freq in Hz */
  118. int AVdb; /* Amp of voicing in dB, 0 to 70 */
  119. int Fhz[10]; // formant Hz, F_NZ to F6 to F_NP
  120. int Bhz[10];
  121. int Ap[10]; /* Amp of parallel formants in dB, 0 to 80 */
  122. int Bphz[10]; /* Parallel formants bw in Hz, 40 to 1000 */
  123. int ASP; /* Amp of aspiration in dB, 0 to 70 */
  124. int Kopen; /* # of samples in open period, 10 to 65 */
  125. int Aturb; /* Breathiness in voicing, 0 to 80 */
  126. int TLTdb; /* Voicing spectral tilt in dB, 0 to 24 */
  127. int AF; /* Amp of frication in dB, 0 to 80 */
  128. int Kskew; /* Skewness of alternate periods, 0 to 40 in sample#/2 */
  129. int AB; /* Amp of bypass fric. in dB, 0 to 80 */
  130. int AVpdb; /* Amp of voicing, par in dB, 0 to 70 */
  131. int Gain0; /* Overall gain, 60 dB is unity, 0 to 60 */
  132. int AVdb_tmp; // copy of AVdb, which is changed within parwave()
  133. int Fhz_next[10]; // Fhz for the next chunk, so we can do interpolation of resonator (a,b,c) parameters
  134. int Bhz_next[10];
  135. } klatt_frame_t, *klatt_frame_ptr;
  136. typedef struct {
  137. int freq; // Hz
  138. int bw; // klatt bandwidth
  139. int ap; // parallel amplitude
  140. int bp; // parallel bandwidth
  141. DOUBLEX freq1; // floating point versions of the above
  142. DOUBLEX bw1;
  143. DOUBLEX ap1;
  144. DOUBLEX bp1;
  145. DOUBLEX freq_inc; // increment by this every 64 samples
  146. DOUBLEX bw_inc;
  147. DOUBLEX ap_inc;
  148. DOUBLEX bp_inc;
  149. } klatt_peaks_t;
  150. #ifdef __cplusplus
  151. }
  152. #endif