Skip to content

Commit

Permalink
fix(filter attach): use async updater to update side freq/Q
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Nov 21, 2024
1 parent fba1fbf commit 4299288
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmake-includes/Sanitizer.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Enable Sanitizer
# Enable Address Sanitizer
if (DEFINED ENV{ADDRESS_SANITIZER_FLAG})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
add_compile_options("-fsanitize=address")
link_libraries("-fsanitize=address")
message("Enable Address Sanitizer")
endif ()

# Enable Thread Sanitizer
if (DEFINED ENV{THREAD_SANITIZER_FLAG})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
Expand Down
15 changes: 15 additions & 0 deletions source/dsp/chore/chore.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2024 - zsliu98
// This file is part of ZLEqualizer
//
// ZLEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3 as published by the Free Software Foundation.
//
// ZLEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

#ifndef ZLCHORE_HPP
#define ZLCHORE_HPP

#include "para_updater.hpp"

#endif //ZLCHORE_HPP
40 changes: 40 additions & 0 deletions source/dsp/chore/para_updater.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2024 - zsliu98
// This file is part of ZLEqualizer
//
// ZLEqualizer is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3 as published by the Free Software Foundation.
//
// ZLEqualizer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License along with ZLEqualizer. If not, see <https://www.gnu.org/licenses/>.

#ifndef ZLCHORE_PARA_UPDATER_HPP
#define ZLCHORE_PARA_UPDATER_HPP

#include <juce_audio_processors/juce_audio_processors.h>

namespace zlChore {
class ParaUpdater final : private juce::AsyncUpdater {
public:
explicit ParaUpdater(const juce::AudioProcessorValueTreeState &parameter,
const std::string &parameterIdx) {
para = parameter.getParameter(parameterIdx);
}

void update(const float paraValue) {
value.store(paraValue);
triggerAsyncUpdate();
}

private:
juce::RangedAudioParameter *para;
std::atomic<float> value;

void handleAsyncUpdate() override {
para->beginChangeGesture();
para->setValueNotifyingHost(value.load());
para->endChangeGesture();
}
};
}

#endif //ZLCHORE_PARA_UPDATER_HPP
12 changes: 8 additions & 4 deletions source/dsp/filters_attach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ namespace zlDSP {
controllerRef(controller), filtersRef(controller.getFilters()) {
addListeners();
initDefaultValues();
for (size_t i = 0; i < bandNUM; ++i) {
sideFreqUpdater[i] = std::make_unique<zlChore::ParaUpdater>(parameters,
zlDSP::appendSuffix(zlDSP::sideFreq::ID, i));
sideQUpdater[i] = std::make_unique<zlChore::ParaUpdater>(parameters,
zlDSP::appendSuffix(zlDSP::sideQ::ID, i));
}
}

template<typename FloatType>
Expand Down Expand Up @@ -128,10 +134,8 @@ namespace zlDSP {
f.getFilterType(), f.getFreq(), f.getQ());
const auto soloFreq01 = sideFreq::convertTo01(static_cast<float>(soloFreq));
const auto soloQ01 = sideQ::convertTo01(static_cast<float>(soloQ));
const auto paraFreq = parameterRef.getParameter(zlDSP::appendSuffix(sideFreq::ID, idx));
updateParaNotifyHost(paraFreq, soloFreq01);
const auto paraQ = parameterRef.getParameter(zlDSP::appendSuffix(sideQ::ID, idx));
updateParaNotifyHost(paraQ, soloQ01);
sideFreqUpdater[idx]->update(soloFreq01);
sideQUpdater[idx] -> update(soloQ01);
}

template<typename FloatType>
Expand Down
4 changes: 4 additions & 0 deletions source/dsp/filters_attach.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define ZLEQUALIZER_FILTERS_ATTACH_HPP

#include "controller.hpp"
#include "chore/chore.hpp"
#include "../state/state_definitions.hpp"

namespace zlDSP {
Expand Down Expand Up @@ -41,6 +42,9 @@ namespace zlDSP {
juce::AudioProcessorValueTreeState &parameterRef, &parameterNARef;
Controller<FloatType> &controllerRef;
std::array<zlFilter::DynamicIIR<FloatType, Controller<FloatType>::FilterSize>, bandNUM> &filtersRef;
std::array<std::string, bandNUM * 2> sideParaNames;
std::array<std::unique_ptr<zlChore::ParaUpdater>, bandNUM> sideFreqUpdater;
std::array<std::unique_ptr<zlChore::ParaUpdater>, bandNUM> sideQUpdater;

constexpr static std::array IDs{
bypass::ID, fType::ID, slope::ID, freq::ID, gain::ID, Q::ID,
Expand Down

0 comments on commit 4299288

Please sign in to comment.