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

@@ -16,7 +16,7 @@
- Vibrato Gain = 1
- Volume = 128
by Perry R. Cook and Gary P. Scavone, 1995 - 2010.
by Perry R. Cook and Gary P. Scavone, 1995-2011.
*/
/***************************************************/
@@ -28,22 +28,25 @@ namespace stk {
Brass :: Brass( StkFloat lowestFrequency )
{
length_ = (unsigned long) ( Stk::sampleRate() / lowestFrequency + 1 );
delayLine_.setMaximumDelay( length_ );
delayLine_.setDelay( 0.5 * length_ );
if ( lowestFrequency <= 0.0 ) {
oStream_ << "Brass::Brass: argument is less than or equal to zero!";
handleError( StkError::FUNCTION_ARGUMENT );
}
unsigned long nDelays = (unsigned long) ( Stk::sampleRate() / lowestFrequency );
delayLine_.setMaximumDelay( nDelays + 1 );
lipFilter_.setGain( 0.03 );
dcBlock_.setBlockZero();
adsr_.setAllTimes( 0.005, 0.001, 1.0, 0.010 );
vibrato_.setFrequency( 6.137 );
vibratoGain_ = 0.0;
this->clear();
maxPressure_ = 0.0;
lipTarget_ = 0.0;
this->clear();
// This is necessary to initialize variables.
this->setFrequency( 220.0 );
}
@@ -61,35 +64,40 @@ void Brass :: clear( void )
void Brass :: setFrequency( StkFloat frequency )
{
StkFloat freakency = frequency;
#if defined(_STK_DEBUG_)
if ( frequency <= 0.0 ) {
errorString_ << "Brass::setFrequency: parameter is less than or equal to zero!";
handleError( StkError::WARNING );
freakency = 220.0;
oStream_ << "Brass::setFrequency: argument is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
#endif
// Fudge correction for filter delays.
slideTarget_ = (Stk::sampleRate() / freakency * 2.0) + 3.0;
slideTarget_ = ( Stk::sampleRate() / frequency * 2.0 ) + 3.0;
delayLine_.setDelay( slideTarget_ ); // play a harmonic
lipTarget_ = freakency;
lipFilter_.setResonance( freakency, 0.997 );
lipTarget_ = frequency;
lipFilter_.setResonance( frequency, 0.997 );
}
void Brass :: setLip( StkFloat frequency )
{
StkFloat freakency = frequency;
#if defined(_STK_DEBUG_)
if ( frequency <= 0.0 ) {
errorString_ << "Brass::setLip: parameter is less than or equal to zero!";
handleError( StkError::WARNING );
freakency = 220.0;
oStream_ << "Brass::setLip: argument is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
#endif
lipFilter_.setResonance( freakency, 0.997 );
lipFilter_.setResonance( frequency, 0.997 );
}
void Brass :: startBlowing( StkFloat amplitude, StkFloat rate )
{
if ( amplitude <= 0.0 || rate <= 0.0 ) {
oStream_ << "Brass::startBlowing: one or more arguments is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
adsr_.setAttackRate( rate );
maxPressure_ = amplitude;
adsr_.keyOn();
@@ -97,6 +105,11 @@ void Brass :: startBlowing( StkFloat amplitude, StkFloat rate )
void Brass :: stopBlowing( StkFloat rate )
{
if ( rate <= 0.0 ) {
oStream_ << "Brass::stopBlowing: argument is less than or equal to zero!";
handleError( StkError::WARNING ); return;
}
adsr_.setReleaseRate( rate );
adsr_.keyOff();
}
@@ -105,57 +118,40 @@ void Brass :: noteOn( StkFloat frequency, StkFloat amplitude )
{
this->setFrequency( frequency );
this->startBlowing( amplitude, amplitude * 0.001 );
#if defined(_STK_DEBUG_)
errorString_ << "Brass::NoteOn: frequency = " << frequency << ", amplitude = " << amplitude << ".";
handleError( StkError::DEBUG_WARNING );
#endif
}
void Brass :: noteOff( StkFloat amplitude )
{
this->stopBlowing( amplitude * 0.005 );
#if defined(_STK_DEBUG_)
errorString_ << "Brass::NoteOff: amplitude = " << amplitude << ".";
handleError( StkError::DEBUG_WARNING );
#endif
}
void Brass :: controlChange( int number, StkFloat value )
{
StkFloat norm = value * ONE_OVER_128;
if ( norm < 0 ) {
norm = 0.0;
errorString_ << "Brass::controlChange: control value less than zero ... setting to zero!";
handleError( StkError::WARNING );
}
else if ( norm > 1.0 ) {
norm = 1.0;
errorString_ << "Brass::controlChange: control value greater than 128.0 ... setting to 128.0!";
handleError( StkError::WARNING );
#if defined(_STK_DEBUG_)
if ( Stk::inRange( value, 0.0, 128.0 ) == false ) {
oStream_ << "Brass::controlChange: value (" << value << ") is out of range!";
handleError( StkError::WARNING ); return;
}
#endif
StkFloat normalizedValue = value * ONE_OVER_128;
if (number == __SK_LipTension_) { // 2
StkFloat temp = lipTarget_ * pow( 4.0, (2.0 * norm) - 1.0 );
this->setLip(temp);
StkFloat temp = lipTarget_ * pow( 4.0, (2.0 * normalizedValue) - 1.0 );
this->setLip( temp );
}
else if (number == __SK_SlideLength_) // 4
delayLine_.setDelay( slideTarget_ * (0.5 + norm) );
delayLine_.setDelay( slideTarget_ * (0.5 + normalizedValue) );
else if (number == __SK_ModFrequency_) // 11
vibrato_.setFrequency( norm * 12.0 );
vibrato_.setFrequency( normalizedValue * 12.0 );
else if (number == __SK_ModWheel_ ) // 1
vibratoGain_ = norm * 0.4;
vibratoGain_ = normalizedValue * 0.4;
else if (number == __SK_AfterTouch_Cont_) // 128
adsr_.setTarget( norm );
adsr_.setTarget( normalizedValue );
#if defined(_STK_DEBUG_)
else {
errorString_ << "Brass::controlChange: undefined control number (" << number << ")!";
oStream_ << "Brass::controlChange: undefined control number (" << number << ")!";
handleError( StkError::WARNING );
}
#if defined(_STK_DEBUG_)
errorString_ << "Brass::controlChange: number = " << number << ", value = " << value << ".";
handleError( StkError::DEBUG_WARNING );
#endif
}