Skip to content

Commit f4276be

Browse files
committed
feat(zlp::controller): add dynamic bypass
1 parent 9ab0344 commit f4276be

3 files changed

Lines changed: 65 additions & 20 deletions

File tree

source/dsp/filter/spec_dynamic/spec_dynamic.hpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace zldsp::filter {
2424
states_.resize(fft_size);
2525
}
2626

27-
template <bool to_add = true>
27+
template <bool to_add = true, bool bypass = false>
2828
void process(FloatType* HWY_RESTRICT side_log_sqr,
2929
FloatType* HWY_RESTRICT dynamic_db,
3030
SpecResponse<FloatType>& response,
@@ -58,14 +58,19 @@ namespace zldsp::filter {
5858
hn::Store(v_state, d, states + (i << 1));
5959
hn::Store(v_y, d, states + (i << 1) + lanes);
6060
// calculate diff
61-
const auto v_diff = hn::Mul(hn::Load(d, diffs + i), v_y);
62-
if constexpr (to_add) {
63-
const auto v_dyn = hn::Load(d, dynamic_db + i);
64-
hn::Store(hn::Add(v_diff, v_dyn), d, dynamic_db + i);
65-
} else {
66-
hn::Store(v_diff, d, dynamic_db + i);
61+
if constexpr (!bypass) {
62+
const auto v_diff = hn::Mul(hn::Load(d, diffs + i), v_y);
63+
if constexpr (to_add) {
64+
const auto v_dyn = hn::Load(d, dynamic_db + i);
65+
hn::Store(hn::Add(v_diff, v_dyn), d, dynamic_db + i);
66+
} else {
67+
hn::Store(v_diff, d, dynamic_db + i);
68+
}
6769
}
6870
}
71+
if constexpr (to_add && bypass) {
72+
std::fill(dynamic_db + i_start, dynamic_db + i_stop, static_cast<FloatType>(0));
73+
}
6974
}
7075

7176
void updateTK(const double threshold, const double knee) {

source/zlp/controller.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// You should have received a copy of the GNU Affero General Public License along with ZLSpectrumEqualizer. If not, see <https://www.gnu.org/licenses/>.
99

1010
#include "controller.hpp"
11+
#include "../dsp/splitter/inplace_ms_splitter.hpp"
1112

1213
namespace zlp {
1314
namespace {
@@ -315,14 +316,23 @@ namespace zlp {
315316
// process each dynamic band
316317
{
317318
const auto band = data.dynamic_bands[0];
318-
spec_dynamic_[band].process<false>(side_ptr, dynamic_ptr,
319-
spec_response_[band], spec_follower_[band]);
320-
std::fill(dynamic_ptr + spec_response_[band].getDiffEndIdx(), dynamic_ptr + end_idx, 0.f);
319+
if (dynamic_bypass_[band]) {
320+
spec_dynamic_[band].process<false, true>(side_ptr, dynamic_ptr,
321+
spec_response_[band], spec_follower_[band]);
322+
} else {
323+
spec_dynamic_[band].process<false, false>(side_ptr, dynamic_ptr,
324+
spec_response_[band], spec_follower_[band]);
325+
}
321326
}
322327
for (size_t i = 1; i < data.dynamic_bands.size(); ++i) {
323328
const auto band = data.dynamic_bands[i];
324-
spec_dynamic_[band].process<true>(side_ptr, dynamic_ptr,
325-
spec_response_[band], spec_follower_[band]);
329+
if (dynamic_bypass_[band]) {
330+
spec_dynamic_[band].process<true, true>(side_ptr, dynamic_ptr,
331+
spec_response_[band], spec_follower_[band]);
332+
} else {
333+
spec_dynamic_[band].process<true, false>(side_ptr, dynamic_ptr,
334+
spec_response_[band], spec_follower_[band]);
335+
}
326336
}
327337
// convert dynamic response from db to linear
328338
auto* HWY_RESTRICT static_ptr = data.static_response.data();

source/zlp/controller.hpp

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "../dsp/filter/spec_dynamic/spec_follower.hpp"
1919
#include "../dsp/filter/spec_dynamic/spec_dynamic.hpp"
2020
#include "../dsp/filter/spec_dynamic/spec_smoother.hpp"
21-
#include "../dsp/splitter/inplace_ms_splitter.hpp"
2221
#include "../dsp/fft/zldsp_fft_include.hpp"
2322

2423
#include "../chore/thread/notifier.hpp"
@@ -50,11 +49,33 @@ namespace zlp {
5049
void processMainImpl();
5150

5251
void setFilterStatus(const size_t idx, const FilterStatus filter_status) {
53-
filter_status_[idx].store(filter_status, std::memory_order::relaxed);
52+
a_filter_status_[idx].store(filter_status, std::memory_order::relaxed);
5453
to_update_status_.signal();
5554
to_update_.signal();
5655
}
5756

57+
void setLRMS(const size_t idx, const FilterStereo filter_stereo) {
58+
a_lrms_[idx].store(filter_stereo, std::memory_order::relaxed);
59+
to_update_lrms_.signal();
60+
to_update_.signal();
61+
}
62+
63+
auto& getEmptyFilters() {
64+
return emptys_;
65+
}
66+
67+
auto& getEmptyUpdateFlags() {
68+
return empty_update_flags_;
69+
}
70+
71+
auto& getUpdateFlag() {
72+
return to_update_;
73+
}
74+
75+
bool isSideRequired() const {
76+
return side_status_ != SideStatus::kNotRequired;
77+
}
78+
5879
private:
5980
enum class SideStatus {
6081
kNotRequired, kLR, kMS, kLRMS
@@ -80,14 +101,27 @@ namespace zlp {
80101
juce::AudioProcessor& p_ref_;
81102
zlchore::thread::Notifier to_update_{false};
82103
// filter status
83-
std::array<std::atomic<FilterStatus>, kBandNum> filter_status_{};
84-
std::array<FilterStatus, kBandNum> c_filter_status_{};
104+
std::array<std::atomic<FilterStatus>, kBandNum> a_filter_status_{};
105+
std::array<FilterStatus, kBandNum> filter_status_{};
85106
std::vector<size_t> not_off_total_{};
86107
zlchore::thread::Notifier to_update_status_{false};
108+
// filter l/r/m/s
109+
std::array<std::atomic<FilterStereo>, kBandNum> a_lrms_{};
110+
std::array<FilterStereo, kBandNum> lrms_{};
111+
zlchore::thread::Notifier to_update_lrms_{false};
87112
// empty filters for holding atomic parameters
88113
std::array<zldsp::filter::Empty, kBandNum> emptys_{};
89114
std::array<zlchore::thread::Notifier, kBandNum> empty_update_flags_{};
90115
std::array<zldsp::filter::FilterParameters, kBandNum> filter_paras_{};
116+
// filter dynamic flags
117+
std::array<std::atomic<bool>, kBandNum> a_dynamic_on_{};
118+
std::array<std::atomic<bool>, kBandNum> a_dynamic_bypass_{};
119+
std::array<bool, kBandNum> dynamic_on_{};
120+
std::array<bool, kBandNum> dynamic_bypass_{};
121+
zlchore::thread::Notifier to_update_dynamic_{false};
122+
123+
// filters for calculating prototype response and biquad response
124+
std::array<zldsp::filter::Ideal<float, kFilterSize>, kBandNum> ideals_{};
91125
// spectrum processing
92126
std::array<zldsp::filter::SpecResponse<float>, kBandNum> spec_response_
93127
= make_array_of<zldsp::filter::SpecResponse<float>, kBandNum>();
@@ -120,10 +154,6 @@ namespace zlp {
120154

121155
SideStatus side_status_{SideStatus::kNotRequired};
122156

123-
bool isSideRequired() const {
124-
return side_status_ != SideStatus::kNotRequired;
125-
}
126-
127157
void processFrame(bool is_bypass);
128158

129159
void processSide();

0 commit comments

Comments
 (0)