Version 4.4.3

This commit is contained in:
Gary Scavone
2013-09-29 23:21:29 +02:00
committed by Stephen Sinclair
parent baca57040b
commit 0aec39260a
223 changed files with 26190 additions and 11130 deletions

View File

@@ -13,20 +13,26 @@
Stanford, bearing the names of Karplus and/or
Strong.
by Perry R. Cook and Gary P. Scavone, 1995 - 2010.
by Perry R. Cook and Gary P. Scavone, 1995-2011.
*/
/***************************************************/
#include "Drone.h"
#include <sstream>
namespace stk {
Drone :: Drone( StkFloat lowestFrequency )
{
length_ = (unsigned long) ( Stk::sampleRate() / lowestFrequency + 1 );
loopGain_ = 0.999;
delayLine_.setMaximumDelay( length_ );
delayLine_.setDelay( 0.5 * length_ );
if ( lowestFrequency <= 0.0 ) {
oStream_ << "Drone::Drone: argument is less than or equal to zero!";
handleError( StkError::FUNCTION_ARGUMENT );
}
unsigned long delays = (unsigned long) ( Stk::sampleRate() / lowestFrequency );
delayLine_.setMaximumDelay( delays + 1 );
this->setFrequency( 220.0 );
envelope_.setAllTimes( 2.0, 0.5, 0.0, 0.5 );
this->clear();
}
@@ -43,21 +49,18 @@ void Drone :: clear( void )
void Drone :: setFrequency( StkFloat frequency )
{
StkFloat freakency = frequency;
#if defined(_STK_DEBUG_)
if ( frequency <= 0.0 ) {
errorString_ << "Drone::setFrequency: parameter is less than or equal to zero!";
handleError( StkError::WARNING );
freakency = 220.0;
oStream_ << "Drone::setFrequency: argument is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
#endif
// Delay = length - approximate filter delay.
StkFloat delay = (Stk::sampleRate() / freakency) - 0.5;
if ( delay <= 0.0 )
delay = 0.3;
else if (delay > length_)
delay = length_;
StkFloat delay = (Stk::sampleRate() / frequency) - 0.5;
delayLine_.setDelay( delay );
loopGain_ = 0.997 + (freakency * 0.000002);
loopGain_ = 0.997 + (frequency * 0.000002);
if ( loopGain_ >= 1.0 ) loopGain_ = 0.99999;
}
@@ -70,31 +73,16 @@ void Drone :: noteOn( StkFloat frequency, StkFloat amplitude )
{
this->setFrequency( frequency );
this->pluck( amplitude );
#if defined(_STK_DEBUG_)
errorString_ << "Drone::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
handleError( StkError::DEBUG_WARNING );
#endif
}
void Drone :: noteOff( StkFloat amplitude )
{
loopGain_ = 1.0 - amplitude;
if ( loopGain_ < 0.0 ) {
errorString_ << "Drone::noteOff: amplitude is greater than 1.0 ... setting to 1.0!";
handleError( StkError::WARNING );
loopGain_ = 0.0;
}
else if ( loopGain_ > 1.0 ) {
errorString_ << "Drone::noteOff: amplitude is < 0.0 ... setting to 0.0!";
handleError( StkError::WARNING );
loopGain_ = 0.99999;
if ( amplitude < 0.0 || amplitude > 1.0 ) {
oStream_ << "Plucked::noteOff: amplitude is out of range!";
handleError( StkError::WARNING ); return;
}
#if defined(_STK_DEBUG_)
errorString_ << "Drone::noteOff: amplitude = " << amplitude << ".";
handleError( StkError::DEBUG_WARNING );
#endif
loopGain_ = 1.0 - amplitude;
}
} // stk namespace