Skip to content

Commit

Permalink
feat: complete dynamic filter
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Dec 24, 2023
1 parent 7d747b3 commit af61845
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 9 deletions.
32 changes: 28 additions & 4 deletions source/dsp/iir_filter/dynamic_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@
//
// You should have received a copy of the GNU General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

//
// Created by Zishu Liu on 12/19/23.
//

#include "dynamic_filter.h"

namespace zlIIR {
template<typename FloatType>
void DynamicFilter<FloatType>::prepare(const juce::dsp::ProcessSpec &spec) {
mFilter.prepare(spec);
tFilter.prepare(spec);
mixer.prepare(spec);
tBuffer.setSize(static_cast<int>(spec.numChannels),
static_cast<int>(spec.maximumBlockSize));
}

template<typename FloatType>
void DynamicFilter<FloatType>::process(juce::AudioBuffer<FloatType> &buffer) {
mFilter.process(buffer);
if (dynamicON.load()) {
tBuffer.makeCopyOf(buffer, true);
tFilter.process(tBuffer);
mixer.pushDrySamples(juce::dsp::AudioBlock<FloatType>(buffer));
mixer.mixWetSamples(juce::dsp::AudioBlock<FloatType>(tBuffer));
}
}

template
class DynamicFilter<float>;

template
class DynamicFilter<double>;
}
54 changes: 49 additions & 5 deletions source/dsp/iir_filter/dynamic_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
//
// You should have received a copy of the GNU General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

//
// Created by Zishu Liu on 12/19/23.
//

#ifndef ZLEQUALIZER_IIR_FILTER_H
#define ZLEQUALIZER_IIR_FILTER_H

Expand All @@ -19,8 +15,56 @@
namespace zlIIR {
template<typename FloatType>
class DynamicFilter {
public:
DynamicFilter() = default;

void prepare(const juce::dsp::ProcessSpec &spec);

void process(juce::AudioBuffer<FloatType> &buffer);

inline void setFreq(FloatType x) {
mFilter.setFreq(x);
tFilter.setFreq(x);
}

inline void setGainMain(FloatType x) {
mFilter.setGain(x);
}

inline void setGainTarget(FloatType x) {
tFilter.setGain(x);
}

inline void setQMain(FloatType x) {
mFilter.setQ(x);
}

inline void setQTarget(FloatType x) {
tFilter.setQ(x);
}

inline void setFilterType(FilterType x) {
mFilter.setFilterType(x);
tFilter.setFilterType(x);
}

inline void setOrder(size_t x) {
mFilter.setOrder(x);
tFilter.setOrder(x);
}

inline void setTargetProportion(FloatType x) {
mixer.setWetMixProportion(x);
}

inline void setDynamicON(bool x) {
dynamicON.store(x);
}

private:
SingleFilter<FloatType> filter0, filter1;
SingleFilter<FloatType> mFilter, tFilter;
juce::dsp::DryWetMixer<FloatType> mixer;
juce::AudioBuffer<FloatType> tBuffer;
std::atomic<bool> dynamicON = false;
};
}
Expand Down

0 comments on commit af61845

Please sign in to comment.