diff options
author | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2003-08-16 17:08:55 +0000 |
---|---|---|
committer | Hans-Christoph Steiner <eighthave@users.sourceforge.net> | 2003-08-16 17:08:55 +0000 |
commit | 506b8e7dedb80d79bf015e47d92e8b8dd8284584 (patch) | |
tree | 6393e98add0a0ae7f92388665b3b6242977f5b64 /stkdrone~/drone.cc | |
parent | 856eaf396d9a4d371a458a2c373a052bb72c8057 (diff) |
added files straight from Yves' sources
svn path=/trunk/externals/unauthorized/; revision=864
Diffstat (limited to 'stkdrone~/drone.cc')
-rw-r--r-- | stkdrone~/drone.cc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/stkdrone~/drone.cc b/stkdrone~/drone.cc new file mode 100644 index 0000000..ba065ad --- /dev/null +++ b/stkdrone~/drone.cc @@ -0,0 +1,77 @@ + /******************************************/ +/* Karplus-Strong drone string model */ +/* by Perry Cook, 1995-96 */ +/* */ +/* There exist at least two patents, */ +/* assigned to Stanford, bearing the */ +/* names of Karplus and/or Strong. */ +/******************************************/ + +#include "drone.h" + +drone :: drone(MY_FLOAT lowestFreq) +{ + length = (long) (SRATE / lowestFreq + 1); + loopGain = (MY_FLOAT) 0.999; + loopFilt = new OneZero(); + delayLine = new DLineA(length); + envelope = new ADSR(); + noise = new Noise; + envelope->setAllTimes(2.0,0.5,0.0,0.5); + this->clear(); +} + +drone :: ~drone() +{ + delete loopFilt; + delete delayLine; + delete envelope; + delete noise; +} + +void drone :: clear() +{ + loopFilt->clear(); + delayLine->clear(); +} + +void drone :: setFreq(MY_FLOAT frequency) +{ + MY_FLOAT delay; + delay = (SRATE / frequency); + delayLine->setDelay(delay - 0.5); + loopGain = (MY_FLOAT) 0.997 + (frequency * (MY_FLOAT) 0.000002); + if (loopGain>1.0) loopGain = (MY_FLOAT) 0.99999; +} + +void drone :: pluck(MY_FLOAT amplitude) +{ + envelope->keyOn(); +} + +void drone :: noteOn(MY_FLOAT freq, MY_FLOAT amp) +{ + this->setFreq(freq); + this->pluck(amp); +#if defined(_debug_) + printf("drone : NoteOn: Freq=%lf Amp=%lf\n",freq,amp); +#endif +} + +void drone :: noteOff(MY_FLOAT amp) +{ + loopGain = (MY_FLOAT) 1.0 - amp; +#if defined(_debug_) + printf("drone : NoteOff: Amp=%lf\n",amp); +#endif +} + +MY_FLOAT drone :: tick() +{ + /* check this out */ + /* here's the whole inner loop of the instrument!! */ + lastOutput = delayLine->tick(loopFilt->tick((delayLine->lastOut() * loopGain)) + + (0.005 * envelope->tick() * noise->tick())); + return lastOutput; +} + |