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

« back to all changes in this revision

Viewing changes to synti/stklib/Modal4.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
 
/*
3
 
  Four Resonance Modal Synthesis Instrument
4
 
  by Perry R. Cook, 1995-2000
5
 
 
6
 
  This instrument contains an excitation
7
 
  wavetable, an envelope, an oscillator,
8
 
  and four resonances (Non-Sweeping BiQuad
9
 
  Filters).
10
 
*/
11
 
/*******************************************/
12
 
 
13
 
#include "Modal4.h"
14
 
 
15
 
Modal4 :: Modal4()
16
 
{
17
 
  envelope = new Envelope;
18
 
  // We don't make the excitation wave here yet,
19
 
  // because we don't know what it's going to be.
20
 
  filters[0] = new BiQuad;
21
 
  filters[1] = new BiQuad;
22
 
  filters[2] = new BiQuad;
23
 
  filters[3] = new BiQuad;
24
 
  onepole = new OnePole;
25
 
 
26
 
  // Concatenate the STK RAWWAVE_PATH to the rawwave file
27
 
  char file[128];
28
 
  strcpy(file, RAWWAVE_PATH);
29
 
  vibr = new RawWvIn(strcat(file,"rawwaves/sinewave.raw"),"looping");
30
 
  vibr->setFreq((MY_FLOAT) 6.0);
31
 
  vibrGain = (MY_FLOAT) 0.0; // zero gain by default
32
 
    
33
 
  directGain = (MY_FLOAT) 0.0;
34
 
  masterGain = (MY_FLOAT) 1.0;
35
 
  baseFreq = (MY_FLOAT) 440.0;
36
 
  this->setRatioAndReson(0,(MY_FLOAT) 1.00,(MY_FLOAT) 0.9997);    /*  Set some      */
37
 
  this->setRatioAndReson(1,(MY_FLOAT) 1.30,(MY_FLOAT) 0.9997);    /*  silly         */
38
 
  this->setRatioAndReson(2,(MY_FLOAT) 1.77,(MY_FLOAT) 0.9997);    /*  default       */
39
 
  this->setRatioAndReson(3,(MY_FLOAT) 2.37,(MY_FLOAT) 0.9997);    /*  values here   */
40
 
  this->setFiltGain(0,(MY_FLOAT) 0.01);
41
 
  this->setFiltGain(1,(MY_FLOAT) 0.01);
42
 
  this->setFiltGain(2,(MY_FLOAT) 0.01);
43
 
  this->setFiltGain(3,(MY_FLOAT) 0.01);
44
 
  this->clear();
45
 
  filters[0]->setEqualGainZeroes();
46
 
  filters[1]->setEqualGainZeroes();
47
 
  filters[2]->setEqualGainZeroes();
48
 
  filters[3]->setEqualGainZeroes();
49
 
  stickHardness = (MY_FLOAT) 0.5;
50
 
  strikePosition = (MY_FLOAT) 0.561;
51
 
}  
52
 
 
53
 
Modal4 :: ~Modal4()
54
 
{
55
 
  delete envelope; 
56
 
  delete filters[0];
57
 
  delete filters[1];
58
 
  delete filters[2];
59
 
  delete filters[3];
60
 
  delete onepole;
61
 
  delete vibr;
62
 
}
63
 
 
64
 
void Modal4 :: clear()
65
 
{    
66
 
  onepole->clear();
67
 
  filters[0]->clear();
68
 
  filters[1]->clear();
69
 
  filters[2]->clear();
70
 
  filters[3]->clear();
71
 
}
72
 
 
73
 
void Modal4 :: setFreq(MY_FLOAT frequency)
74
 
{    
75
 
  baseFreq = frequency;
76
 
  this->setRatioAndReson(0,ratios[0],resons[0]);
77
 
  this->setRatioAndReson(1,ratios[1],resons[1]);
78
 
  this->setRatioAndReson(2,ratios[2],resons[2]);
79
 
  this->setRatioAndReson(3,ratios[3],resons[3]);
80
 
}
81
 
 
82
 
#include <stdio.h>
83
 
 
84
 
void Modal4 :: setRatioAndReson(int whichOne, MY_FLOAT ratio,MY_FLOAT reson)
85
 
