Version 4.2.0

This commit is contained in:
Gary Scavone
2009-03-24 23:02:14 -04:00
committed by Stephen Sinclair
parent cf06b7598b
commit a6381b9d38
281 changed files with 17152 additions and 12000 deletions

View File

@@ -12,14 +12,14 @@
filters in parallel with corresponding right
and left outputs.
by Perry R. Cook and Gary P. Scavone, 1995 - 2002.
by Perry R. Cook and Gary P. Scavone, 1995 - 2004.
*/
/***************************************************/
#include "NRev.h"
#include <math.h>
NRev :: NRev(MY_FLOAT T60)
NRev :: NRev(StkFloat T60)
{
int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19};
double scaler = Stk::sampleRate() / 25641.0;
@@ -33,77 +33,94 @@ NRev :: NRev(MY_FLOAT T60)
}
for (i=0; i<6; i++) {
combDelays[i] = new Delay( lengths[i], lengths[i]);
combCoefficient[i] = pow(10.0, (-3 * lengths[i] / (T60 * Stk::sampleRate())));
combDelays_[i].setMaximumDelay( lengths[i] );
combDelays_[i].setDelay( lengths[i] );
combCoefficient_[i] = pow(10.0, (-3 * lengths[i] / (T60 * Stk::sampleRate())));
}
for (i=0; i<8; i++)
allpassDelays[i] = new Delay(lengths[i+6], lengths[i+6]);
for (i=0; i<8; i++) {
allpassDelays_[i].setMaximumDelay( lengths[i+6] );
allpassDelays_[i].setDelay( lengths[i+6] );
}
allpassCoefficient = 0.7;
effectMix = 0.3;
this->setT60( T60 );
allpassCoefficient_ = 0.7;
effectMix_ = 0.3;
this->clear();
}
NRev :: ~NRev()
{
int i;
for (i=0; i<6; i++) delete combDelays[i];
for (i=0; i<8; i++) delete allpassDelays[i];
}
void NRev :: clear()
{
int i;
for (i=0; i<6; i++) combDelays[i]->clear();
for (i=0; i<8; i++) allpassDelays[i]->clear();
lastOutput[0] = 0.0;
lastOutput[1] = 0.0;
lowpassState = 0.0;
for (i=0; i<6; i++) combDelays_[i].clear();
for (i=0; i<8; i++) allpassDelays_[i].clear();
lastOutput_[0] = 0.0;
lastOutput_[1] = 0.0;
lowpassState_ = 0.0;
}
MY_FLOAT NRev :: tick(MY_FLOAT input)
void NRev :: setT60( StkFloat T60 )
{
MY_FLOAT temp, temp0, temp1, temp2, temp3;
for ( int i=0; i<6; i++ )
combCoefficient_[i] = pow(10.0, (-3.0 * combDelays_[i].getDelay() / (T60 * Stk::sampleRate())));
}
StkFloat NRev :: tick(StkFloat input)
{
StkFloat temp, temp0, temp1, temp2, temp3;
int i;
temp0 = 0.0;
for (i=0; i<6; i++) {
temp = input + (combCoefficient[i] * combDelays[i]->lastOut());
temp0 += combDelays[i]->tick(temp);
temp = input + (combCoefficient_[i] * combDelays_[i].lastOut());
temp0 += combDelays_[i].tick(temp);
}
for (i=0; i<3; i++) {
temp = allpassDelays[i]->lastOut();
temp1 = allpassCoefficient * temp;
temp = allpassDelays_[i].lastOut();
temp1 = allpassCoefficient_ * temp;
temp1 += temp0;
allpassDelays[i]->tick(temp1);
temp0 = -(allpassCoefficient * temp1) + temp;
allpassDelays_[i].tick(temp1);
temp0 = -(allpassCoefficient_ * temp1) + temp;
}
// One-pole lowpass filter.
lowpassState = 0.7*lowpassState + 0.3*temp0;
temp = allpassDelays[3]->lastOut();
temp1 = allpassCoefficient * temp;
temp1 += lowpassState;
allpassDelays[3]->tick(temp1);
temp1 = -(allpassCoefficient * temp1) + temp;
lowpassState_ = 0.7*lowpassState_ + 0.3*temp0;
temp = allpassDelays_[3].lastOut();
temp1 = allpassCoefficient_ * temp;
temp1 += lowpassState_;
allpassDelays_[3].tick(temp1);
temp1 = -(allpassCoefficient_ * temp1) + temp;
temp = allpassDelays[4]->lastOut();
temp2 = allpassCoefficient * temp;
temp = allpassDelays_[4].lastOut();
temp2 = allpassCoefficient_ * temp;
temp2 += temp1;
allpassDelays[4]->tick(temp2);
lastOutput[0] = effectMix*(-(allpassCoefficient * temp2) + temp);
allpassDelays_[4].tick(temp2);
lastOutput_[0] = effectMix_*(-(allpassCoefficient_ * temp2) + temp);
temp = allpassDelays[5]->lastOut();
temp3 = allpassCoefficient * temp;
temp = allpassDelays_[5].lastOut();
temp3 = allpassCoefficient_ * temp;
temp3 += temp1;
allpassDelays[5]->tick(temp3);
lastOutput[1] = effectMix*(-(allpassCoefficient * temp3) + temp);
allpassDelays_[5].tick(temp3);
lastOutput_[1] = effectMix_*(-(allpassCoefficient_ * temp3) + temp);
temp = (1.0 - effectMix) * input;
lastOutput[0] += temp;
lastOutput[1] += temp;
temp = (1.0 - effectMix_) * input;
lastOutput_[0] += temp;
lastOutput_[1] += temp;
return (lastOutput[0] + lastOutput[1]) * 0.5;
return Effect::lastOut();
}
StkFloat *NRev :: tick(StkFloat *vector, unsigned int vectorSize)
{
return Effect::tick( vector, vectorSize );
}
StkFrames& NRev :: tick( StkFrames& frames, unsigned int channel )
{
return Effect::tick( frames, channel );
}