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

@@ -17,7 +17,7 @@
- String Sustain = 11
- String Stretch = 1
by Perry R. Cook and Gary P. Scavone, 1995 - 2010.
by Perry R. Cook and Gary P. Scavone, 1995-2011.
*/
/***************************************************/
@@ -29,21 +29,24 @@ namespace stk {
StifKarp :: StifKarp( StkFloat lowestFrequency )
{
length_ = (unsigned long) ( Stk::sampleRate() / lowestFrequency + 1 );
delayLine_.setMaximumDelay( length_ );
delayLine_.setDelay( 0.5 * length_ );
combDelay_.setMaximumDelay( length_ );
combDelay_.setDelay( 0.2 * length_ );
if ( lowestFrequency <= 0.0 ) {
oStream_ << "StifKarp::StifKarp: argument is less than or equal to zero!";
handleError( StkError::FUNCTION_ARGUMENT );
}
unsigned long nDelays = (unsigned long) ( Stk::sampleRate() / lowestFrequency );
delayLine_.setMaximumDelay( nDelays + 1 );
combDelay_.setMaximumDelay( nDelays + 1 );
pluckAmplitude_ = 0.3;
pickupPosition_ = 0.4;
lastFrequency_ = lowestFrequency * 2.0;
lastLength_ = length_ * 0.5;
stretching_ = 0.9999;
baseLoopGain_ = 0.995;
loopGain_ = 0.999;
this->clear();
this->setFrequency( 220.0 );
}
StifKarp :: ~StifKarp( void )
@@ -59,19 +62,16 @@ void StifKarp :: clear( void )
void StifKarp :: setFrequency( StkFloat frequency )
{
lastFrequency_ = frequency;
#if defined(_STK_DEBUG_)
if ( frequency <= 0.0 ) {
errorString_ << "StifKarp::setFrequency: parameter is less than or equal to zero!";
handleError( StkError::WARNING );
lastFrequency_ = 220.0;
oStream_ << "StifKarp::setFrequency: parameter is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
#endif
lastFrequency_ = frequency;
lastLength_ = Stk::sampleRate() / lastFrequency_;
StkFloat delay = lastLength_ - 0.5;
if (delay <= 0.0)
delay = 0.3;
else if (delay > length_)
delay = length_;
delayLine_.setDelay( delay );
loopGain_ = baseLoopGain_ + (frequency * 0.000005);
@@ -89,8 +89,8 @@ void StifKarp :: setStretch( StkFloat stretch )
StkFloat freq = lastFrequency_ * 2.0;
StkFloat dFreq = ( (0.5 * Stk::sampleRate()) - freq ) * 0.25;
StkFloat temp = 0.5 + (stretch * 0.5);
if (temp > 0.9999) temp = 0.9999;
for (int i=0; i<4; i++) {
if ( temp > 0.9999 ) temp = 0.9999;
for ( int i=0; i<4; i++ ) {
coefficient = temp * temp;
biquad_[i].setA2( coefficient );
biquad_[i].setB0( coefficient );
@@ -105,19 +105,14 @@ void StifKarp :: setStretch( StkFloat stretch )
}
void StifKarp :: setPickupPosition( StkFloat position ) {
pickupPosition_ = position;
if ( position < 0.0 ) {
errorString_ << "StifKarp::setPickupPosition: parameter is less than zero ... setting to 0.0!";
handleError( StkError::WARNING );
pickupPosition_ = 0.0;
}
else if ( position > 1.0 ) {
errorString_ << "StifKarp::setPickupPosition: parameter is greater than 1.0 ... setting to 1.0!";
handleError( StkError::WARNING );
pickupPosition_ = 1.0;
if ( position < 0.0 || position > 1.0 ) {
oStream_ << "StifKarp::setPickupPosition: parameter is out of range!";
handleError( StkError::WARNING ); return;
}
// Set the pick position, which puts zeroes at position * length.
pickupPosition_ = position;
combDelay_.setDelay( 0.5 * pickupPosition_ * lastLength_ );
}
@@ -130,20 +125,13 @@ void StifKarp :: setBaseLoopGain( StkFloat aGain )
void StifKarp :: pluck( StkFloat amplitude )
{
StkFloat gain = amplitude;
if ( gain > 1.0 ) {
errorString_ << "StifKarp::pluck: amplitude is greater than 1.0 ... setting to 1.0!";
handleError( StkError::WARNING );
gain = 1.0;
}
else if ( gain < 0.0 ) {
errorString_ << "StifKarp::pluck: amplitude is less than zero ... setting to 0.0!";
handleError( StkError::WARNING );
gain = 0.0;
if ( amplitude < 0.0 || amplitude > 1.0 ) {
oStream_ << "StifKarp::pluck: amplitude is out of range!";
handleError( StkError::WARNING ); return;
}
pluckAmplitude_ = amplitude;
for (unsigned long i=0; i<length_; i++) {
for ( unsigned long i=0; i<length_; i++ ) {
// Fill delay with noise additively with current contents.
delayLine_.tick( (delayLine_.lastOut() * 0.6) + 0.4 * noise_.tick() * pluckAmplitude_ );
//delayLine_.tick( combDelay_.tick((delayLine_.lastOut() * 0.6) + 0.4 * noise->tick() * pluckAmplitude_) );
@@ -154,62 +142,39 @@ void StifKarp :: noteOn( StkFloat frequency, StkFloat amplitude )
{
this->setFrequency( frequency );
this->pluck( amplitude );
#if defined(_STK_DEBUG_)
errorString_ << "StifKarp::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
handleError( StkError::DEBUG_WARNING );
#endif
}
void StifKarp :: noteOff( StkFloat amplitude )
{
StkFloat gain = amplitude;
if ( gain > 1.0 ) {
errorString_ << "StifKarp::noteOff: amplitude is greater than 1.0 ... setting to 1.0!";
handleError( StkError::WARNING );
gain = 1.0;
if ( amplitude < 0.0 || amplitude > 1.0 ) {
oStream_ << "StifKarp::noteOff: amplitude is out of range!";
handleError( StkError::WARNING ); return;
}
else if ( gain < 0.0 ) {
errorString_ << "StifKarp::noteOff: amplitude is < 0.0 ... setting to 0.0!";
handleError( StkError::WARNING );
gain = 0.0;
}
loopGain_ = (1.0 - gain) * 0.5;
#if defined(_STK_DEBUG_)
errorString_ << "StifKarp::NoteOff: amplitude = " << amplitude << ".";
handleError( StkError::DEBUG_WARNING );
#endif
loopGain_ = (1.0 - amplitude) * 0.5;
}
void StifKarp :: controlChange( int number, StkFloat value )
{
StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
errorString_ << "StifKarp::controlChange: control value less than zero ... setting to zero!";
handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
errorString_ << "StifKarp::controlChange: control value greater than 128.0 ... setting to 128.0!";
handleError( StkError::WARNING );
}
if (number == __SK_PickPosition_) // 4
this->setPickupPosition( norm );
else if (number == __SK_StringDamping_) // 11
this->setBaseLoopGain( 0.97 + (norm * 0.03) );
else if (number == __SK_StringDetune_) // 1
this->setStretch( 0.9 + (0.1 * (1.0 - norm)) );
else {
errorString_ << "StifKarp::controlChange: undefined control number (" << number << ")!";
handleError( StkError::WARNING );
}
#if defined(_STK_DEBUG_)
errorString_ << "StifKarp::controlChange: number = " << number << ", value = " << value << ".";
handleError( StkError::DEBUG_WARNING );
if ( Stk::inRange( value, 0.0, 128.0 ) == false ) {
oStream_ << "Clarinet::controlChange: value (" << value << ") is out of range!";
handleError( StkError::WARNING ); return;
}
#endif
StkFloat normalizedValue = value * ONE_OVER_128;
if (number == __SK_PickPosition_) // 4
this->setPickupPosition( normalizedValue );
else if (number == __SK_StringDamping_) // 11
this->setBaseLoopGain( 0.97 + (normalizedValue * 0.03) );
else if (number == __SK_StringDetune_) // 1
this->setStretch( 0.9 + (0.1 * (1.0 - normalizedValue)) );
#if defined(_STK_DEBUG_)
else {
oStream_ << "StifKarp::controlChange: undefined control number (" << number << ")!";
handleError( StkError::WARNING );
}
#endif
}