/* * Filename: Operator.cpp * * Description: * * * Version: * Created: Sun Mar 8 08:36:21 2020 * Revision: None * Author: Rachel Fae Fox (foxiepaws),fox@foxiepa.ws * */ #include "Operator.h" namespace amalgam { namespace FM { void Operator::process(){ phase += smpTime * (((*freq * mul) + detune)); _out=last=sin((2*M_PI*phase) + _in + (fbgain*last)); } double Operator::operator()(){ process(); elast = e(); return elast * _out; } double Operator::operator()(double in){ _in = in; process(); elast = e(); return elast * _out; } void Operator::setAll(double mul, double detune, double fbgain) { this->mul = mul; this->detune = detune; this->fbgain = fbgain; } Operator::Operator(){ __m = true; freq = (double*) malloc(sizeof(double)); gate = (bool*) malloc(sizeof(bool)); e.setGate(gate); } Operator::Operator(double* f, bool* g) { gate = g; freq = f; e.setGate(gate); } Operator::Operator(double* f, bool* g, unsigned int sr) { gate = g; freq = f; smpRate = sr; smpTime = 1.0/sr; e.setRate(sr); e.setGate(gate); } Operator::~Operator(){ if (__m) { free(freq); free(gate); } } } }