1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 10:05:46 -05:00

DATV Demod: removed VLAs in leansdr. Activated VLA warning at compile time

This commit is contained in:
f4exb 2018-03-01 04:15:46 +01:00
parent 5c055ac2ad
commit d6cc7ef23d
4 changed files with 87 additions and 6 deletions

View File

@ -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

View File

@ -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<TPM> 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;

View File

@ -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 <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_UTIL_INCREMENTALARRAY_H_
#define SDRBASE_UTIL_INCREMENTALARRAY_H_
#include <stdint.h>
namespace leansdr
{
template<typename T>
class IncrementalArray
{
public:
T *m_array;
IncrementalArray();
~IncrementalArray();
void allocate(uint32_t size);
private:
uint32_t m_size;
};
template<typename T>
IncrementalArray<T>::IncrementalArray() :
m_array(0),
m_size(0)
{
}
template<typename T>
IncrementalArray<T>::~IncrementalArray()
{
if (m_array) { delete[] m_array; }
}
template<typename T>
void IncrementalArray<T>::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_ */

View File

@ -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<float> [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<T> *pin = in.rd();
complex<float> data[fft.n];
//complex<float> data[fft.n];
complex<float> *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<complex<float> > m_data;
IncrementalArray<float> 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<complex<T> > m_data;
IncrementalArray<T> 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<T> data[fft.n];
//complex<T> data[fft.n];
complex<T> *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)