From bd0ad31f7750c784b8b287fd4376d836e190dc8a Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Sat, 25 Jul 2026 15:28:57 -0400 Subject: [PATCH 1/2] demoddatv: Fix spectrum compilation against current cfft_engine API The spectrum template was not being instantiated by the current build, so stale accesses to cfft_engine::n went unnoticed. Replace direct accesses to the private cfft_engine member with the public size() accessor. This restores spectrum compilation and allows the upcoming VLA cleanup to be built and tested. Signed-off-by: Robin Getz --- plugins/channelrx/demoddatv/leansdr/sdr.h | 24 ++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/channelrx/demoddatv/leansdr/sdr.h b/plugins/channelrx/demoddatv/leansdr/sdr.h index 9ce9cdf5b..f5acd900f 100644 --- a/plugins/channelrx/demoddatv/leansdr/sdr.h +++ b/plugins/channelrx/demoddatv/leansdr/sdr.h @@ -2086,9 +2086,10 @@ struct spectrum : runnable void run() { - while (in.readable() >= fft.n * decim && out.writable() >= 1) + const int fft_size = fft.size(); + while (in.readable() >= fft_size * decim && out.writable() >= 1) { - phase += fft.n * decim; + phase += fft_size * decim; if (phase >= decimation) { @@ -2096,24 +2097,25 @@ struct spectrum : runnable do_spectrum(); } - in.read(fft.n * decim); + in.read(fft_size * decim); } } private: void do_spectrum() { - std::complex data[fft.n]; + const int fft_size = fft.size(); + std::complex data[fft_size]; if (decim == 1) { - memcpy(data, in.rd(), fft.n * sizeof(data[0])); + memcpy(data, in.rd(), fft_size * sizeof(data[0])); } else { std::complex *pin = in.rd(); - for (int i = 0; i < fft.n; ++i, pin += decim) { + for (int i = 0; i < fft_size; ++i, pin += decim) { data[i] = *pin; } } @@ -2121,23 +2123,23 @@ struct spectrum : runnable fft.inplace(data, true); float power[NFFT]; - for (int i = 0; i < fft.n; ++i) { + for (int i = 0; i < fft_size; ++i) { power[i] = (float)data[i].real() * data[i].real() + (float)data[i].imag() * data[i].imag(); } if (!avgpower) { // Initialize with first spectrum - avgpower = new float[fft.n]; - memcpy(avgpower, power, fft.n * sizeof(avgpower[0])); + avgpower = new float[fft_size]; + memcpy(avgpower, power, fft_size * sizeof(avgpower[0])); } // Accumulate and low-pass filter - for (int i = 0; i < fft.n; ++i) + for (int i = 0; i < fft_size; ++i) avgpower[i] = avgpower[i] * (1 - kavg) + power[i] * kavg; // Reuse power[] - for (int i = 0; i < fft.n / 2; ++i) + for (int i = 0; i < fft_size / 2; ++i) { power[i] = 10 * log10f(avgpower[NFFT / 2 + i]); power[NFFT / 2 + i] = 10 * log10f(avgpower[i]); From fef5c27425b55e95427e322720b80f1201e453e4 Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Sat, 25 Jul 2026 15:44:41 -0400 Subject: [PATCH 2/2] demoddatv: Replace spectrum VLA with std::vector Replace the runtime-sized stack array in the spectrum processing path with std::vector to avoid compiler VLA extensions. Although the spectrum template is not instantiated as part of the current SDRangel build, GCC still emits -Wvla warnings while parsing the template definition. This change removes those warnings and keeps the template valid for future use. Use std::copy() and vector::data() when accessing the underlying storage. Part of #2830 Signed-off-by: Robin Getz --- plugins/channelrx/demoddatv/leansdr/sdr.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/channelrx/demoddatv/leansdr/sdr.h b/plugins/channelrx/demoddatv/leansdr/sdr.h index f5acd900f..42f555ee3 100644 --- a/plugins/channelrx/demoddatv/leansdr/sdr.h +++ b/plugins/channelrx/demoddatv/leansdr/sdr.h @@ -19,8 +19,10 @@ #ifndef LEANSDR_SDR_H #define LEANSDR_SDR_H -#include +#include #include +#include +#include #include "leansdr/dsp.h" #include "leansdr/math.h" @@ -2105,11 +2107,11 @@ struct spectrum : runnable void do_spectrum() { const int fft_size = fft.size(); - std::complex data[fft_size]; + std::vector> data(fft_size); if (decim == 1) { - memcpy(data, in.rd(), fft_size * sizeof(data[0])); + std::copy(in.rd(), in.rd() + fft_size, data.begin()); } else { @@ -2120,7 +2122,7 @@ struct spectrum : runnable } } - fft.inplace(data, true); + fft.inplace(data.data(), true); float power[NFFT]; for (int i = 0; i < fft_size; ++i) {