From c29adad91e1987da63b11716156b86d237cfda82 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 10 Nov 2011 10:23:05 -0800 Subject: uhd: performance improvement for tx waveforms using integer table lookup --- host/examples/tx_waveforms.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'host/examples') diff --git a/host/examples/tx_waveforms.cpp b/host/examples/tx_waveforms.cpp index 5b17e0595..a182f2d11 100644 --- a/host/examples/tx_waveforms.cpp +++ b/host/examples/tx_waveforms.cpp @@ -75,8 +75,9 @@ public: } } - inline std::complex operator()(const double theta) const{ - return _wave_table[unsigned(theta*wave_table_len)%wave_table_len]; + inline std::complex operator()(size_t &index) const{ + index %= wave_table_len; + return _wave_table[index]; } private: @@ -188,8 +189,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ //pre-compute the waveform values const wave_table_class wave_table(wave_type, ampl); - const double cps = wave_freq/usrp->get_tx_rate(); - double theta = 0; + const size_t step = boost::math::iround(wave_freq/usrp->get_tx_rate() * wave_table_len); + size_t index = 0; //create a transmit streamer //linearly map channels (index0 = channel0, index1 = channel1, ...) @@ -240,12 +241,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ while(not stop_signal_called){ //fill the buffer with the waveform for (size_t n = 0; n < buff.size(); n++){ - buff[n] = wave_table(theta += cps); + buff[n] = wave_table(index); + index += step; } - //bring the theta back into range [0, 1) - theta = std::fmod(theta, 1); - //send the entire contents of the buffer tx_stream->send(buffs, buff.size(), md); -- cgit v1.2.3