wip: filter lfo
This commit is contained in:
@@ -18,6 +18,7 @@ void Filter::Trigger() {}
|
||||
void Filter::Release() {}
|
||||
|
||||
float Filter::Process(float in) {
|
||||
calculate_coefficients();
|
||||
float out = in * m_a0 + m_z1;
|
||||
m_z1 = in * m_a1 + m_z2 - m_b1 * out;
|
||||
m_z2 = in * m_a2 - m_b2 * out;
|
||||
@@ -28,7 +29,7 @@ void Filter::Process(std::vector<float>& samples) {
|
||||
// todo: that will not work for ADSR-controlled filter. So, let's calculate
|
||||
// all the possible frequency values into array/dictionary then just lookup
|
||||
// for each sample
|
||||
calculate_coefficients();
|
||||
|
||||
for (std::size_t i = 0; i < samples.size(); i++) {
|
||||
samples[i] = Process(samples[i]);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
LowPassFilter::LowPassFilter() {
|
||||
// todo: defaults
|
||||
m_freq = 200.f / SAMPLE_RATE;
|
||||
m_q = 0.707f;
|
||||
m_q = 1.0f;//0.707f;
|
||||
m_order = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ void Oscillator::SetFreq(float freq) {
|
||||
m_phase_dt = (this->*m_dt_function)(freq);
|
||||
}
|
||||
|
||||
float Oscillator::GenerateSample(float duration) {
|
||||
float Oscillator::GenerateSample() {
|
||||
return (this->*m_osc_function)() * m_volume;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "LowPassFilter.h"
|
||||
|
||||
Synth::Synth(/* args */) {
|
||||
m_lfo = new Oscillator(OscillatorType::Sine, 5.f, VOLUME);
|
||||
add_oscillator();
|
||||
add_oscillator();
|
||||
AddEffect(new ADSR());
|
||||
@@ -69,7 +70,18 @@ void Synth::Trigger(Note input) {
|
||||
trigger_note_on_effects();
|
||||
}
|
||||
|
||||
void Synth::apply_filter_lfo() {
|
||||
float dt = m_lfo->GenerateSample();
|
||||
Filter* filter = (Filter*)m_effects[1];
|
||||
float freq = filter->GetFreq();
|
||||
//todo: check formula
|
||||
//filter->SetParameters(freq + dt * 0.2f, filter->GetRes(), filter->GetPeakGain());
|
||||
}
|
||||
|
||||
void Synth::Process() {
|
||||
//todo: on each sample.
|
||||
//in order to do that, we need to move to per-sample processing
|
||||
apply_filter_lfo();
|
||||
get_note();
|
||||
apply_effects();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user