~ubuntu-branches/ubuntu/oneiric/muse/oneiric

« back to all changes in this revision

Viewing changes to synti/stklib/FMVoices.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************/
 
2
/*  Singing Voice Synthesis Subclass      */
 
3
/*  of Algorithm 6 (TX81Z) Subclass of    */ 
 
4
/*  4 Operator FM Synth                   */
 
5
/*  by Perry R. Cook, 1996                */ 
 
6
/******************************************/
 
7
 
 
8
#include "FMVoices.h"
 
9
#include "SKINI11.msg"
 
10
 
 
11
FMVoices :: FMVoices() : FM4Alg6()
 
12
{
 
13
  // Concatenate the STK RAWWAVE_PATH to the rawwave file
 
14
  char file1[128];
 
15
  char file2[128];
 
16
  char file3[128];
 
17
  char file4[128];
 
18
  strcpy(file1, RAWWAVE_PATH);
 
19
  strcpy(file2, RAWWAVE_PATH);
 
20
  strcpy(file3, RAWWAVE_PATH);
 
21
  strcpy(file4, RAWWAVE_PATH);
 
22
  this->loadWaves(strcat(file1,"rawwaves/sinewave.raw"),
 
23
                  strcat(file2,"rawwaves/sinewave.raw"),
 
24
                  strcat(file3,"rawwaves/sinewave.raw"),
 
25
                  strcat(file4,"rawwaves/fwavblnk.raw"));
 
26
    
 
27
  this->setRatio(0,(MY_FLOAT) 2.00);
 
28
  this->setRatio(1,(MY_FLOAT) 4.00);
 
29
  this->setRatio(2,(MY_FLOAT) 12.0);
 
30
  this->setRatio(3,(MY_FLOAT) 1.00);
 
31
  gains[3] = __FM4Op_gains[80];
 
32
  adsr[0]->setAllTimes((MY_FLOAT) 0.050,(MY_FLOAT) 0.050,
 
33
                       __FM4Op_susLevels[15],(MY_FLOAT) 0.050);
 
34
  adsr[1]->setAllTimes((MY_FLOAT) 0.050,(MY_FLOAT) 0.050,
 
35
                       __FM4Op_susLevels[15],(MY_FLOAT) 0.050);
 
36
  adsr[2]->setAllTimes((MY_FLOAT) 0.050,(MY_FLOAT) 0.050,
 
37
                       __FM4Op_susLevels[15],(MY_FLOAT) 0.050);
 
38
  adsr[3]->setAllTimes((MY_FLOAT) 0.010,(MY_FLOAT) 0.010,
 
39
                       __FM4Op_susLevels[15],(MY_FLOAT) 0.500);
 
40
  twozero->setGain((MY_FLOAT) 0.0);
 
41
  modDepth = (MY_FLOAT) 0.005;
 
42
  currentVowel = 0;
 
43
  tilt[0] = (MY_FLOAT) 1.0;
 
44
  tilt[1] = (MY_FLOAT) 0.5;
 
45
  tilt[2] = (MY_FLOAT) 0.2;    
 
46
  mods[0] = (MY_FLOAT) 1.0;
 
47
  mods[1] = (MY_FLOAT) 1.1;
 
48
  mods[2] = (MY_FLOAT) 1.1;
 
49
  baseFreq = (MY_FLOAT) 110.0;
 
50
  this->setFreq((MY_FLOAT) 110.0);    
 
51
}  
 
52
 
 
53
/*  #include "phonTabl.h"   */
 
54
 
 
55
extern double phonGains[32][2];
 
56
extern double phonParams[32][4][3];
 
57
extern char phonemes[32][4];
 
58
 
 
59
void FMVoices :: setFreq(MY_FLOAT frequency)
 
