diff --git a/CMakeLists.txt b/CMakeLists.txt index 96d1b840a..3c1fd2f52 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,7 +204,7 @@ if (SANITIZE_ADDRESS) set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fsanitize=address") endif() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fmax-errors=10 -ffast-math -ftree-vectorize ${EXTRA_FLAGS}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wvla -fmax-errors=10 -ffast-math -ftree-vectorize ${EXTRA_FLAGS}") ############################################################################## # base libraries diff --git a/plugins/channelrx/demoddatv/leansdr/dvb.h b/plugins/channelrx/demoddatv/leansdr/dvb.h index 4f4957445..3a08afe06 100644 --- a/plugins/channelrx/demoddatv/leansdr/dvb.h +++ b/plugins/channelrx/demoddatv/leansdr/dvb.h @@ -7,6 +7,7 @@ #include "leansdr/convolutional.h" #include "leansdr/sdr.h" #include "leansdr/rs.h" +#include "leansdr/incrementalarray.h" namespace leansdr { @@ -1459,6 +1460,7 @@ private: dvb_dec_interface *dec; TCS *map; // [nsymbols] }*syncs; // [nsyncs] + IncrementalArray m_totaldiscr; int current_sync; static const int chunk_size = 128; int resync_phase; @@ -1512,6 +1514,7 @@ public: // polarity inversion. We could reduce nsyncs. syncs = new sync[nsyncs]; + m_totaldiscr.allocate(nsyncs); for (int s = 0; s < nsyncs; ++s) { @@ -1636,7 +1639,8 @@ public: while ((long) in.readable() >= nshifts * chunk_size + (nshifts - 1) && ((long) out.writable() * 8) >= fec->bits_in * chunk_size) { - TPM totaldiscr[nsyncs]; + //TPM totaldiscr[nsyncs]; + TPM *totaldiscr = m_totaldiscr.m_array; for (int s = 0; s < nsyncs; ++s) totaldiscr[s] = 0; diff --git a/plugins/channelrx/demoddatv/leansdr/incrementalarray.h b/plugins/channelrx/demoddatv/leansdr/incrementalarray.h new file mode 100644 index 000000000..ac2c33db5 --- /dev/null +++ b/plugins/channelrx/demoddatv/leansdr/incrementalarray.h @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////////////// +// Copyright (C) 2016 Edouard Griffiths, F4EXB // +// // +// This program is free software; you can redistribute it and/or modify // +// it under the terms of the GNU General Public License as published by // +// the Free Software Foundation as version 3 of the License, or // +// // +// This program 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 General Public License V3 for more details. // +// // +// You should have received a copy of the GNU General Public License // +// along with this program. If not, see . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef SDRBASE_UTIL_INCREMENTALARRAY_H_ +#define SDRBASE_UTIL_INCREMENTALARRAY_H_ + +#include + +namespace leansdr +{ + +template +class IncrementalArray +{ +public: + T *m_array; + + IncrementalArray(); + ~IncrementalArray(); + + void allocate(uint32_t size); + +private: + uint32_t m_size; +}; + +template +IncrementalArray::IncrementalArray() : + m_array(0), + m_size(0) +{ +} + +template +IncrementalArray::~IncrementalArray() +{ + if (m_array) { delete[] m_array; } +} + +template +void IncrementalArray::allocate(uint32_t size) +{ + if (size <= m_size) { return; } + if (m_array) { delete[] m_array; } + m_array = new T[size]; + m_size = size; +} + +} // namespace + +#endif /* SDRBASE_UTIL_INCREMENTALARRAY_H_ */ diff --git a/plugins/channelrx/demoddatv/leansdr/sdr.h b/plugins/channelrx/demoddatv/leansdr/sdr.h index ebd4d9c23..94b35db94 100644 --- a/plugins/channelrx/demoddatv/leansdr/sdr.h +++ b/plugins/channelrx/demoddatv/leansdr/sdr.h @@ -3,6 +3,7 @@ #include "leansdr/math.h" #include "leansdr/dsp.h" +#include "leansdr/incrementalarray.h" namespace leansdr { @@ -50,6 +51,8 @@ struct auto_notch: runnable __slots[s].i = -1; __slots[s].expj = new complex [fft.n]; } + m_data.allocate(fft.n); + m_amp.allocate(fft.n); } void run() @@ -71,7 +74,8 @@ struct auto_notch: runnable void detect() { complex *pin = in.rd(); - complex data[fft.n]; + //complex data[fft.n]; + complex *data = m_data.m_array; float m0 = 0, m2 = 0; for (unsigned int i = 0; i < fft.n; ++i) @@ -95,7 +99,8 @@ struct auto_notch: runnable } fft.inplace(data, true); - float amp[fft.n]; + //float amp[fft.n]; + float *amp = m_amp.m_array; for (unsigned int i = 0; i < fft.n; ++i) { amp[i] = hypotf(data[i].re, data[i].im); @@ -179,6 +184,8 @@ private: int phase; float gain; T agc_rms_setpoint; + IncrementalArray > m_data; + IncrementalArray m_amp; }; // SIGNAL STRENGTH ESTIMATOR @@ -1537,12 +1544,16 @@ struct cnr_fft: runnable if (bandwidth > 0.25) { fail("cnr_fft::cnr_fft", "CNR estimator requires Fsampling > 4x Fsignal"); } + m_data.allocate(fft.n); + m_power.allocate(fft.n); } float bandwidth; float *freq_tap, tap_multiplier; int decimation; float kavg; + IncrementalArray > m_data; + IncrementalArray m_power; void run() { @@ -1564,10 +1575,12 @@ private: { float center_freq = freq_tap ? *freq_tap * tap_multiplier : 0; int icf = floor(center_freq * fft.n + 0.5); - complex data[fft.n]; + //complex data[fft.n]; + complex *data = m_data.m_array; memcpy(data, in.rd(), fft.n * sizeof(data[0])); fft.inplace(data, true); - T power[fft.n]; + //T power[fft.n]; + T *power = m_power.m_array; for (unsigned int i = 0; i < fft.n; ++i) power[i] = data[i].re * data[i].re + data[i].im * data[i].im; if (!avgpower)