You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

34 lines
595 B

#include "tone.h"
#include <math.h>
#include "../utility/dsp.h"
using namespace daisysp;
void Tone::Init(float sample_rate)
{
prevout_ = 0.0f;
freq_ = 100.0f;
c1_ = 0.5f;
c2_ = 0.5f;
sample_rate_ = sample_rate;
}
float Tone::Process(float &in)
{
float out;
out = c1_ * in + c2_ * prevout_;
prevout_ = out;
return out;
}
void Tone::CalculateCoefficients()
{
float b, c1, c2;
b = 2.0f - cosf(TWOPI_F * freq_ / sample_rate_);
c2 = b - sqrtf(b * b - 1.0f);
c1 = 1.0f - c2;
c1_ = c1;
c2_ = c2;
}