The code allows for the delay time (in milliseconds) and the gain.
See also:
Please do not redistribute this code. In the event that it contains a bug, this will ensure that it can be fixed without the buggy copies floating around indefinitely.
Last Modified: 6/28/98
/*********************************************************
Comb.cpp - A comb filter for building reverberators
Copyright (c) 1998, Scott Lehman, slehman@harmony-central.com
This code may be used and modified freely provided that credit
is given to the author in any public release. Any derivative
programs must be distributed freely and/or the modified source
code made publicly available. All code is provided AS IS and
without warranty of any kind.
*********************************************************/
#ifndef COMB_H
#define COMB_H
#include "Processor.h"
class Comb : public Processor {
public:
Comb(float delay, float gain); //delay is in milliseconds
void Initialize(void);
void Process(void);
void Cleanup(void);
~Comb(){;}
private:
float delay, gain;
float * bufferStart, * bufferEnd, * readPtr;
float * inputSignal, * outputSignal;
int i, numSamples;
Comb(Comb&){};
};
#endif
|
/*********************************************************
Comb.cpp - A comb filter for building reverberators
Copyright (c) 1998, Scott Lehman, slehman@harmony-central.com
This code may be used and modified freely provided that credit
is given to the author in any public release. Any derivative
programs must be distributed freely and/or the modified source
code made publicly available. All code is provided AS IS and
without warranty of any kind.
*********************************************************/
#include "Comb.h"
// *************** Comb(float, float) ***************
Comb :: Comb(float delayTime, float feedbackGain)
{
SetNumInputs(1);
SetNumOutputs(1);
gain = feedbackGain;
delay = delayTime; //delaytime in milliseconds
}
// *************** Initialize(void) ********************
void Comb :: Initialize (void)
{
int bufferLength = int(delay*samplingRate/1000);
bufferStart = new float[bufferLength];
bufferEnd = bufferStart + bufferLength;
//zero out the buffer (silence)
for(i=0; i<bufferLength; i++)
bufferStart[i] = 0.0;
//set read pointer to start of buffer
readPtr = bufferStart;
//assign pointers for the only input and output
inputSignal = inputs[0];
outputSignal = outputs[0];
return;
}
// **************** Process(void) ********************
void Comb :: Process (void)
{
for(i=0; i<frameLength; i++) { //for each sample...
outputSignal[i] = *readPtr; //read the value
//write the scaled value + the new input sample
*readPtr = (*readPtr)*gain + inputSignal[i];
if(++readPtr >= bufferEnd) //if reach end of buffer, wrap
readPtr = bufferStart;
}
}
// ***************** Cleanup(void) ******************
void Comb :: Cleanup (void)
{
delete [] bufferStart;
return;
}
|