{
86
 
  MY_FLOAT temp;
87
 
 
88
 
  if (ratio*baseFreq < SRATE_OVER_TWO) {
89
 
    ratios[whichOne] = ratio;
90
 
  }
91
 
  else {
92
 
    temp = ratio;
93
 
    while (temp*baseFreq > SRATE_OVER_TWO) temp *= (MY_FLOAT) 0.5;
94
 
    ratios[whichOne] = temp;
95
 
#if defined(_debug_)        
96
 
    printf("Modal4 : Aliasing would occur here, correcting.\n");
97
 
#endif    
98
 
  }
99
 
  resons[whichOne] = reson;
100
 
  if (ratio < 0) 
101
 
    temp = -ratio;
102
 
  else
103
 
    temp = ratio*baseFreq;
104
 
 
105
 
  filters[whichOne]->setFreqAndReson(temp,reson);
106
 
}
107
 
 
108
 
void Modal4 :: setMasterGain(MY_FLOAT aGain)
109
 
{
110
 
  masterGain = aGain;
111
 
}
112
 
 
113
 
void Modal4 :: setDirectGain(MY_FLOAT aGain)
114
 
{
115
 
  directGain = aGain;
116
 
}
117
 
 
118
 
void Modal4 :: setFiltGain(int whichOne, MY_FLOAT gain)
119
 
{
120
 
  filters[whichOne]->setGain(gain);
121
 
}
122
 
 
123
 
void Modal4 :: strike(MY_FLOAT amplitude)
124
 
{
125
 
  int i;
126
 
  MY_FLOAT temp;
127
 
 
128
 
  envelope->setRate((MY_FLOAT) 1.0);
129
 
  envelope->setTarget(amplitude);
130
 
  onepole->setPole((MY_FLOAT) 1.0 - amplitude);
131
 
  envelope->tick();
132
 
  wave->reset();
133
 
 
134
 
  for (i=0; i<4; i++) {
135
 
    if (ratios[i] < 0)
136
 
      temp = -ratios[i];
137
 
    else
138
 
      temp = ratios[i] * baseFreq;
139
 
    filters[i]->setFreqAndReson(temp,resons[i]);
140
 
  }
141
 
}
142
 
 
143
 
void Modal4 :: noteOn(MY_FLOAT freq, MY_FLOAT amp)
144
 
{
145
 
  this->strike(amp);
146
 
  this->setFreq(freq);
147
 
#if defined(_debug_)        
148
 
  printf("Modal4 : NoteOn: Freq=%lf Amp=%lf\n",freq,amp);
149
 
#endif    
150
 
}
151
 
 
152
 
/* This calls damp, but inverts the meaning of amplitude
153
 
 * (high amplitude means fast damping).
154
 
 */
155
 
void Modal4 :: noteOff(MY_FLOAT amp)
156
 
{
157
 
  this->damp((MY_FLOAT) 1.0 - (amp * (MY_FLOAT) 0.03));
158
 
#if defined(_debug_)        
159
 
  printf("Modal4 : NoteOff: Amp=%lf\n",amp);
160
 
#endif    
161
 
}
162
 
 
163
 
void Modal4 :: damp(MY_FLOAT amplitude)
164
 
{
165
 
  int i;
166
 
  MY_FLOAT temp;
167
 
 
168
 
  for (i=0; i<4; i++) {
169
 
    if (ratios[i] < 0)
170
 
      temp = -ratios[i];
171
 
    else
172
 
      temp = ratios[i] * baseFreq;
173
 
    filters[i]->setFreqAndReson(temp,resons[i]*amplitude);
174
 
  }
175
 
}
176
 
 
177
 
void Modal4 :: controlChange(int number, MY_FLOAT value)
178
 
{
179
 
}
180
 
 
181
 
MY_FLOAT Modal4 :: tick()
182
 
{
183
 
  MY_FLOAT temp,temp2;
184
 
 
185
 
  temp   = masterGain * onepole->tick(wave->tick() * envelope->tick());
186
 
  temp2  = filters[0]->tick(temp);
187
 
  temp2 += filters[1]->tick(temp);
188
 
  temp2 += filters[2]->tick(temp);
189
 
  temp2 += filters[3]->tick(temp);
190
 
  temp2  = temp2 - (temp2 * directGain);
191
 
  temp2 += directGain * temp;
192
 
 
193
 
  if (vibrGain != 0.0)  {
194
 
    // Calculate AM and apply to master out
195
 
    temp = (MY_FLOAT) 1.0 + (vibr->tick() * vibrGain);
196
 
    temp2 = temp * temp2;
197
 
  }
198
 
    
199
 
  lastOutput = temp2 * (MY_FLOAT) 2.0;
200
 
  return lastOutput;
201
 
}
202