]> git.bts.cx Git - benzene.git/blob - third_party/soloud_speech/klatt.h
Fixed Aseprite rendering system
[benzene.git] / third_party / soloud_speech / klatt.h
1 #ifndef KLATT_H
2 #define KLATT_H
3
4 #include "resonator.h"
5
6 #define CASCADE_PARALLEL 1
7 #define ALL_PARALLEL 2
8 #define NPAR 40
9
10 class klatt_frame
11 {
12 public:
13 int mF0FundamentalFreq; // Voicing fund freq in Hz
14 int mVoicingAmpdb; // Amp of voicing in dB, 0 to 70
15 int mFormant1Freq; // First formant freq in Hz, 200 to 1300
16 int mFormant1Bandwidth; // First formant bw in Hz, 40 to 1000
17 int mFormant2Freq; // Second formant freq in Hz, 550 to 3000
18 int mFormant2Bandwidth; // Second formant bw in Hz, 40 to 1000
19 int mFormant3Freq; // Third formant freq in Hz, 1200 to 4999
20 int mFormant3Bandwidth; // Third formant bw in Hz, 40 to 1000
21 int mFormant4Freq; // Fourth formant freq in Hz, 1200 to 4999
22 int mFormant4Bandwidth; // Fourth formant bw in Hz, 40 to 1000
23 int mFormant5Freq; // Fifth formant freq in Hz, 1200 to 4999
24 int mFormant5Bandwidth; // Fifth formant bw in Hz, 40 to 1000
25 int mFormant6Freq; // Sixth formant freq in Hz, 1200 to 4999
26 int mFormant6Bandwidth; // Sixth formant bw in Hz, 40 to 2000
27 int mNasalZeroFreq; // Nasal zero freq in Hz, 248 to 528
28 int mNasalZeroBandwidth; // Nasal zero bw in Hz, 40 to 1000
29 int mNasalPoleFreq; // Nasal pole freq in Hz, 248 to 528
30 int mNasalPoleBandwidth; // Nasal pole bw in Hz, 40 to 1000
31 int mAspirationAmpdb; // Amp of aspiration in dB, 0 to 70
32 int mNoSamplesInOpenPeriod; // # of samples in open period, 10 to 65
33 int mVoicingBreathiness; // Breathiness in voicing, 0 to 80
34 int mVoicingSpectralTiltdb; // Voicing spectral tilt in dB, 0 to 24
35 int mFricationAmpdb; // Amp of frication in dB, 0 to 80
36 int mSkewnessOfAlternatePeriods; // Skewness of alternate periods, 0 to 40 in sample#/2
37 int mFormant1Ampdb; // Amp of par 1st formant in dB, 0 to 80
38 int mFormant1ParallelBandwidth; // Par. 1st formant bw in Hz, 40 to 1000
39 int mFormant2Ampdb; // Amp of F2 frication in dB, 0 to 80
40 int mFormant2ParallelBandwidth; // Par. 2nd formant bw in Hz, 40 to 1000
41 int mFormant3Ampdb; // Amp of F3 frication in dB, 0 to 80
42 int mFormant3ParallelBandwidth; // Par. 3rd formant bw in Hz, 40 to 1000
43 int mFormant4Ampdb; // Amp of F4 frication in dB, 0 to 80
44 int mFormant4ParallelBandwidth; // Par. 4th formant bw in Hz, 40 to 1000
45 int mFormant5Ampdb; // Amp of F5 frication in dB, 0 to 80
46 int mFormant5ParallelBandwidth; // Par. 5th formant bw in Hz, 40 to 1000
47 int mFormant6Ampdb; // Amp of F6 (same as r6pa), 0 to 80
48 int mFormant6ParallelBandwidth; // Par. 6th formant bw in Hz, 40 to 2000
49 int mParallelNasalPoleAmpdb; // Amp of par nasal pole in dB, 0 to 80
50 int mBypassFricationAmpdb; // Amp of bypass fric. in dB, 0 to 80
51 int mPalallelVoicingAmpdb; // Amp of voicing, par in dB, 0 to 70
52 int mOverallGaindb; // Overall gain, 60 dB is unity, 0 to 60
53 klatt_frame();
54 };
55
56 class darray;
57 class Element;
58
59 class Slope
60 {
61 public:
62 float mValue; /* boundary value */
63 int mTime; /* transition time */
64 Slope()
65 {
66 mValue = 0;
67 mTime = 0;
68 }
69 };
70
71
72 enum KLATT_WAVEFORM
73 {
74 KW_SAW,
75 KW_TRIANGLE,
76 KW_SIN,
77 KW_SQUARE,
78 KW_PULSE,
79 KW_NOISE,
80 KW_WARBLE
81 };
82
83 class klatt
84 {
85 // resonators
86 resonator mParallelFormant1, mParallelFormant2, mParallelFormant3,
87 mParallelFormant4, mParallelFormant5, mParallelFormant6,
88 mParallelResoNasalPole, mNasalPole, mNasalZero,
89 mCritDampedGlotLowPassFilter, mDownSampLowPassFilter, mOutputLowPassFilter;
90 public:
91 int mBaseF0;
92 float mBaseSpeed;
93 float mBaseDeclination;
94 int mBaseWaveform;
95
96 int mF0Flutter;
97 int mSampleRate;
98 int mNspFr;
99 int mF0FundamentalFreq; // Voicing fund freq in Hz
100 int mVoicingAmpdb; // Amp of voicing in dB, 0 to 70
101 int mSkewnessOfAlternatePeriods; // Skewness of alternate periods,0 to 40
102 int mTimeCount; // used for f0 flutter
103 int mNPer; // Current loc in voicing period 40000 samp/s
104 int mT0; // Fundamental period in output samples times 4
105 int mNOpen; // Number of samples in open phase of period
106 int mNMod; // Position in period to begin noise amp. modul
107
108 // Various amplitude variables used in main loop
109
110 float mAmpVoice; // mVoicingAmpdb converted to linear gain
111 float mAmpBypas; // mBypassFricationAmpdb converted to linear gain
112 float mAmpAspir; // AP converted to linear gain
113 float mAmpFrica; // mFricationAmpdb converted to linear gain
114 float mAmpBreth; // ATURB converted to linear gain
115
116 // State variables of sound sources
117
118 int mSkew; // Alternating jitter, in half-period units
119 float mVLast; // Previous output of voice
120 float mNLast; // Previous output of random number generator
121 float mGlotLast; // Previous value of glotout
122 float mDecay; // mVoicingSpectralTiltdb converted to exponential time const
123 float mOneMd; // in voicing one-pole ELM_FEATURE_LOW-pass filter
124
125 unsigned int mSeed; // random seed
126
127
128
129 float natural_source(int aNper);
130
131 void frame_init();
132 void flutter();
133 void pitch_synch_par_reset(int ns);
134 void parwave(short int *jwave);
135 void init(int aBaseFrequency = 1330, float aBaseSpeed = 10.0f, float aBaseDeclination = 0.5f, int aBaseWaveform = KW_SAW);
136 static int phone_to_elm(char *aPhoneme, int aCount, darray *aElement);
137
138 int mElementCount;
139 unsigned char *mElement;
140 int mElementIndex;
141 klatt_frame mFrame;
142 Element * mLastElement;
143 int mTStress;
144 int mNTStress;
145 Slope mStressS;
146 Slope mStressE;
147 float mTop;
148 void initsynth(int aElementCount,unsigned char *aElement);
149 int synth(int aSampleCount, short *aSamplePointer);
150 klatt();
151 };
152
153 #endif