Skip to content

Commit

Permalink
implementing the convolver window
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmm committed Feb 22, 2025
1 parent b7bc7ed commit 5bd074d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/contents/ui/Convolver.qml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ Kirigami.ScrollablePage {
} else {
convolverChart.xUnit = "s";
convolverChart.updateData(chartChannel.left ? pluginBackend.chartMagL : pluginBackend.chartMagR);
spectrumLogScale.checked = false;
convolverChart.logarithimicHorizontalAxis = checked;
}
}
},
Expand Down
9 changes: 6 additions & 3 deletions src/contents/ui/EeChart.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ Item {
readonly property real yMinLog: Math.log10(yMin)
readonly property real yMaxLog: Math.log10(yMax)
readonly property color backgroundRectColor: Kirigami.Theme.backgroundColor
property var inputData: []

function updateData(newData) {
inputData = newData;
function updateData(inputData) {
//We do not want the object received as argument to be modified here
let newData = [];
for (let n = 0; n < inputData.length; n++) {
newData.push(inputData[n]);
}
let minX = Number.POSITIVE_INFINITY;
let maxX = Number.NEGATIVE_INFINITY;
let minY = Number.POSITIVE_INFINITY;
Expand Down
1 change: 1 addition & 0 deletions src/contents/ui/PageStreamsEffects.qml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ Kirigami.Page {
logarithimicHorizontalAxis: DB.Manager.spectrum.logarithimicHorizontalAxis
dynamicYScale: DB.Manager.spectrum.dynamicYScale
xUnit: "Hz"
visible: DB.Manager.spectrum.state
Component.onCompleted: {
headerFrameAnimation.start();
}
Expand Down
15 changes: 6 additions & 9 deletions src/spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <span>
#include <string>
#include <tuple>
#include "easyeffects_db_spectrum.h"
#include "lv2_wrapper.hpp"
#include "pipeline_type.hpp"
#include "plugin_base.hpp"
Expand All @@ -42,6 +43,7 @@
Spectrum::Spectrum(const std::string& tag, pw::Manager* pipe_manager, PipelineType pipe_type, QString instance_id)
: PluginBase(tag, "spectrum", tags::plugin_package::Package::ee, instance_id, pipe_manager, pipe_type),
fftw_ready(true) {
bypass = !db::Spectrum::state();
// Precompute the Hann window, which is an expensive operation.
// https://en.wikipedia.org/wiki/Hann_function
for (size_t n = 0; n < n_bands; n++) {
Expand Down Expand Up @@ -76,12 +78,7 @@ Spectrum::Spectrum(const std::string& tag, pw::Manager* pipe_manager, PipelineTy
// lv2_wrapper->bind_key_int<"time_l", "avsync-delay">(settings);
// lv2_wrapper->bind_key_int<"time_r", "avsync-delay">(settings);

// g_signal_connect(settings, "changed::show", G_CALLBACK(+[](GSettings* settings, char* key, gpointer user_data) {
// auto* self = static_cast<Spectrum*>(user_data);

// self->bypass = g_settings_get_boolean(settings, key) == 0;
// }),
// this);
connect(db::Spectrum::self(), &db::Spectrum::stateChanged, [&]() { bypass = !db::Spectrum::state(); });
}

Spectrum::~Spectrum() {
Expand Down Expand Up @@ -128,8 +125,8 @@ void Spectrum::process(std::span<float>& left_in,
std::span<float>& right_in,
std::span<float>& left_out,
std::span<float>& right_out) {
std::copy(left_in.begin(), left_in.end(), left_out.begin());
std::copy(right_in.begin(), right_in.end(), right_out.begin());
std::ranges::copy(left_in, left_out.begin());
std::ranges::copy(right_in, right_out.begin());

if (bypass || !fftw_ready) {
return;
Expand Down Expand Up @@ -259,7 +256,7 @@ auto Spectrum::compute_magnitudes() -> std::tuple<uint, QList<double>> {
fftwf_execute(plan);

for (uint i = 0U; i < output.size(); i++) {
float sqr = complex_output[i][0] * complex_output[i][0] + complex_output[i][1] * complex_output[i][1];
float sqr = (complex_output[i][0] * complex_output[i][0]) + (complex_output[i][1] * complex_output[i][1]);

sqr /= static_cast<float>(output.size() * output.size());

Expand Down

0 comments on commit 5bd074d

Please sign in to comment.