Sample copy FFT ready updated

master
Lucjan Bryndza 2013-05-26 17:16:28 +02:00
rodzic ffcd138c45
commit 89e1dcb46f
3 zmienionych plików z 34 dodań i 8 usunięć

Wyświetl plik

@ -213,6 +213,11 @@ public:
{ {
return m_tx_codec; return m_tx_codec;
} }
//Set FFT interval
void set_fft_interval( unsigned short timeout )
{
m_spectrum_timeout = timeout;
}
//Lock and unlock device //Lock and unlock device
virtual void lock( bool lock ) = 0; virtual void lock( bool lock ) = 0;
private: private:
@ -229,11 +234,13 @@ protected:
m_mode = mode::off; m_mode = mode::off;
} }
private: private:
tx_codec* m_tx_codec { nullptr }; /* Transmit codec ptr */ tx_codec* m_tx_codec { nullptr }; /* Transmit codec ptr */
std::array<rx_codec*, MAX_CODECS> m_rx_codecs {{}}; /* RX codecs array */ std::array<rx_codec*, MAX_CODECS> m_rx_codecs {{}}; /* RX codecs array */
spectrum_calculator m_spectrum; /* Spectrum calculator object */ spectrum_calculator m_spectrum; /* Spectrum calculator object */
const event_handler_t m_evt_callback; /* Event handler object */ unsigned m_spectrum_tmr {}; /* Spectrum time */
mode m_mode { mode::off }; /* Current device mode */ unsigned short m_spectrum_timeout { 250 }; /* Spectrum timeout */
const event_handler_t m_evt_callback; /* Event handler object */
mode m_mode { mode::off }; /* Current device mode */
}; };

Wyświetl plik

@ -42,11 +42,22 @@ public:
spectrum_calculator() spectrum_calculator()
{} {}
public: public:
//Copy sample buffer bool copy_samples( const pow_t* samples, size_t len )
void copy_samples( const pow_t* samples )
{ {
std::memcpy( m_real, samples, sizeof(pow_t) * WIDTH ); size_t cpyn = WIDTH - m_sample_buf_cnt;
if( len < cpyn ) cpyn = len;
std::memcpy( &m_real[m_sample_buf_cnt], samples, sizeof(pow_t) * cpyn );
m_sample_buf_cnt += cpyn;
m_energy_calculated = false; m_energy_calculated = false;
if( m_sample_buf_cnt >= WIDTH )
{
m_sample_buf_cnt = 0;
return true;
}
else
{
return false;
}
} }
//Get buffer samples and calculate it //Get buffer samples and calculate it
const pow_t& operator[]( size_t idx ) const pow_t& operator[]( size_t idx )
@ -104,6 +115,7 @@ private:
bool m_energy_calculated { false }; //Energy is calculated bool m_energy_calculated { false }; //Energy is calculated
scale m_scale { scale::log }; //Current scale scale m_scale { scale::log }; //Current scale
pow_t m_factor { std::numeric_limits<pow_t>::max() }; pow_t m_factor { std::numeric_limits<pow_t>::max() };
short m_sample_buf_cnt {}; //Sample buffer counter
}; };
/*----------------------------------------------------------*/ /*----------------------------------------------------------*/

Wyświetl plik

@ -7,7 +7,6 @@
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
#include "codec/trx_device_base.hpp" #include "codec/trx_device_base.hpp"
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
//Namespace def //Namespace def
namespace ham { namespace ham {
@ -74,6 +73,14 @@ void trx_device_base::adc_process( const sample_type *buf, size_t len )
if( v != nullptr ) if( v != nullptr )
(*v)( buf, len ); (*v)( buf, len );
} }
//Calculate the tout sample
m_spectrum_tmr += (1000*len)/get_rx_sample_rate();
if( m_spectrum_tmr >= m_spectrum_timeout )
{
//True if all samples completed
if( m_spectrum.copy_samples( buf, len ) )
m_spectrum_tmr = 0;
}
} }
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
//DAC vector func return true if finished //DAC vector func return true if finished