~ubuntu-branches/ubuntu/breezy/muse/breezy

« back to all changes in this revision

Viewing changes to synti/stklib/VoicForm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2004-02-07 15:18:22 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040207151822-es27xxkzbcxkebjm
Tags: 0.6.3-1
* New upstream version.
* Added patches:
  + [10_alsa_init_fix] New, from upstream CVS.
    Initialize direction variable when setting Alsa parameters.
  + [10_canvas_translation_fix] New, from upstream CVS.
    Do not translate tooltips twice in canvas popup.
  + [10_checkbox_fix] New, from upstream CVS.
    Use proper set/test methods on metronome checkboxes.
  + [10_html_doc_cleanup] New.
    Fix links and HTML errors in documentation.
  + [20_allow_system_timer] New.
    The new upstream version fails by default if the real-time clock
    could not be accessed (usually the case when not running suid-root).
    This patch reverts the old behaviour of falling back to the more
    inaccurate system timer.
* Updated patches:
  + [11_PIC_fixes_fixup] Rediffed.
* Removed patches:
  + [20_no_atomic_asm] Merged upstream.
* debian/compat: Splice out debhelper compatibility level from rules file.
* debian/control: Build-depend on latest jack release by default.
  Closes: #228788
* debian/control: Bump standards version.
* debian/control: Use auto-generated debconf dependency via misc:Depends.
* debian/control: Minor tweaks to the long description.
* debian/control: Tighten fluidsynth build dependency to sane version.
* debian/muse.doc-base: New. Register HTML documentation with doc-base.
* debian/templates: Tiny rewording, and typo fix.
* debian/templates, debian/po/*: Switch to po-debconf for translations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************/
2
 
/*  4 Formant Synthesis Instrument         */
3
 
/*  by Perry R. Cook, 1995-96              */ 
4
 
/*  This instrument contains an excitation */
5
 
/*  singing wavetable (looping wave with   */
6
 
/*  random and periodic vibrato, smoothing */
7
 
/*  on frequency, etc.), excitation noise, */
8
 
/*  and four sweepable complex resonances. */
9
 
/*                                         */
10
 
/*  Measured Formant data (from me) is     */
11
 
/*  included, and enough data is there to  */
12
 
/*  support either parallel or cascade     */
13
 
/*  synthesis.  In the floating point case */
14
 
/*  cascade synthesis is the most natural  */
15
 
/*  so that's what you'll find here.       */
16
 
/*                                         */
17
 
/*******************************************/
18
 
 
19
 
#include "VoicForm.h"
20
 
#include "SKINI11.msg"
21
 
 
22
 
VoicForm :: VoicForm() : Instrmnt()
23
 
{
24
 
  // Concatenate the STK RAWWAVE_PATH to the rawwave file
25
 
  char file[128];
26
 
  strcpy(file, RAWWAVE_PATH);
27
 
        voiced = new SingWave(strcat(file,"rawwaves/impuls20.raw"));
28
 
        voiced->normalize();
29
 
        voiced->setGainRate((MY_FLOAT) 0.001);
30
 
        voiced->setGainTarget((MY_FLOAT) 0.0);
31
 
 
32
 
        noise = new Noise;
33
 
 
34
 
        filters[0] = new FormSwep;
35
 
        filters[1] = new FormSwep;
36
 
        filters[2] = new FormSwep;
37
 
        filters[3] = new FormSwep;
38
 
        filters[0]->setSweepRate((MY_FLOAT) 0.001);
39
 
        filters[1]->setSweepRate((MY_FLOAT) 0.001);
40
 
        filters[2]->setSweepRate((MY_FLOAT) 0.001);
41
 
        filters[3]->setSweepRate((MY_FLOAT) 0.001);
42
 
    
43
 
        onezero = new OneZero;
44
 
        onezero->setCoeff((MY_FLOAT) -0.9);
45
 
        onepole = new OnePole;
46
 
        onepole->setPole((MY_FLOAT) 0.9);
47
 
    
48
 
        noiseEnv = new Envelope;
49
 
        noiseEnv->setRate((MY_FLOAT) 0.001);
50
 
        noiseEnv->setTarget((MY_FLOAT) 0.0);
51
 
    
52
 
        this->setPhoneme("eee");
53
 
        this->clear();
54
 
}  
55
 
 
56
 
VoicForm :: ~VoicForm()
57
 
