Version 4.4.0

This commit is contained in:
Gary Scavone
2013-09-29 23:11:39 +02:00
committed by Stephen Sinclair
parent d199342e86
commit eccd8c9981
287 changed files with 11712 additions and 7676 deletions

View File

@@ -2,43 +2,45 @@
/*! \class NRev
\brief CCRMA's NRev reverberator class.
This class is derived from the CLM NRev
function, which is based on the use of
networks of simple allpass and comb delay
filters. This particular arrangement consists
of 6 comb filters in parallel, followed by 3
allpass filters, a lowpass filter, and another
allpass in series, followed by two allpass
filters in parallel with corresponding right
and left outputs.
This class takes a monophonic input signal and produces a stereo
output signal. It is derived from the CLM NRev function, which is
based on the use of networks of simple allpass and comb delay
filters. This particular arrangement consists of 6 comb filters
in parallel, followed by 3 allpass filters, a lowpass filter, and
another allpass in series, followed by two allpass filters in
parallel with corresponding right and left outputs.
by Perry R. Cook and Gary P. Scavone, 1995 - 2007.
by Perry R. Cook and Gary P. Scavone, 1995 - 2009.
*/
/***************************************************/
#include "NRev.h"
#include <math.h>
#include <cmath>
NRev :: NRev(StkFloat T60)
namespace stk {
NRev :: NRev( StkFloat T60 )
{
lastFrame_.resize( 1, 2, 0.0 ); // resize lastFrame_ for stereo output
int lengths[15] = {1433, 1601, 1867, 2053, 2251, 2399, 347, 113, 37, 59, 53, 43, 37, 29, 19};
double scaler = Stk::sampleRate() / 25641.0;
int delay, i;
for (i=0; i<15; i++) {
for ( i=0; i<15; i++ ) {
delay = (int) floor(scaler * lengths[i]);
if ( (delay & 1) == 0) delay++;
while ( !this->isPrime(delay) ) delay += 2;
lengths[i] = delay;
}
for (i=0; i<6; i++) {
for ( i=0; i<6; i++ ) {
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++) {
for ( i=0; i<8; i++ ) {
allpassDelays_[i].setMaximumDelay( lengths[i+6] );
allpassDelays_[i].setDelay( lengths[i+6] );
}
@@ -49,17 +51,13 @@ NRev :: NRev(StkFloat T60)
this->clear();
}
NRev :: ~NRev()
{
}
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;
lastFrame_[0] = 0.0;
lastFrame_[1] = 0.0;
lowpassState_ = 0.0;
}
@@ -69,47 +67,44 @@ void NRev :: setT60( StkFloat T60 )
combCoefficient_[i] = pow(10.0, (-3.0 * combDelays_[i].getDelay() / (T60 * Stk::sampleRate())));
}
StkFloat NRev :: computeSample(StkFloat input)
StkFrames& NRev :: tick( StkFrames& frames, unsigned int channel )
{
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);
#if defined(_STK_DEBUG_)
if ( channel >= frames.channels() - 1 ) {
errorString_ << "NRev::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
for (i=0; i<3; i++) {
temp = allpassDelays_[i].lastOut();
temp1 = allpassCoefficient_ * temp;
temp1 += temp0;
allpassDelays_[i].tick(temp1);
temp0 = -(allpassCoefficient_ * temp1) + temp;
#endif
StkFloat *samples = &frames[channel];
unsigned int hop = frames.channels();
for ( unsigned int i=0; i<frames.frames(); i++, samples += hop ) {
*samples = tick( *samples );
samples++;
*samples = lastFrame_[1];
}
// 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;
temp = allpassDelays_[4].lastOut();
temp2 = allpassCoefficient_ * temp;
temp2 += temp1;
allpassDelays_[4].tick(temp2);
lastOutput_[0] = effectMix_*(-(allpassCoefficient_ * temp2) + temp);
temp = allpassDelays_[5].lastOut();
temp3 = allpassCoefficient_ * temp;
temp3 += temp1;
allpassDelays_[5].tick(temp3);
lastOutput_[1] = effectMix_*(-(allpassCoefficient_ * temp3) + temp);
temp = (1.0 - effectMix_) * input;
lastOutput_[0] += temp;
lastOutput_[1] += temp;
return Effect::lastOut();
return frames;
}
StkFrames& NRev :: tick( StkFrames& iFrames, StkFrames& oFrames, unsigned int iChannel, unsigned int oChannel )
{
#if defined(_STK_DEBUG_)
if ( iChannel >= iFrames.channels() || oChannel >= oFrames.channels() - 1 ) {
errorString_ << "NRev::tick(): channel and StkFrames arguments are incompatible!";
handleError( StkError::FUNCTION_ARGUMENT );
}
#endif
StkFloat *iSamples = &iFrames[iChannel];
StkFloat *oSamples = &oFrames[oChannel];
unsigned int iHop = iFrames.channels(), oHop = oFrames.channels();
for ( unsigned int i=0; i<iFrames.frames(); i++, iSamples += iHop, oSamples += oHop ) {
*oSamples++ = tick( *iSamples );
*oSamples = lastFrame_[1];
}
return iFrames;
}
} // stk namespace