refactor: move around some code

This commit is contained in:
2023-09-10 01:13:25 +04:00
parent de37b814bf
commit d7dd36ccd1
4 changed files with 12 additions and 15 deletions

View File

@@ -22,4 +22,8 @@ struct FilterFactory {
}
return newFilter;
}
static Filter* GetDefaultFilter() {
return new LowPassFilter();
}
};

View File

@@ -15,6 +15,7 @@ void Filter::Trigger() {}
void Filter::Release() {}
float Filter::Process(float in) {
// may move to a compile-time dictionary calculation, if needed
calculate_coefficients();
float out = in * m_a0 + m_z1;
m_z1 = in * m_a1 + m_z2 - m_b1 * out;
@@ -23,10 +24,6 @@ float Filter::Process(float in) {
}
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
for (std::size_t i = 0; i < samples.size(); i++) {
samples[i] = Process(samples[i]);
}

View File

@@ -241,13 +241,8 @@ float Renderer::draw_filter_panel(Synth& synth, FilterGuiState& gui_filter,
gui_filter.is_dropdown_open = !gui_filter.is_dropdown_open;
gui_filter.type = (FilterType)(shape_index);
// APPLY STATE TO REAL SYNTH
if (!filter->IsSameFilterType(gui_filter.type)) {
synth.SetFilter(gui_filter.type);
}
//filter.SetType(ui_osc->waveshape);
synth.SetFilter(gui_filter.type);
}
// if (gui_filter.is_dropdown_open)
// break;
// apply values to real one
// todo: thrid (order) parameter

View File

@@ -3,7 +3,6 @@
#include "Logger.h"
#include "OscillatorType.h"
#include "Settings.h"
#include "LowPassFilter.h"
#include "FilterFactory.h"
Synth::Synth(/* args */) {
@@ -11,7 +10,7 @@ Synth::Synth(/* args */) {
add_oscillator();
add_oscillator();
AddEffect(new ADSR());
AddEffect(new LowPassFilter());
AddEffect(FilterFactory::GetDefaultFilter());
for (size_t i = 0; i < STREAM_BUFFER_SIZE; i++) {
float sample = 0.0f;
m_out_signal.push_back(sample);
@@ -98,7 +97,9 @@ void Synth::AddEffect(Effect* fx) { m_effects.push_back(fx); }
void Synth::SetFilter(FilterType type) {
Filter* oldFilter = this->GetFilter();
Filter* newFilter = FilterFactory::CreateFilter(oldFilter, type);
delete oldFilter;
m_effects[1] = newFilter;
if (!oldFilter->IsSameFilterType(type)) {
Filter* newFilter = FilterFactory::CreateFilter(oldFilter, type);
delete oldFilter;
m_effects[1] = newFilter;
}
}