mirror of
https://github.com/thestk/stk
synced 2026-01-13 04:51:53 +00:00
Version 2.01
This commit is contained in:
committed by
Stephen Sinclair
parent
6485746ee9
commit
ea749b71d2
78
Mandolin.cpp
78
Mandolin.cpp
@@ -4,8 +4,8 @@
|
||||
/* by Perry Cook, 1995-96 */
|
||||
/* Controls: CONTROL1 = bodySize */
|
||||
/* CONTROL2 = pluckPosition */
|
||||
/* CONTROL3 = loopGain */
|
||||
/* MOD_WHEEL= deTuning */
|
||||
/* CONTROL3 = loopGain */
|
||||
/* MOD_WHEEL= deTuning */
|
||||
/* */
|
||||
/* Note: Commuted Synthesis, as with many */
|
||||
/* other WaveGuide techniques, is covered */
|
||||
@@ -17,24 +17,46 @@
|
||||
/********************************************/
|
||||
|
||||
#include "Mandolin.h"
|
||||
#include "SKINI11.msg"
|
||||
|
||||
Mandolin :: Mandolin(MY_FLOAT lowestFreq) : Plucked2(lowestFreq)
|
||||
{
|
||||
soundfile = new RawWave("rawwaves/mandpluk.raw");
|
||||
soundfile->normalize(0.05); /* Empirical hack here */
|
||||
soundfile->setLooping(0);
|
||||
int i;
|
||||
|
||||
soundfile[0] = new RawWave("rawwaves/mand1.raw");
|
||||
soundfile[1] = new RawWave("rawwaves/mand2.raw");
|
||||
soundfile[2] = new RawWave("rawwaves/mand3.raw");
|
||||
soundfile[3] = new RawWave("rawwaves/mand4.raw");
|
||||
soundfile[4] = new RawWave("rawwaves/mand5.raw");
|
||||
soundfile[5] = new RawWave("rawwaves/mand6.raw");
|
||||
soundfile[6] = new RawWave("rawwaves/mand7.raw");
|
||||
soundfile[7] = new RawWave("rawwaves/mand8.raw");
|
||||
soundfile[8] = new RawWave("rawwaves/mand9.raw");
|
||||
soundfile[9] = new RawWave("rawwaves/mand10.raw");
|
||||
soundfile[10] = new RawWave("rawwaves/mand11.raw");
|
||||
soundfile[11] = new RawWave("rawwaves/mand12.raw");
|
||||
for (i=0;i<12;i++) {
|
||||
// soundfile[i]->normalize((MY_FLOAT) 0.1); /* Empirical hack here */
|
||||
soundfile[i]->setLooping(0);
|
||||
}
|
||||
directBody = 1.0;
|
||||
mic = 0;
|
||||
dampTime = 0;
|
||||
waveDone = 1;
|
||||
}
|
||||
|
||||
Mandolin :: ~Mandolin()
|
||||
{
|
||||
}
|
||||
|
||||
void Mandolin :: pluck(MY_FLOAT amplitude)
|
||||
{ /* this function gets interesting here, */
|
||||
soundfile->reset(); /* because pluck may be longer than */
|
||||
soundfile[mic]->reset(); /* because pluck may be longer than */
|
||||
pluckAmp = amplitude; /* string length, so we just reset the */
|
||||
/* soundfile and add in the pluck in */
|
||||
/* the tick method. */
|
||||
combDelay->setDelay(
|
||||
0.5 * pluckPos * lastLength); /* Set Pick Position */
|
||||
(MY_FLOAT) 0.5 * pluckPos * lastLength); /* Set Pick Position */
|
||||
/* which puts zeroes at pos*length */
|
||||
dampTime = (long) lastLength; /* See tick method below */
|
||||
waveDone = 0;
|
||||
@@ -57,15 +79,18 @@ void Mandolin :: noteOn(MY_FLOAT freq, MY_FLOAT amp)
|
||||
|
||||
void Mandolin :: setBodySize(MY_FLOAT size)
|
||||
{
|
||||
soundfile->setRate(size);
|
||||
int i;
|
||||
for (i=0;i<12;i++) {
|
||||
soundfile[i]->setRate(size);
|
||||
}
|
||||
}
|
||||
|
||||
MY_FLOAT Mandolin :: tick()
|
||||
{
|
||||
MY_FLOAT temp = 0;
|
||||
MY_FLOAT temp = (MY_FLOAT) 0;
|
||||
if (!waveDone) {
|
||||
waveDone = soundfile->informTick(); /* as long as it goes . . . */
|
||||
temp = soundfile->lastOut() * pluckAmp; /* scaled pluck excitation */
|
||||
waveDone = soundfile[mic]->informTick(); /* as long as it goes . . . */
|
||||
temp = soundfile[mic]->lastOut() * pluckAmp; /* scaled pluck excitation */
|
||||
temp = temp - combDelay->tick(temp); /* with comb filtering */
|
||||
}
|
||||
if (dampTime>=0) { /* Damping hack to help avoid */
|
||||
@@ -73,11 +98,11 @@ MY_FLOAT Mandolin :: tick()
|
||||
lastOutput = delayLine->tick( /* Calculate 1st delay */
|
||||
filter->tick( /* filterered reflection */
|
||||
temp + /* plus pluck excitation */
|
||||
(delayLine->lastOut() * 0.7)));
|
||||
(delayLine->lastOut() * (MY_FLOAT) 0.7)));
|
||||
lastOutput += delayLine2->tick( /* and 2nd delay */
|
||||
filter2->tick( /* just like the 1st */
|
||||
temp +
|
||||
(delayLine2->lastOut() * 0.7))); /* that's the whole thing!! */
|
||||
(delayLine2->lastOut() * (MY_FLOAT) 0.7))); /* that's the whole thing!! */
|
||||
}
|
||||
else { /* No damping hack after 1 period */
|
||||
lastOutput = delayLine->tick( /* Calculate 1st delay */
|
||||
@@ -91,7 +116,7 @@ MY_FLOAT Mandolin :: tick()
|
||||
(delayLine2->lastOut()
|
||||
* loopGain)));
|
||||
}
|
||||
lastOutput *= 2.0;
|
||||
lastOutput *= (MY_FLOAT) 0.3 / 32768.0;
|
||||
return lastOutput;
|
||||
}
|
||||
|
||||
@@ -100,17 +125,20 @@ void Mandolin :: controlChange(int number, MY_FLOAT value)
|
||||
#if defined(_debug_)
|
||||
printf("Mandolin : ControlChange: Number=%i Value=%f\n",number,value);
|
||||
#endif
|
||||
if (number == MIDI_control1)
|
||||
this->setBodySize(value * NORM_7 * 2.0);
|
||||
else if (number == MIDI_control2)
|
||||
this->setPluckPos(value * NORM_7);
|
||||
else if (number == MIDI_control3)
|
||||
this->setBaseLoopGain(0.97 + (value * NORM_7 * 0.03));
|
||||
else if (number == MIDI_mod_wheel)
|
||||
this->setDetune(1.0 - (value * NORM_7 * 0.1));
|
||||
else if (number == MIDI_after_touch)
|
||||
this->pluck(value * NORM_7);
|
||||
if (number == __SK_BodySize_)
|
||||
this->setBodySize(value * (MY_FLOAT) NORM_7 * (MY_FLOAT) 2.0);
|
||||
else if (number == __SK_PickPosition_)
|
||||
this->setPluckPos(value * (MY_FLOAT) NORM_7);
|
||||
else if (number == __SK_StringDamping_)
|
||||
this->setBaseLoopGain((MY_FLOAT) 0.97 + (value * (MY_FLOAT) NORM_7 * (MY_FLOAT) 0.03));
|
||||
else if (number == __SK_StringDetune_)
|
||||
this->setDetune((MY_FLOAT) 1.0 - (value * (MY_FLOAT) NORM_7 * (MY_FLOAT) 0.1));
|
||||
else if (number == __SK_AfterTouch_)
|
||||
this->pluck(value * (MY_FLOAT) NORM_7);
|
||||
else if (number == 411) {
|
||||
mic = (int) value % 12;
|
||||
}
|
||||
else {
|
||||
printf("Mandolin : Undefined Control Number!!\n");
|
||||
printf("Mandolin : Undefined Control Number!! %i\n",number);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user