50 lines
1005 B
C++
50 lines
1005 B
C++
/*
|
|
* Filename: basic.cpp
|
|
*
|
|
* Description:
|
|
*
|
|
*
|
|
* Version:
|
|
* Created: Fri Nov 1 00:04:23 2019
|
|
* Revision: None
|
|
* Author: Rachel Fae Fox (foxiepaws),fox@foxiepa.ws
|
|
*
|
|
*/
|
|
|
|
#include "../common.h"
|
|
#include "../utils/envelope.h"
|
|
#include "basic.h"
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
float Basic::run() {
|
|
float out;
|
|
this->env.gate = this->gate;
|
|
switch (this->shape) {
|
|
case _waveform_saw:
|
|
out = this->amp * this->env.run() * fmod((this->freq+1) * this->t / 44100,1.0);
|
|
break;
|
|
case _waveform_sine:
|
|
out = this->amp * this->env.run() * sin(2 * M_PI * this->t * this->freq / 44100);
|
|
break;
|
|
case _waveform_square:
|
|
out = this->amp * this->env.run() * fmod((this->freq+1) * this->t / 44100,1.0) > this->pwm;
|
|
break;
|
|
default:
|
|
out = 0.0F;
|
|
break;
|
|
}
|
|
|
|
return out;
|
|
}
|
|
|
|
Basic::Basic(Waveform w, Envelope e) {
|
|
this->shape = w;
|
|
this->env = e;
|
|
this->amp = 1.0;
|
|
this->pwm = 0.5f;
|
|
this->gate = false;
|
|
this->t = 0;
|
|
}
|
|
|