mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-11-03 13:11:20 -05:00 
			
		
		
		
	DATV Demod: removed VLAs in leansdr. Activated VLA warning at compile time
This commit is contained in:
		
							parent
							
								
									5c055ac2ad
								
							
						
					
					
						commit
						d6cc7ef23d
					
				@ -204,7 +204,7 @@ if (SANITIZE_ADDRESS)
 | 
				
			|||||||
    set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fsanitize=address")
 | 
					    set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -fsanitize=address")
 | 
				
			||||||
endif()
 | 
					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
 | 
					# base libraries
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@
 | 
				
			|||||||
#include "leansdr/convolutional.h"
 | 
					#include "leansdr/convolutional.h"
 | 
				
			||||||
#include "leansdr/sdr.h"
 | 
					#include "leansdr/sdr.h"
 | 
				
			||||||
#include "leansdr/rs.h"
 | 
					#include "leansdr/rs.h"
 | 
				
			||||||
 | 
					#include "leansdr/incrementalarray.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace leansdr
 | 
					namespace leansdr
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -1459,6 +1460,7 @@ private:
 | 
				
			|||||||
        dvb_dec_interface *dec;
 | 
					        dvb_dec_interface *dec;
 | 
				
			||||||
        TCS *map;  // [nsymbols]
 | 
					        TCS *map;  // [nsymbols]
 | 
				
			||||||
    }*syncs;  // [nsyncs]
 | 
					    }*syncs;  // [nsyncs]
 | 
				
			||||||
 | 
					    IncrementalArray<TPM> m_totaldiscr;
 | 
				
			||||||
    int current_sync;
 | 
					    int current_sync;
 | 
				
			||||||
    static const int chunk_size = 128;
 | 
					    static const int chunk_size = 128;
 | 
				
			||||||
    int resync_phase;
 | 
					    int resync_phase;
 | 
				
			||||||
@ -1512,6 +1514,7 @@ public:
 | 
				
			|||||||
        // polarity inversion.  We could reduce nsyncs.
 | 
					        // polarity inversion.  We could reduce nsyncs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        syncs = new sync[nsyncs];
 | 
					        syncs = new sync[nsyncs];
 | 
				
			||||||
 | 
					        m_totaldiscr.allocate(nsyncs);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int s = 0; s < nsyncs; ++s)
 | 
					        for (int s = 0; s < nsyncs; ++s)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@ -1636,7 +1639,8 @@ public:
 | 
				
			|||||||
        while ((long) in.readable() >= nshifts * chunk_size + (nshifts - 1)
 | 
					        while ((long) in.readable() >= nshifts * chunk_size + (nshifts - 1)
 | 
				
			||||||
                && ((long) out.writable() * 8) >= fec->bits_in * chunk_size)
 | 
					                && ((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)
 | 
					            for (int s = 0; s < nsyncs; ++s)
 | 
				
			||||||
                totaldiscr[s] = 0;
 | 
					                totaldiscr[s] = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										64
									
								
								plugins/channelrx/demoddatv/leansdr/incrementalarray.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								plugins/channelrx/demoddatv/leansdr/incrementalarray.h
									
									
									
									
									
										Normal 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_ */
 | 
				
			||||||
@ -3,6 +3,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "leansdr/math.h"
 | 
					#include "leansdr/math.h"
 | 
				
			||||||
#include "leansdr/dsp.h"
 | 
					#include "leansdr/dsp.h"
 | 
				
			||||||
 | 
					#include "leansdr/incrementalarray.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace leansdr
 | 
					namespace leansdr
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -50,6 +51,8 @@ struct auto_notch: runnable
 | 
				
			|||||||
            __slots[s].i = -1;
 | 
					            __slots[s].i = -1;
 | 
				
			||||||
            __slots[s].expj = new complex<float> [fft.n];
 | 
					            __slots[s].expj = new complex<float> [fft.n];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        m_data.allocate(fft.n);
 | 
				
			||||||
 | 
					        m_amp.allocate(fft.n);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void run()
 | 
					    void run()
 | 
				
			||||||
@ -71,7 +74,8 @@ struct auto_notch: runnable
 | 
				
			|||||||
    void detect()
 | 
					    void detect()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        complex<T> *pin = in.rd();
 | 
					        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;
 | 
					        float m0 = 0, m2 = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (unsigned int i = 0; i < fft.n; ++i)
 | 
					        for (unsigned int i = 0; i < fft.n; ++i)
 | 
				
			||||||
@ -95,7 +99,8 @@ struct auto_notch: runnable
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fft.inplace(data, true);
 | 
					        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) {
 | 
					        for (unsigned int i = 0; i < fft.n; ++i) {
 | 
				
			||||||
            amp[i] = hypotf(data[i].re, data[i].im);
 | 
					            amp[i] = hypotf(data[i].re, data[i].im);
 | 
				
			||||||
@ -179,6 +184,8 @@ private:
 | 
				
			|||||||
    int phase;
 | 
					    int phase;
 | 
				
			||||||
    float gain;
 | 
					    float gain;
 | 
				
			||||||
    T agc_rms_setpoint;
 | 
					    T agc_rms_setpoint;
 | 
				
			||||||
 | 
					    IncrementalArray<complex<float> > m_data;
 | 
				
			||||||
 | 
					    IncrementalArray<float> m_amp;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// SIGNAL STRENGTH ESTIMATOR
 | 
					// SIGNAL STRENGTH ESTIMATOR
 | 
				
			||||||
@ -1537,12 +1544,16 @@ struct cnr_fft: runnable
 | 
				
			|||||||
        if (bandwidth > 0.25) {
 | 
					        if (bandwidth > 0.25) {
 | 
				
			||||||
            fail("cnr_fft::cnr_fft", "CNR estimator requires Fsampling > 4x Fsignal");
 | 
					            fail("cnr_fft::cnr_fft", "CNR estimator requires Fsampling > 4x Fsignal");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        m_data.allocate(fft.n);
 | 
				
			||||||
 | 
					        m_power.allocate(fft.n);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    float bandwidth;
 | 
					    float bandwidth;
 | 
				
			||||||
    float *freq_tap, tap_multiplier;
 | 
					    float *freq_tap, tap_multiplier;
 | 
				
			||||||
    int decimation;
 | 
					    int decimation;
 | 
				
			||||||
    float kavg;
 | 
					    float kavg;
 | 
				
			||||||
 | 
					    IncrementalArray<complex<T> > m_data;
 | 
				
			||||||
 | 
					    IncrementalArray<T> m_power;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void run()
 | 
					    void run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -1564,10 +1575,12 @@ private:
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        float center_freq = freq_tap ? *freq_tap * tap_multiplier : 0;
 | 
					        float center_freq = freq_tap ? *freq_tap * tap_multiplier : 0;
 | 
				
			||||||
        int icf = floor(center_freq * fft.n + 0.5);
 | 
					        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]));
 | 
					        memcpy(data, in.rd(), fft.n * sizeof(data[0]));
 | 
				
			||||||
        fft.inplace(data, true);
 | 
					        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)
 | 
					        for (unsigned int i = 0; i < fft.n; ++i)
 | 
				
			||||||
            power[i] = data[i].re * data[i].re + data[i].im * data[i].im;
 | 
					            power[i] = data[i].re * data[i].re + data[i].im * data[i].im;
 | 
				
			||||||
        if (!avgpower)
 | 
					        if (!avgpower)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user