Skip to content

Commit

Permalink
fix(sum panel): use empty filter to update dynamic gain/Q
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Sep 18, 2024
1 parent 6a477ba commit 23f41b8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 61 deletions.
20 changes: 12 additions & 8 deletions source/dsp/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace zlDSP {
void Controller<FloatType>::processDynamic(juce::AudioBuffer<FloatType> &subMainBuffer,
juce::AudioBuffer<FloatType> &subSideBuffer) {
autoGain.processPre(subMainBuffer);
// set threshold
// set auto threshold
for (size_t i = 0; i < bandNUM; ++i) {
if (filters[i].getDynamicON()) {
if (isHistON[i].load()) {
Expand Down Expand Up @@ -297,13 +297,17 @@ namespace zlDSP {
msMainSplitter.combine(subMainBuffer);
}
for (size_t i = 0; i < bandNUM; ++i) {
if (filters[i].getDynamicON() && isHistON[i].load()) {
auto &compressor = filters[i].getCompressor();
const auto diff = compressor.getBaseLine() - compressor.getTracker().getMomentaryLoudness();
if (diff <= 100) {
const auto histIdx = juce::jlimit(0, 79, juce::roundToInt(diff));
histograms[i].push(static_cast<size_t>(histIdx));
subHistograms[i].push(static_cast<size_t>(histIdx));
if (filters[i].getDynamicON() ) {
mainFilters[i].setGain(filters[i].getMainFilter().getGain());
mainFilters[i].setQ(filters[i].getMainFilter().getQ());
if (isHistON[i].load()) {
auto &compressor = filters[i].getCompressor();
const auto diff = compressor.getBaseLine() - compressor.getTracker().getMomentaryLoudness();
if (diff <= 100) {
const auto histIdx = juce::jlimit(0, 79, juce::roundToInt(diff));
histograms[i].push(static_cast<size_t>(histIdx));
subHistograms[i].push(static_cast<size_t>(histIdx));
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions source/dsp/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ namespace zlDSP {

inline zlFilter::DynamicIIR<FloatType> &getFilter(const size_t idx) { return filters[idx]; }

inline zlFilter::Empty<FloatType> &getMainFilter(const size_t idx) { return mainFilters[idx]; }

inline std::array<zlFilter::DynamicIIR<FloatType>, bandNUM> &getFilters() { return filters; }

void setFilterLRs(lrType::lrTypes x, size_t idx);
Expand Down Expand Up @@ -126,6 +128,7 @@ namespace zlDSP {
private:
juce::AudioProcessor &processorRef;
std::array<zlFilter::DynamicIIR<FloatType>, bandNUM> filters;
std::array<zlFilter::Empty<FloatType>, bandNUM> mainFilters;

std::array<std::atomic<lrType::lrTypes>, bandNUM> filterLRs;
zlSplitter::LRSplitter<FloatType> lrMainSplitter, lrSideSplitter;
Expand Down
54 changes: 24 additions & 30 deletions source/dsp/filters_attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,44 +145,37 @@ namespace zlDSP {
if (parameterID.startsWith(bypass::ID)) {
filtersRef[idx].setBypass(static_cast<bool>(value));
} else if (parameterID.startsWith(fType::ID)) {
filtersRef[idx].getBaseFilter().setFilterType(static_cast<zlFilter::FilterType>(value));
filtersRef[idx].getMainFilter().setFilterType(static_cast<zlFilter::FilterType>(value));
if (filtersRef[idx].getDynamicON()) {
filtersRef[idx].getTargetFilter().setFilterType(static_cast<zlFilter::FilterType>(value));
}
const auto fType = static_cast<zlFilter::FilterType>(value);
filtersRef[idx].getBaseFilter().setFilterType(fType);
filtersRef[idx].getMainFilter().setFilterType(fType);
filtersRef[idx].getTargetFilter().setFilterType(fType);
controllerRef.getMainFilter(idx).setFilterType(fType);
} else if (parameterID.startsWith(slope::ID)) {
filtersRef[idx].getBaseFilter().setOrder(slope::orderArray[static_cast<size_t>(value)]);
filtersRef[idx].getMainFilter().setOrder(slope::orderArray[static_cast<size_t>(value)]);
if (filtersRef[idx].getDynamicON()) {
filtersRef[idx].getTargetFilter().setOrder(slope::orderArray[static_cast<size_t>(value)]);
}
const auto newOrder = slope::orderArray[static_cast<size_t>(value)];
filtersRef[idx].getBaseFilter().setOrder(newOrder);
filtersRef[idx].getMainFilter().setOrder(newOrder);
filtersRef[idx].getTargetFilter().setOrder(newOrder);
controllerRef.getMainFilter(idx).setOrder(newOrder);
} else if (parameterID.startsWith(freq::ID)) {
filtersRef[idx].getBaseFilter().setFreq(value);
filtersRef[idx].getMainFilter().setFreq(value);
if (filtersRef[idx].getDynamicON()) {
filtersRef[idx].getTargetFilter().setFreq(value);
if (sDynLink[idx].load()) {
updateSideFQ(idx);
}
filtersRef[idx].getTargetFilter().setFreq(value);
controllerRef.getMainFilter(idx).setFreq(value);
if (sDynLink[idx].load()) {
updateSideFQ(idx);
}
} else if (parameterID.startsWith(gain::ID)) {
value *= static_cast<FloatType>(scale::formatV(parameterRef.getRawParameterValue(scale::ID)->load()));
value = gain::range.snapToLegalValue(static_cast<float>(value));
if (filtersRef[idx].getDynamicON()) {
filtersRef[idx].getBaseFilter().setGain(value);
} else {
filtersRef[idx].getBaseFilter().setGain(value);
filtersRef[idx].getMainFilter().setGain(value);
}
filtersRef[idx].getBaseFilter().setGain(value);
filtersRef[idx].getMainFilter().setGain(value);
controllerRef.getMainFilter(idx).setGain(value);
} else if (parameterID.startsWith(Q::ID)) {
if (filtersRef[idx].getDynamicON()) {
filtersRef[idx].getBaseFilter().setQ(value);
if (sDynLink[idx].load()) {
updateSideFQ(idx);
}
} else {
filtersRef[idx].getBaseFilter().setQ(value);
filtersRef[idx].getMainFilter().setQ(value);
filtersRef[idx].getBaseFilter().setQ(value);
filtersRef[idx].getMainFilter().setQ(value);
controllerRef.getMainFilter(idx).setQ(value);
if (sDynLink[idx].load()) {
updateSideFQ(idx);
}
} else if (parameterID.startsWith(lrType::ID)) {
controllerRef.setFilterLRs(static_cast<lrType::lrTypes>(value), idx);
Expand All @@ -196,7 +189,8 @@ namespace zlDSP {
const auto thresholdV = static_cast<float>(
-hist.getPercentile(FloatType(0.5)) + controllerRef.getThreshold(idx) + FloatType(40));
const auto kneeV = static_cast<float>(
hist.getPercentile(FloatType(0.95)) - hist.getPercentile(FloatType(0.05))) / 120.f;
hist.getPercentile(FloatType(0.95)) - hist.getPercentile(FloatType(0.05))
) / 120.f;
const std::array dynamicLearnValues{
threshold::convertTo01(threshold::range.snapToLegalValue(thresholdV)),
kneeW::convertTo01(kneeW::range.snapToLegalValue(kneeV))
Expand Down
40 changes: 19 additions & 21 deletions source/panel/curve_panel/sum_panel/sum_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ namespace zlPanel {
}
for (size_t i = 0; i < zlDSP::bandNUM; ++i) {
for (const auto &idx: changeIDs) {
parametersRef.addParameterListener(zlDSP::appendSuffix(idx, i), this);
const auto paraID = zlDSP::appendSuffix(idx, i);
parameterChanged(paraID, parametersRef.getRawParameterValue(paraID)->load());
parametersRef.addParameterListener(paraID, this);
}
}
}
Expand Down Expand Up @@ -72,14 +74,9 @@ namespace zlPanel {
void SumPanel::run() {
juce::ScopedNoDenormals noDenormals;
std::array<bool, 5> useLRMS{false, false, false, false, false};
constexpr std::array<zlDSP::lrType::lrTypes, 5> lrTypes{
zlDSP::lrType::stereo,
zlDSP::lrType::left, zlDSP::lrType::right,
zlDSP::lrType::mid, zlDSP::lrType::side
};
for (size_t i = 0; i < zlDSP::bandNUM; ++i) {
const auto idx = static_cast<size_t>(c.getFilterLRs(i));
if (!c.getFilter(i).getBypass()) {
const auto idx = static_cast<size_t>(lrTypes[i].load());
if (!isBypassed[i].load()) {
useLRMS[idx] = true;
}
}
Expand All @@ -92,11 +89,11 @@ namespace zlPanel {

std::fill(dBs.begin(), dBs.end(), 0.0);
for (size_t i = 0; i < zlState::bandNUM; i++) {
auto &filter{c.getFilter(i)};
if (c.getFilterLRs(i) == lrTypes[j] && !filter.getBypass()) {
if (filter.getDynamicON()) {
mMainFilters[i].setGain(filter.getMainFilter().getGain());
mMainFilters[i].setQ(filter.getMainFilter().getQ());
auto &filter{c.getMainFilter(i)};
if (lrTypes[i].load() == static_cast<zlDSP::lrType::lrTypes>(j) && !isBypassed[i].load()) {
if (filter.exchangeParaOutdated(false)) {
mMainFilters[i].setGain(filter.getGain());
mMainFilters[i].setQ(filter.getQ());
mMainFilters[i].updateMagnidue(ws);
mMainFilters[i].addDBs(dBs);
} else {
Expand All @@ -106,8 +103,8 @@ namespace zlPanel {
}

const juce::Rectangle<float> bound{
xx.load(), yy.load() + uiBase.getFontSize(),
width.load(), height.load() - 2 * uiBase.getFontSize()
atomicBound.getX(), atomicBound.getY() + uiBase.getFontSize(),
atomicBound.getWidth(), atomicBound.getHeight() - 2 * uiBase.getFontSize()
};

drawCurve(paths[j], dBs, maximumDB.load(), bound, false, true);
Expand All @@ -119,16 +116,17 @@ namespace zlPanel {
}

void SumPanel::parameterChanged(const juce::String &parameterID, float newValue) {
juce::ignoreUnused(parameterID, newValue);
const auto idx = static_cast<size_t>(parameterID.getTrailingIntValue());
if (parameterID.startsWith(zlDSP::bypass::ID)) {
isBypassed[idx].store(static_cast<bool>(newValue));
} else if (parameterID.startsWith(zlDSP::lrType::ID)) {
lrTypes[idx].store(static_cast<zlDSP::lrType::lrTypes>(newValue));
}
toRepaint.store(true);
}

void SumPanel::resized() {
const auto bound = getLocalBounds().toFloat();
xx.store(bound.getX());
yy.store(bound.getY());
width.store(bound.getWidth());
height.store(bound.getHeight());
atomicBound.update(getLocalBounds().toFloat());
toRepaint.store(true);
}
} // zlPanel
7 changes: 5 additions & 2 deletions source/panel/curve_panel/sum_panel/sum_panel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,18 @@ namespace zlPanel {
juce::AudioProcessorValueTreeState &parametersRef;
zlInterface::UIBase &uiBase;
zlDSP::Controller<double> &c;
std::array<zlFilter::Ideal<double, 16>, 16> &mBaseFilters, &mMainFilters;
std::array<zlFilter::Ideal<double, 16>, zlState::bandNUM> &mBaseFilters, &mMainFilters;
std::atomic<float> maximumDB;
std::vector<double> dBs{};
std::atomic<float> xx{-100.f}, yy{-100.f}, width{.1f}, height{.1f};
AtomicBound atomicBound;

static constexpr std::array changeIDs{
zlDSP::bypass::ID, zlDSP::lrType::ID
};

std::array<std::atomic<bool>, zlState::bandNUM> isBypassed{};
std::array<std::atomic<zlDSP::lrType::lrTypes>, zlState::bandNUM> lrTypes;

std::atomic<bool> toRepaint{false};

void parameterChanged(const juce::String &parameterID, float newValue) override;
Expand Down

0 comments on commit 23f41b8

Please sign in to comment.