feat(filter): Add modulation support and LFO integration
This commit is contained in:
parent
3c3fec9b90
commit
fe594a5494
6 changed files with 131 additions and 20 deletions
44
core/Oscillator.cpp
Normal file
44
core/Oscillator.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "Oscillator.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
Oscillator::Oscillator(float initFreq)
|
||||
: freq_(initFreq), gain_(100.0f), waveShape_(kWaveShapeSine),
|
||||
sampleRate_(48000.f), phase_(0.0f), inc_(0.0f) {
|
||||
recalc_();
|
||||
};
|
||||
|
||||
void Oscillator::process(float *out, uint32_t frames) {
|
||||
for (uint32_t i = 0; i < frames; ++i) {
|
||||
switch (waveShape_) {
|
||||
default:
|
||||
case kWaveShapeSine:
|
||||
out[i] = std::sinf(phase_ * 2.0f * M_PI) * gain_;
|
||||
break;
|
||||
}
|
||||
phase_ += inc_;
|
||||
if (phase_ >= 1.0f)
|
||||
phase_ -= 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Oscillator::recalc_() { inc_ = freq_ / sampleRate_; }
|
||||
|
||||
void Oscillator::setFrequency(float newFreq) {
|
||||
freq_ = std::fmax(newFreq, 0.0f);
|
||||
}
|
||||
float Oscillator::getFrequency() const { return freq_; };
|
||||
|
||||
void Oscillator::setGain(float newGain) {
|
||||
gain_ = newGain > 0 ? newGain : 1.0f;
|
||||
}
|
||||
float Oscillator::getGain() const { return gain_; };
|
||||
|
||||
void Oscillator::setSampleRate(float newSampleRate) {
|
||||
sampleRate_ = newSampleRate > 0 ? newSampleRate : 48000.0f;
|
||||
recalc_();
|
||||
}
|
||||
float Oscillator::getSampleRate() const { return sampleRate_; }
|
||||
|
||||
void Oscillator::setWaveShape(WaveShape shape) { waveShape_ = shape; }
|
||||
Oscillator::WaveShape Oscillator::getWaveShape() const { return waveShape_; }
|
||||
Loading…
Add table
Add a link
Reference in a new issue