Skip to content

Commit

Permalink
fix(fft analyzer): move async update call to update path
Browse files Browse the repository at this point in the history
  • Loading branch information
zsliu98 committed Dec 3, 2024
1 parent c34a908 commit 9e2cde7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 34 deletions.
41 changes: 19 additions & 22 deletions source/dsp/fft_analyzer/conflict_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace zlFFT {
ConflictAnalyzer<FloatType>::ConflictAnalyzer(const size_t fftOrder)
: Thread("conflict_analyzer"),
syncAnalyzer(fftOrder) {
// std::fill(mainDB.begin(), mainDB.end(), -144.f);
// std::fill(refDB.begin(), refDB.end(), -144.f);
syncAnalyzer.setDecayRate(0, 0.985f);
syncAnalyzer.setDecayRate(1, 0.985f);
syncAnalyzer.setON({true, true});
Expand Down Expand Up @@ -62,9 +60,6 @@ namespace zlFFT {
void ConflictAnalyzer<FloatType>::process() {
if (currentIsON) {
syncAnalyzer.process({mainBuffer, refBuffer});
if (!isConflictReady.load()) {
triggerAsyncUpdate();
}
}
}

Expand Down Expand Up @@ -113,25 +108,27 @@ namespace zlFFT {

template<typename FloatType>
void ConflictAnalyzer<FloatType>::updateGradient(juce::ColourGradient &gradient) {
// calculate gradient
gradient.point1 = juce::Point<float>(x1.load(), 0.f);
gradient.point2 = juce::Point<float>(x2.load(), 0.f);
gradient.isRadial = false;
gradient.clearColours();

gradient.addColour(0.0,
gColour.withMultipliedAlpha(juce::jmax(conflictsP.front().load(), 0.f)));
gradient.addColour(1.0,
gColour.withMultipliedAlpha(juce::jmax(conflictsP.back().load(), 0.f)));
for (size_t i = 1; i < conflictsP.size() - 1; ++i) {
if (conflictsP[i + 1] > 0 || conflictsP[i - 1] > 0) {
const auto p = (static_cast<double>(i) + 0.5) / static_cast<double>(conflictsP.size());
const auto rectColour = gColour.withMultipliedAlpha(juce::jmax(conflictsP[i].load(), 0.f));
gradient.addColour(p, rectColour);
if (isConflictReady.load()) {
// calculate gradient
gradient.point1 = juce::Point<float>(x1.load(), 0.f);
gradient.point2 = juce::Point<float>(x2.load(), 0.f);
gradient.isRadial = false;
gradient.clearColours();

gradient.addColour(0.0,
gColour.withMultipliedAlpha(juce::jmax(conflictsP.front().load(), 0.f)));
gradient.addColour(1.0,
gColour.withMultipliedAlpha(juce::jmax(conflictsP.back().load(), 0.f)));
for (size_t i = 1; i < conflictsP.size() - 1; ++i) {
if (conflictsP[i + 1] > 0 || conflictsP[i - 1] > 0) {
const auto p = (static_cast<double>(i) + 0.5) / static_cast<double>(conflictsP.size());
const auto rectColour = gColour.withMultipliedAlpha(juce::jmax(conflictsP[i].load(), 0.f));
gradient.addColour(p, rectColour);
}
}
isConflictReady.store(false);
}

isConflictReady.store(false);
triggerAsyncUpdate();
}

template<typename FloatType>
Expand Down
1 change: 0 additions & 1 deletion source/dsp/fft_analyzer/conflict_analyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ namespace zlFFT {
private:
MultipleFFTAnalyzer<FloatType, 2, pointNum> syncAnalyzer;
juce::AudioBuffer<FloatType> mainBuffer, refBuffer;
// std::array<float, pointNum> mainDB{}, refDB{};
std::atomic<FloatType> strength{.375f}, conflictScale{1.f};
std::atomic<bool> isON{false}, isConflictReady{false}, toReset{false};
bool currentIsON{false};
Expand Down
16 changes: 8 additions & 8 deletions source/dsp/fft_analyzer/pre_post_fft_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ namespace zlFFT {
}
if (currentON) {
fftAnalyzer.process({preBuffer, postBuffer, sideBuffer});
if (!isPathReady.load()) {
triggerAsyncUpdate();
}
}
}

Expand Down Expand Up @@ -122,11 +119,14 @@ namespace zlFFT {
template<typename FloatType>
void PrePostFFTAnalyzer<FloatType>::updatePaths(
juce::Path &prePath_, juce::Path &postPath_, juce::Path &sidePath_, juce::Rectangle<float> bound) {
prePath_.clear();
postPath_.clear();
sidePath_.clear();
fftAnalyzer.createPath({prePath_, postPath_, sidePath_}, bound);
isPathReady.store(false);
if (isPathReady.load()) {
prePath_.clear();
postPath_.clear();
sidePath_.clear();
fftAnalyzer.createPath({prePath_, postPath_, sidePath_}, bound);
isPathReady.store(false);
}
triggerAsyncUpdate();
}

template
Expand Down
2 changes: 0 additions & 2 deletions source/dsp/fft_analyzer/pre_post_fft_analyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ namespace zlFFT {

inline bool getSideON() const { return isSideON.load(); }

bool getPathReady() const { return isPathReady.load(); }

void updatePaths(juce::Path &prePath_, juce::Path &postPath_, juce::Path &sidePath_,
juce::Rectangle<float> bound);

Expand Down
2 changes: 1 addition & 1 deletion source/panel/curve_panel/curve_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace zlPanel {
juce::ignoreUnused(flag);
if (!showMatching.load()) {
const auto &analyzer = controllerRef.getAnalyzer();
if ((analyzer.getPreON() || analyzer.getPostON() || analyzer.getSideON()) && analyzer.getPathReady()) {
if (analyzer.getPreON() || analyzer.getPostON() || analyzer.getSideON()) {
fftPanel.updatePaths();
}
for (const auto &sP: singlePanels) {
Expand Down

0 comments on commit 9e2cde7

Please sign in to comment.