Skip to content

Commit

Permalink
feat: add more filter structures
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Sep 14, 2024
1 parent 44de5e2 commit d5ba50e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
5 changes: 1 addition & 4 deletions source/dsp/chore_attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ namespace zlDSP {
} else if (parameterID == outputGain::ID) {
controllerRef.getGainDSP().setGainDecibels(static_cast<FloatType>(newValue));
} else if (parameterID == filterStructure::ID) {
for (size_t i = 0; i < bandNUM; ++i) {
controllerRef.getFilter(i).setSVFON(static_cast<bool>(newValue));
}
controllerRef.getSoloFilter().setSVFON(static_cast<bool>(newValue));
controllerRef.setFilterStructure(static_cast<filterStructure::FilterStructure>(newValue));
} else if (parameterID == dynLink::ID) {
controllerRef.setDynLink(static_cast<bool>(newValue));
} else if (parameterID == dynHQ::ID) {
Expand Down
32 changes: 30 additions & 2 deletions source/dsp/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ namespace zlDSP {
template<typename FloatType>
Controller<FloatType>::Controller(juce::AudioProcessor &processor)
: processorRef(processor) {
for(size_t i = 0; i < bandNUM; ++i) {
for (size_t i = 0; i < bandNUM; ++i) {
histograms[i].setDecayRate(FloatType(0.99999));
subHistograms[i].setDecayRate(FloatType(0.9995));
}
soloFilter.setSVFON(true);
}

template<typename FloatType>
Expand Down Expand Up @@ -73,6 +74,10 @@ namespace zlDSP {

template<typename FloatType>
void Controller<FloatType>::process(juce::AudioBuffer<FloatType> &buffer) {
if (filterStructure.load() != currentFtilerStructure) {
currentFtilerStructure = filterStructure.load();
updateFilterStructure();
}
juce::AudioBuffer<FloatType> mainBuffer{buffer.getArrayOfWritePointers() + 0, 2, buffer.getNumSamples()};
juce::AudioBuffer<FloatType> sideBuffer{buffer.getArrayOfWritePointers() + 2, 2, buffer.getNumSamples()};
// if no side chain, copy the main buffer into the side buffer
Expand Down Expand Up @@ -187,7 +192,7 @@ namespace zlDSP {
if (filters[i].getDynamicON()) {
if (isHistON[i].load()) {
const auto depThres =
currentThreshold[i].load() + FloatType(40) +
currentThreshold[i].load() + FloatType(40) +
static_cast<FloatType>(threshold::range.snapToLegalValue(
static_cast<float>(-subHistograms[i].getPercentile(FloatType(0.5)))));
filters[i].getCompressor().getComputer().setThreshold(depThres);
Expand Down Expand Up @@ -452,6 +457,29 @@ namespace zlDSP {
}
}

template<typename FloatType>
void Controller<FloatType>::updateFilterStructure() {
switch (currentFtilerStructure) {
case filterStructure::minimum:
case filterStructure::matched:
case filterStructure::mixed: {
for (auto &f: filters) {
f.setSVFON(false);
}
break;
}
case filterStructure::svf: {
for (auto &f: filters) {
f.setSVFON(true);
}
break;
}
case filterStructure::parallel:
case filterStructure::linear: {
}
}
}

template
class Controller<float>;

Expand Down
9 changes: 9 additions & 0 deletions source/dsp/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ namespace zlDSP {

zlPhase::PhaseFlip<FloatType> &getPhaseFlipper() { return phaseFlipper; }

void setFilterStructure(const filterStructure::FilterStructure x) {
filterStructure.store(x);
}

private:
juce::AudioProcessor &processorRef;
std::array<zlFilter::DynamicIIR<FloatType>, bandNUM> filters;
Expand Down Expand Up @@ -168,6 +172,9 @@ namespace zlDSP {

zlPhase::PhaseFlip<FloatType> phaseFlipper;

std::atomic<filterStructure::FilterStructure> filterStructure{filterStructure::minimum};
filterStructure::FilterStructure currentFtilerStructure{filterStructure::minimum};

void processSubBuffer(juce::AudioBuffer<FloatType> &subMainBuffer,
juce::AudioBuffer<FloatType> &subSideBuffer);

Expand All @@ -180,6 +187,8 @@ namespace zlDSP {
void updateTrackersON();

void updateSubBuffer();

void updateFilterStructure();
};
}

Expand Down
6 changes: 5 additions & 1 deletion source/dsp/dsp_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ namespace zlDSP {
auto static constexpr ID = "filter_structure";
auto static constexpr name = "Filter Structure";
inline auto static const choices = juce::StringArray{
"Transposed DF-II", "State Variable"
"Minimum Phase", "State Variable", "Parallel",
"Prototype", "Mixed Phase", "Linear Phase"
};
enum FilterStructure {
minimum, svf, parallel, matched, mixed, linear
};
int static constexpr defaultI = 0;
};
Expand Down
5 changes: 2 additions & 3 deletions source/dsp/filter/iir_filter/single_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ namespace zlFilter {

template<typename FloatType>
void IIR<FloatType>::process(juce::AudioBuffer<FloatType> &buffer, bool isBypassed) {
const auto nextUseSVF = useSVF.load();
if (currentUseSVF != nextUseSVF) {
currentUseSVF = nextUseSVF;
if (currentUseSVF != useSVF.load()) {
currentUseSVF = useSVF.load();
toReset.store(true);
toUpdatePara.store(true);
}
Expand Down

0 comments on commit d5ba50e

Please sign in to comment.