60
{    
 
61
  MY_FLOAT temp, temp2 = 0.0;
 
62
  int tempi, tempi2 = 0;
 
63
 
 
64
  if (currentVowel < 32)        {
 
65
    tempi2 = currentVowel;
 
66
    temp2 = (MY_FLOAT) 0.9;
 
67
  }
 
68
  else if (currentVowel < 64)   {
 
69
    tempi2 = currentVowel - 32;
 
70
    temp2 = (MY_FLOAT) 1.0;
 
71
  }
 
72
  else if (currentVowel < 96)   {
 
73
    tempi2 = currentVowel - 64;
 
74
    temp2 = (MY_FLOAT) 1.1;
 
75
  }
 
76
  else if (currentVowel <= 128) {
 
77
    tempi2 = currentVowel - 96;
 
78
    temp2 = (MY_FLOAT) 1.2;
 
79
  }
 
80
  baseFreq = frequency;
 
81
  temp = (temp2 * (MY_FLOAT)  phonParams[tempi2][0][0] / baseFreq) + (MY_FLOAT) 0.5;
 
82
  tempi = (int) temp;
 
83
  this->setRatio(0,(MY_FLOAT) tempi);
 
84
  temp = (temp2 * (MY_FLOAT)  phonParams[tempi2][1][0] / baseFreq) + (MY_FLOAT) 0.5;
 
85
  tempi = (int) temp;
 
86
  this->setRatio(1,(MY_FLOAT) tempi);
 
87
  temp = (temp2 * (MY_FLOAT)  phonParams[tempi2][2][0] / baseFreq) + (MY_FLOAT) 0.5;
 
88
  tempi = (int) temp;
 
89
  this->setRatio(2,(MY_FLOAT) tempi);    
 
90
  gains[0] = (MY_FLOAT)  1.0;  // pow(10.0,phonParams[tempi2][0][2] * 0.05);
 
91
  gains[1] = (MY_FLOAT)  1.0;  // pow(10.0,phonParams[tempi2][1][2] * 0.05);
 
92
  gains[2] = (MY_FLOAT)  1.0;  // pow(10.0,phonParams[tempi2][2][2] * 0.05);
 
93
}
 
94
 
 
95
void FMVoices :: noteOn(MY_FLOAT freq, MY_FLOAT amp)
 
96
{
 
97
  this->setFreq(freq);
 
98
  tilt[0] = amp;
 
99
  tilt[1] = amp * amp;
 
100
  tilt[2] = amp * amp * amp;
 
101
  this->keyOn();
 
102
#if defined(_debug_)        
 
103
  printf("FMVoices : NoteOn: Freq=%lf Amp=%lf\n",freq,amp);
 
104
#endif    
 
105
}
 
106
 
 
107
void FMVoices :: controlChange(int number, MY_FLOAT value)
 
108
{
 
109
  MY_FLOAT temp;
 
110
  int tempi;
 
111
 
 
112
#if defined(_debug_)        
 
113
  printf("FM4Op : ControlChange: Number=%i Value=%f\n",number,value);
 
114
#endif    
 
115
  if (number == __SK_Breath_)
 
116
    gains[3] = __FM4Op_gains[(int) (value * 0.78125)];
 
117
  else if (number == __SK_FootControl_) {
 
118
    tempi = (int) value;
 
119
    currentVowel = tempi;
 
120
    this->setFreq(baseFreq);
 
121
  }
 
122
  else if (number == __SK_ModFrequency_)
 
123
    this->setModulationSpeed(value * NORM_7 * (MY_FLOAT) 12.0);  /* 0 to 12 Hz */
 
124
  else if (number == __SK_ModWheel_)
 
125
    this->setModulationDepth(value * NORM_7);
 
126
  else if (number == __SK_AfterTouch_Cont_)     {
 
127
    temp = value * NORM_7;
 
128
    tilt[0] = temp;
 
129
    tilt[1] = temp * temp;
 
130
    tilt[2] = temp * temp * temp;
 
131
  }
 
132
  else  {
 
133
    printf("FM4Op : Undefined Control Number!!\n");
 
134
  }  
 
135
}
 
136