From dd782308940e4b206e798eb2f0fa203b6e8c7f07 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 12 Nov 2011 15:45:52 -0800 Subject: convert: made conversion functions into classes so they can keep state --- host/lib/transport/super_recv_packet_handler.hpp | 13 +++++-------- host/lib/transport/super_send_packet_handler.hpp | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) (limited to 'host/lib/transport') diff --git a/host/lib/transport/super_recv_packet_handler.hpp b/host/lib/transport/super_recv_packet_handler.hpp index 57aae96b1..05cad93ea 100644 --- a/host/lib/transport/super_recv_packet_handler.hpp +++ b/host/lib/transport/super_recv_packet_handler.hpp @@ -71,7 +71,6 @@ public: { this->resize(size); set_alignment_failure_threshold(1000); - this->set_scale_factor(1/32767.); } //! Resize the number of transport channels @@ -124,7 +123,8 @@ public: //! Set the conversion routine for all channels void set_converter(const uhd::convert::id_type &id){ _io_buffs.resize(id.num_outputs); - _converter = uhd::convert::get_converter(id); + _converter = uhd::convert::get_converter(id)(); + this->set_scale_factor(1/32767.); //update after setting converter _bytes_per_otw_item = uhd::convert::get_bytes_per_item(id.input_format); _bytes_per_cpu_item = uhd::convert::get_bytes_per_item(id.output_format); } @@ -136,7 +136,7 @@ public: //! Set the scale factor used in float conversion void set_scale_factor(const double scale_factor){ - _scale_factor = scale_factor; + _converter->set_scalar(scale_factor); } /******************************************************************* @@ -207,8 +207,7 @@ private: std::vector _io_buffs; //used in conversion size_t _bytes_per_otw_item; //used in conversion size_t _bytes_per_cpu_item; //used in conversion - uhd::convert::function_type _converter; //used in conversion - double _scale_factor; + uhd::convert::converter::sptr _converter; //used in conversion //! information stored for a received buffer struct per_buffer_info_type{ @@ -523,9 +522,7 @@ private: } //copy-convert the samples from the recv buffer - if (nsamps_to_copy_per_io_buff != 0) _converter( - buff_info.copy_buff, _io_buffs, nsamps_to_copy_per_io_buff, _scale_factor - ); + _converter->conv(buff_info.copy_buff, _io_buffs, nsamps_to_copy_per_io_buff); //update the rx copy buffer to reflect the bytes copied buff_info.copy_buff += bytes_to_copy; diff --git a/host/lib/transport/super_send_packet_handler.hpp b/host/lib/transport/super_send_packet_handler.hpp index c3ffcc861..5ed8e0143 100644 --- a/host/lib/transport/super_send_packet_handler.hpp +++ b/host/lib/transport/super_send_packet_handler.hpp @@ -56,7 +56,6 @@ public: _next_packet_seq(0) { this->resize(size); - this->set_scale_factor(32767.); } //! Resize the number of transport channels @@ -100,7 +99,8 @@ public: //! Set the conversion routine for all channels void set_converter(const uhd::convert::id_type &id){ _io_buffs.resize(id.num_inputs); - _converter = uhd::convert::get_converter(id); + _converter = uhd::convert::get_converter(id)(); + this->set_scale_factor(32767.); //update after setting converter _bytes_per_otw_item = uhd::convert::get_bytes_per_item(id.output_format); _bytes_per_cpu_item = uhd::convert::get_bytes_per_item(id.input_format); } @@ -116,7 +116,7 @@ public: //! Set the scale factor used in float conversion void set_scale_factor(const double scale_factor){ - _scale_factor = scale_factor; + _converter->set_scalar(scale_factor); } /******************************************************************* @@ -202,11 +202,10 @@ private: std::vector _io_buffs; //used in conversion size_t _bytes_per_otw_item; //used in conversion size_t _bytes_per_cpu_item; //used in conversion - uhd::convert::function_type _converter; //used in conversion + uhd::convert::converter::sptr _converter; //used in conversion size_t _max_samples_per_packet; std::vector _zero_buffs; size_t _next_packet_seq; - double _scale_factor; /******************************************************************* * Send a single packet: @@ -239,9 +238,7 @@ private: otw_mem += if_packet_info.num_header_words32; //copy-convert the samples into the send buffer - if (nsamps_per_buff != 0) _converter( - _io_buffs, otw_mem, nsamps_per_buff, _scale_factor - ); + _converter->conv(_io_buffs, otw_mem, nsamps_per_buff); //commit the samples to the zero-copy interface size_t num_bytes_total = (_header_offset_words32+if_packet_info.num_packet_words32)*sizeof(boost::uint32_t); -- cgit v1.2.3