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

@@ -29,7 +29,7 @@
- Register State = 1
- Breath Pressure = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2010.
by Perry R. Cook and Gary P. Scavone, 1995-2011.
*/
/***************************************************/
@@ -41,12 +41,17 @@ namespace stk {
BlowHole :: BlowHole( StkFloat lowestFrequency )
{
length_ = (unsigned long) ( Stk::sampleRate() / lowestFrequency + 1 );
if ( lowestFrequency <= 0.0 ) {
oStream_ << "BlowHole::BlowHole: argument is less than or equal to zero!";
handleError( StkError::FUNCTION_ARGUMENT );
}
unsigned long nDelays = (unsigned long) ( 0.5 * Stk::sampleRate() / lowestFrequency );
// delays[0] is the delay line between the reed and the register vent.
delays_[0].setDelay( 5.0 * Stk::sampleRate() / 22050.0 );
// delays[1] is the delay line between the register vent and the tonehole.
delays_[1].setMaximumDelay( length_ );
delays_[1].setDelay( length_ >> 1 );
delays_[1].setMaximumDelay( nDelays + 1 );
// delays[2] is the delay line between the tonehole and the end of the bore.
delays_[2].setDelay( 4.0 * Stk::sampleRate() / 22050.0 );
@@ -61,9 +66,9 @@ BlowHole :: BlowHole( StkFloat lowestFrequency )
// Calculate tonehole coefficients and set for initially open.
StkFloat te = 1.4 * rth; // effective length of the open hole
thCoeff_ = (te*2*Stk::sampleRate() - 347.23) / (te*2*Stk::sampleRate() + 347.23);
tonehole_.setA1(-thCoeff_);
tonehole_.setB0(thCoeff_);
tonehole_.setB1(-1.0);
tonehole_.setA1( -thCoeff_ );
tonehole_.setB0( thCoeff_ );
tonehole_.setB1( -1.0 );
// Calculate register hole filter coefficients
double r_rh = 0.0015; // register vent radius
@@ -74,15 +79,18 @@ BlowHole :: BlowHole( StkFloat lowestFrequency )
StkFloat rhCoeff = (zeta - 2 * Stk::sampleRate() * psi) / (zeta + 2 * Stk::sampleRate() * psi);
rhGain_ = -347.23 / (zeta + 2 * Stk::sampleRate() * psi);
vent_.setA1( rhCoeff );
vent_.setB0(1.0);
vent_.setB1(1.0);
vent_.setB0( 1.0 );
vent_.setB1( 1.0 );
// Start with register vent closed
vent_.setGain(0.0);
vent_.setGain( 0.0 );
vibrato_.setFrequency((StkFloat) 5.735);
outputGain_ = 1.0;
noiseGain_ = 0.2;
vibratoGain_ = 0.01;
this->setFrequency( 220.0 );
this->clear();
}
BlowHole :: ~BlowHole( void )
@@ -101,19 +109,18 @@ void BlowHole :: clear( void )
void BlowHole :: setFrequency( StkFloat frequency )
{
StkFloat freakency = frequency;
#if defined(_STK_DEBUG_)
if ( frequency <= 0.0 ) {
std::cerr << "BlowHole: setFrequency parameter is less than or equal to zero!" << std::endl;
freakency = 220.0;
oStream_ << "BlowHole::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 - 3.5;
// Account for approximate filter delays and one sample "lastOut" delay.
StkFloat delay = ( Stk::sampleRate() / frequency ) * 0.5 - 3.5;
delay -= delays_[0].getDelay() + delays_[2].getDelay();
if (delay <= 0.0) delay = 0.3;
else if (delay > length_) delay = length_;
delays_[1].setDelay(delay);
delays_[1].setDelay( delay );
}
void BlowHole :: setVent( StkFloat newValue )
@@ -124,9 +131,9 @@ void BlowHole :: setVent( StkFloat newValue )
StkFloat gain;
if (newValue <= 0.0)
if ( newValue <= 0.0 )
gain = 0.0;
else if (newValue >= 1.0)
else if ( newValue >= 1.0 )
gain = rhGain_;
else
gain = newValue * rhGain_;
@@ -146,7 +153,7 @@ void BlowHole :: setTonehole( StkFloat newValue )
else if ( newValue >= 1.0 )
new_coeff = thCoeff_;
else
new_coeff = (newValue * (thCoeff_ - 0.9995)) + 0.9995;
new_coeff = ( newValue * (thCoeff_ - 0.9995) ) + 0.9995;
tonehole_.setA1( -new_coeff );
tonehole_.setB0( new_coeff );
@@ -154,12 +161,22 @@ void BlowHole :: setTonehole( StkFloat newValue )
void BlowHole :: startBlowing( StkFloat amplitude, StkFloat rate )
{
if ( amplitude <= 0.0 || rate <= 0.0 ) {
oStream_ << "BlowHole::startBlowing: one or more arguments is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
envelope_.setRate( rate );
envelope_.setTarget( amplitude );
}
void BlowHole :: stopBlowing( StkFloat rate )
{
if ( rate <= 0.0 ) {
oStream_ << "BlowHole::stopBlowing: argument is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
envelope_.setRate( rate );
envelope_.setTarget( 0.0 );
}
@@ -169,55 +186,38 @@ void BlowHole :: noteOn( StkFloat frequency, StkFloat amplitude )
this->setFrequency( frequency );
this->startBlowing( 0.55 + (amplitude * 0.30), amplitude * 0.005 );
outputGain_ = amplitude + 0.001;
#if defined(_STK_DEBUG_)
errorString_ << "BlowHole::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
handleError( StkError::DEBUG_WARNING );
#endif
}
void BlowHole :: noteOff( StkFloat amplitude )
{
this->stopBlowing( amplitude * 0.01 );
#if defined(_STK_DEBUG_)
errorString_ << "BlowHole::NoteOff: amplitude = " << amplitude << ".";
handleError( StkError::DEBUG_WARNING );
#endif
}
void BlowHole :: controlChange( int number, StkFloat value )
{
StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
errorString_ << "BlowHole::controlChange: control value less than zero ... setting to zero!";
handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
errorString_ << "BlowHole::controlChange: control value greater than 128.0 ... setting to 128.0!";
handleError( StkError::WARNING );
}
if (number == __SK_ReedStiffness_) // 2
reedTable_.setSlope( -0.44 + (0.26 * norm) );
else if (number == __SK_NoiseLevel_) // 4
noiseGain_ = ( norm * 0.4);
else if (number == __SK_ModFrequency_) // 11
this->setTonehole( norm );
else if (number == __SK_ModWheel_) // 1
this->setVent( norm );
else if (number == __SK_AfterTouch_Cont_) // 128
envelope_.setValue( norm );
else {
errorString_ << "BlowHole::controlChange: undefined control number (" << number << ")!";
handleError( StkError::WARNING );
}
#if defined(_STK_DEBUG_)
errorString_ << "BlowHole::controlChange: number = " << number << ", value = " << value << ".";
handleError( StkError::DEBUG_WARNING );
if ( Stk::inRange( value, 0.0, 128.0 ) == false ) {
oStream_ << "BlowHole::controlChange: value (" << value << ") is out of range!";
handleError( StkError::WARNING ); return;
}
#endif
StkFloat normalizedValue = value * ONE_OVER_128;
if (number == __SK_ReedStiffness_) // 2
reedTable_.setSlope( -0.44 + (0.26 * normalizedValue) );
else if (number == __SK_NoiseLevel_) // 4
noiseGain_ = ( normalizedValue * 0.4);
else if (number == __SK_ModFrequency_) // 11
this->setTonehole( normalizedValue );
else if (number == __SK_ModWheel_) // 1
this->setVent( normalizedValue );
else if (number == __SK_AfterTouch_Cont_) // 128
envelope_.setValue( normalizedValue );
#if defined(_STK_DEBUG_)
else {
oStream_ << "BlowHole::controlChange: undefined control number (" << number << ")!";
handleError( StkError::WARNING );
}
#endif
}