{
58
 
        delete voiced;
59
 
        delete noise;
60
 
        delete filters[0];
61
 
        delete filters[1];
62
 
        delete filters[2];
63
 
        delete filters[3];
64
 
        delete onezero;
65
 
        delete onepole;
66
 
        delete noiseEnv;
67
 
}
68
 
 
69
 
void VoicForm :: clear()
70
 
{
71
 
        onezero->clear();
72
 
        onepole->clear();
73
 
        filters[0]->clear();
74
 
        filters[1]->clear();
75
 
        filters[2]->clear();
76
 
        filters[3]->clear();
77
 
}
78
 
 
79
 
void VoicForm :: setFreq(MY_FLOAT frequency)
80
 
{    
81
 
        MY_FLOAT temp;
82
 
        if ((frequency * 22) > SRATE)   {
83
 
           printf("This note is too high!!\n");
84
 
           frequency = SRATE / 22;
85
 
        }
86
 
        lastFreq = frequency;
87
 
        temp = fabs(1500 - frequency) + 200;
88
 
        lastGain = 10000.0 / temp / temp;
89
 
        voiced->setFreq(frequency);
90
 
}
91
 
 
92
 
void VoicForm :: setFormantAll(int whichOne, MY_FLOAT freq,MY_FLOAT reson,MY_FLOAT gain)
93
 
{
94
 
        filters[whichOne]->setTargets(freq,reson,gain);
95
 
}
96
 
 
97
 
#include "phontabl.h"
98
 
 
99
 
int VoicForm :: setPhoneme(char *phoneme)
100
 
{
101
 
        int i=0,found=0;
102
 
 
103
 
        while(i<32 && !found)      {
104
 
                if (!strcmp(phonemes[i],phoneme))      {
105
 
                        found = 1;
106
 
                        this->setFormantAll(0,(MY_FLOAT) phonParams[i][0][0],(MY_FLOAT) phonParams[i][0][1],(MY_FLOAT) pow(10.0,phonParams[i][0][2] / 20.0));
107
 
                        this->setFormantAll(1,(MY_FLOAT) phonParams[i][1][0],(MY_FLOAT) phonParams[i][1][1],(MY_FLOAT) 1.0);
108
 
                        this->setFormantAll(2,(MY_FLOAT) phonParams[i][2][0],(MY_FLOAT) phonParams[i][2][1],(MY_FLOAT) 1.0);
109
 
                        this->setFormantAll(3,(MY_FLOAT) phonParams[i][3][0],(MY_FLOAT) phonParams[i][3][1],(MY_FLOAT) 1.0);
110
 
                        this->setVoicedUnVoiced((MY_FLOAT) phonGains[i][0],(MY_FLOAT) phonGains[i][1]);
111
 
                        printf("Found Formant: %s (number %i)\n",phoneme,i);
112
 
                }
113
 
                i++;
114
 
        }
115
 
        if (!found) printf("Phoneme %s not found\n",phoneme);
116
 
        return found;
117
 
}
118
 
 
119
 
void VoicForm :: setVoiced(MY_FLOAT vGain)
120
 
{
121
 
        voiced->setGainTarget(vGain);
122
 
}
123
 
 
124
 
void VoicForm :: setUnVoiced(MY_FLOAT nGain)
125
 
{
126
 
        noiseEnv->setTarget(nGain);
127
 
}
128
 
 
129
 
void VoicForm :: setVoicedUnVoiced(MY_FLOAT vGain, MY_FLOAT nGain)
130
 
{
131
 
        this->setVoiced(vGain);
132
 
        this->setUnVoiced(nGain);
133
 
}
134
 
 
135
 
void VoicForm :: setFiltSweepRate(int whichOne,MY_FLOAT rate)
136
 
{
137
 
        filters[whichOne]->setSweepRate(rate);
138
 
}
139
 
 
140
 
void VoicForm :: setPitchSweepRate(MY_FLOAT rate)
141
 
{
142
 
        voiced->setSweepRate(rate);
143
 
}
144
 
 
145
 
void VoicForm :: speak()
146
 
{
147
 
        voiced->noteOn();
148
 
}
149
 
 
150
 
void VoicForm :: quiet()
151
 
{
152
 
        voiced->noteOff();
153
 
        noiseEnv->setTarget((MY_FLOAT) 0.0);
154
 
}
155
 
 
156
 
void VoicForm :: noteOn(MY_FLOAT freq, MY_FLOAT amp)
157
 
