| 1 |
/* |
| 2 |
* Copyright (C) 2008 by Jonathan Duddington |
| 3 |
* email: [email protected] |
| 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 |
|
| 24 |
#ifndef ESPEAK_NG_KLATT_H |
| 25 |
#define ESPEAK_NG_KLATT_H |
| 26 |
|
| 27 |
#include "voice.h" // for voice_t |
| 28 |
#include "synthesize.h" // for frame_t, WGEN_DATA |
| 29 |
|
| 30 |
#ifdef __cplusplus |
| 31 |
extern "C" |
| 32 |
{ |
| 33 |
#endif |
| 34 |
|
| 35 |
#define CASCADE_PARALLEL 1 /* Type of synthesis model */ |
| 36 |
#define ALL_PARALLEL 2 |
| 37 |
|
| 38 |
#define IMPULSIVE 1 /* Type of voicing source */ |
| 39 |
#define NATURAL 2 |
| 40 |
#define SAMPLED 3 |
| 41 |
#define SAMPLED2 4 |
| 42 |
|
| 43 |
/* typedef's that need to be exported */ |
| 44 |
|
| 45 |
typedef long flag; |
| 46 |
|
| 47 |
/* Resonator Structure */ |
| 48 |
|
| 49 |
typedef struct { |
| 50 |
double a; |
| 51 |
double b; |
| 52 |
double c; |
| 53 |
double p1; |
| 54 |
double p2; |
| 55 |
double a_inc; |
| 56 |
double b_inc; |
| 57 |
double c_inc; |
| 58 |
} resonator_t, *resonator_ptr; |
| 59 |
|
| 60 |
/* Structure for Klatt Globals */ |
| 61 |
|
| 62 |
typedef struct { |
| 63 |
flag synthesis_model; /* cascade-parallel or all-parallel */ |
| 64 |
flag outsl; /* Output waveform selector */ |
| 65 |
long samrate; /* Number of output samples per second */ |
| 66 |
long FLPhz; /* Frequeny of glottal downsample low-pass filter */ |
| 67 |
long BLPhz; /* Bandwidth of glottal downsample low-pass filter */ |
| 68 |
flag glsource; /* Type of glottal source */ |
| 69 |
int f0_flutter; /* Percentage of f0 flutter 0-100 */ |
| 70 |
long nspfr; /* number of samples per frame */ |
| 71 |
long nper; /* Counter for number of samples in a pitch period */ |
| 72 |
long ns; |
| 73 |
long T0; /* Fundamental period in output samples times 4 */ |
| 74 |
long nopen; /* Number of samples in open phase of period */ |
| 75 |
long nmod; /* Position in period to begin noise amp. modul */ |
| 76 |
long nrand; /* Variable used by random number generator */ |
| 77 |
double pulse_shape_a; /* Makes waveshape of glottal pulse when open */ |
| 78 |
double pulse_shape_b; /* Makes waveshape of glottal pulse when open */ |
| 79 |
double minus_pi_t; |
| 80 |
double two_pi_t; |
| 81 |
double onemd; |
| 82 |
double decay; |
| 83 |
double amp_bypas; /* AB converted to linear gain */ |
| 84 |
double amp_voice; /* AVdb converted to linear gain */ |
| 85 |
double par_amp_voice; /* AVpdb converted to linear gain */ |
| 86 |
double amp_aspir; /* AP converted to linear gain */ |
| 87 |
double amp_frica; /* AF converted to linear gain */ |
| 88 |
double amp_breth; /* ATURB converted to linear gain */ |
| 89 |
double amp_gain0; /* G0 converted to linear gain */ |
| 90 |
int num_samples; /* number of glottal samples */ |
| 91 |
double sample_factor; /* multiplication factor for glottal samples */ |
| 92 |
const short *natural_samples; /* pointer to an array of glottal samples */ |
| 93 |
long original_f0; /* original value of f0 not modified by flutter */ |
| 94 |
|
| 95 |
int fadein; |
| 96 |
int fadeout; // set to 64 to cause fadeout over 64 samples |
| 97 |
int scale_wav; // depends on the voicing source |
| 98 |
|
| 99 |
#define N_RSN 20 |
| 100 |
#define Rnz 0 // nasal zero, anti-resonator |
| 101 |
#define R1c 1 |
| 102 |
#define R2c 2 |
| 103 |
#define R3c 3 |
| 104 |
#define R4c 4 |
| 105 |
#define R5c 5 |
| 106 |
#define R6c 6 |
| 107 |
#define R7c 7 |
| 108 |
#define R8c 8 |
| 109 |
#define Rnpc 9 // nasal pole |
| 110 |
|
| 111 |
#define Rparallel 10 |
| 112 |
#define Rnpp 10 |
| 113 |
#define R1p 11 |
| 114 |
#define R2p 12 |
| 115 |
#define R6p 16 |
| 116 |
|
| 117 |
#define RGL 17 |
| 118 |
#define RLP 18 |
| 119 |
#define Rout 19 |
| 120 |
|
| 121 |
resonator_t rsn[N_RSN]; // internal storage for resonators |
| 122 |
resonator_t rsn_next[N_RSN]; |
| 123 |
|
| 124 |
} klatt_global_t, *klatt_global_ptr; |
| 125 |
|
| 126 |
/* Structure for Klatt Parameters */ |
| 127 |
|
| 128 |
#define F_NZ 0 // nasal zero formant |
| 129 |
#define F1 1 |
| 130 |
#define F2 2 |
| 131 |
#define F3 3 |
| 132 |
#define F4 4 |
| 133 |
#define F5 5 |
| 134 |
#define F6 6 |
| 135 |
#define F_NP 9 // nasal pole formant |
| 136 |
|
| 137 |
|
| 138 |
typedef struct { |
| 139 |
int F0hz10; /* Voicing fund freq in Hz */ |
| 140 |
int AVdb; /* Amp of voicing in dB, 0 to 70 */ |
| 141 |
int Fhz[10]; // formant Hz, F_NZ to F6 to F_NP |
| 142 |
int Bhz[10]; |
| 143 |
int Ap[10]; /* Amp of parallel formants in dB, 0 to 80 */ |
| 144 |
int Bphz[10]; /* Parallel formants bw in Hz, 40 to 1000 */ |
| 145 |
|
| 146 |
int ASP; /* Amp of aspiration in dB, 0 to 70 */ |
| 147 |
int Kopen; /* # of samples in open period, 10 to 65 */ |
| 148 |
int Aturb; /* Breathiness in voicing, 0 to 80 */ |
| 149 |
int TLTdb; /* Voicing spectral tilt in dB, 0 to 24 */ |
| 150 |
int AF; /* Amp of frication in dB, 0 to 80 */ |
| 151 |
int Kskew; /* Skewness of alternate periods, 0 to 40 in sample#/2 */ |
| 152 |
|
| 153 |
int AB; /* Amp of bypass fric. in dB, 0 to 80 */ |
| 154 |
int AVpdb; /* Amp of voicing, par in dB, 0 to 70 */ |
| 155 |
int Gain0; /* Overall gain, 60 dB is unity, 0 to 60 */ |
| 156 |
|
| 157 |
int AVdb_tmp; // copy of AVdb, which is changed within parwave() |
| 158 |
int Fhz_next[10]; // Fhz for the next chunk, so we can do interpolation of resonator (a,b,c) parameters |
| 159 |
int Bhz_next[10]; |
| 160 |
} klatt_frame_t, *klatt_frame_ptr; |
| 161 |
|
| 162 |
|
| 163 |
typedef struct { |
| 164 |
int freq; // Hz |
| 165 |
int bw; // klatt bandwidth |
| 166 |
int ap; // parallel amplitude |
| 167 |
int bp; // parallel bandwidth |
| 168 |
double freq1; // floating point versions of the above |
| 169 |
double bw1; |
| 170 |
double ap1; |
| 171 |
double bp1; |
| 172 |
double freq_inc; // increment by this every 64 samples |
| 173 |
double bw_inc; |
| 174 |
double ap_inc; |
| 175 |
double bp_inc; |
| 176 |
} klatt_peaks_t; |
| 177 |
|
| 178 |
void KlattInit(void); |
| 179 |
void KlattFini(void); |
| 180 |
void KlattReset(int control); |
| 181 |
int Wavegen_Klatt(int length, int resume, frame_t *fr1, frame_t *fr2, WGEN_DATA *wdata, voice_t *wvoice); |
| 182 |
|
| 183 |
#ifdef __cplusplus |
| 184 |
} |
| 185 |
#endif |
| 186 |
|
| 187 |
#endif |