{
158
 
        this->setFreq(freq);
159
 
        voiced->setGainTarget(amp);
160
 
        onepole->setPole((MY_FLOAT) 0.95 - (amp * (MY_FLOAT) NORM_7 * (MY_FLOAT) 0.2));
161
 
}
162
 
 
163
 
void VoicForm :: noteOff(MY_FLOAT amp)
164
 
{
165
 
        this->quiet();
166
 
}
167
 
 
168
 
MY_FLOAT VoicForm :: tick()
169
 
{
170
 
        MY_FLOAT temp;
171
 
        temp   = onepole->tick(onezero->tick(voiced->tick()));
172
 
        temp  += noiseEnv->tick() * noise->tick();
173
 
        lastOutput  = filters[0]->tick(temp);
174
 
        lastOutput  = filters[1]->tick(lastOutput);
175
 
        lastOutput  = filters[2]->tick(lastOutput);
176
 
        lastOutput  = filters[3]->tick(lastOutput);
177
 
        lastOutput *= lastGain;
178
 
        return lastOutput;
179
 
}
180
 
 
181
 
void VoicForm :: controlChange(int number, MY_FLOAT value)
182
 
{
183
 
#if defined(_debug_)        
184
 
        printf("VoicForm : ControlChange: Number=%i Value=%f\n",number,value);
185
 
#endif
186
 
        if (number == __SK_Breath_)     {
187
 
                this->setVoiced((MY_FLOAT) 1.0 - (value *(MY_FLOAT) NORM_7));
188
 
                this->setUnVoiced((MY_FLOAT) 0.01 * value * (MY_FLOAT) NORM_7);
189
 
        }
190
 
        else if (number == __SK_FootControl_)   {
191
 
    MY_FLOAT temp = 0.0;
192
 
                int tempi = (int) value;
193
 
                if (tempi < 32) {
194
 
      tempi = tempi;
195
 
      temp = (MY_FLOAT) 0.9;
196
 
                }
197
 
                else if (tempi < 64)    {
198
 
      tempi = tempi - 32;
199
 
      temp = (MY_FLOAT) 1.0;
200
 
                }
201
 
                else if (tempi < 96)    {
202
 
      tempi = tempi - 64;
203
 
      temp = (MY_FLOAT) 1.1;
204
 
                }
205
 
                else if (tempi <= 128)  {
206
 
      tempi = tempi - 96;
207
 
      temp = (MY_FLOAT) 1.2;
208
 
                }
209
 
                this->setFormantAll(0,temp*(MY_FLOAT) phonParams[tempi][0][0],
210
 
                        (MY_FLOAT) phonParams[tempi][0][1],
211
 
                        (MY_FLOAT) pow(10.0,phonParams[tempi][0][2] / 20.0));
212
 
                this->setFormantAll(1,temp*(MY_FLOAT) phonParams[tempi][1][0],
213
 
                        (MY_FLOAT) phonParams[tempi][1][1],(MY_FLOAT) 1.0);
214
 
                this->setFormantAll(2,temp*(MY_FLOAT) phonParams[tempi][2][0],
215
 
                        (MY_FLOAT) phonParams[tempi][2][1],(MY_FLOAT) 1.0);
216
 
                this->setFormantAll(3,temp*(MY_FLOAT) phonParams[tempi][3][0],
217
 
                        (MY_FLOAT) phonParams[tempi][3][1],(MY_FLOAT) 1.0);
218
 
    this->setVoicedUnVoiced(phonGains[tempi][0],phonGains[tempi][1]);
219
 
        }
220
 
        else if (number == __SK_ModFrequency_)
221
 
                voiced->setVibFreq(value * (MY_FLOAT) NORM_7 * (MY_FLOAT) 12.0);  /* 0 to 12 Hz */
222
 
        else if (number == __SK_ModWheel_)
223
 
                voiced->setVibAmt(value * (MY_FLOAT) NORM_7 * (MY_FLOAT) 0.2);
224
 
        else if (number == __SK_AfterTouch_Cont_)       {
225
 
                this->setVoiced(value*NORM_7);
226
 
                onepole->setPole((MY_FLOAT) 0.99 - (value *(MY_FLOAT) NORM_7 * (MY_FLOAT) 0.2));
227
 
                //onepole->setPole((MY_FLOAT) 0.5 - (value * (MY_FLOAT) NORM_7 * (MY_FLOAT) 0.2));
228
 
        }
229
 
        else    {
230
 
                printf("VoicForm : Undefined Control Number!!\n");
231
 
        }  
232
 
}