From c67b06fd6541bbcd59de459e82735974cbdb3d88 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 3 Dec 2010 11:46:47 -0500 Subject: usrp: move dsp tuning wrap-around into the dsp utils (allows the dsp handler to get the full value) --- host/lib/usrp/dsp_utils.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'host/lib/usrp/dsp_utils.cpp') diff --git a/host/lib/usrp/dsp_utils.cpp b/host/lib/usrp/dsp_utils.cpp index 2553e4a25..576c4639f 100644 --- a/host/lib/usrp/dsp_utils.cpp +++ b/host/lib/usrp/dsp_utils.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include using namespace uhd; @@ -65,13 +67,16 @@ boost::uint32_t dsp_type1::calc_tx_mux_word(subdev_conn_t subdev_conn){ } boost::uint32_t dsp_type1::calc_cordic_word_and_update( - double &freq, - double codec_rate + double &freq, double codec_rate ){ - UHD_ASSERT_THROW(std::abs(freq) <= codec_rate/2.0); - static const double scale_factor = std::pow(2.0, 32); + //correct for outside of rate (wrap around) + freq = std::fmod(freq, codec_rate); + if (std::abs(freq) > codec_rate/2.0) + freq -= boost::math::sign(freq)*codec_rate; //calculate the freq register word (signed) + UHD_ASSERT_THROW(std::abs(freq) <= codec_rate/2.0); + static const double scale_factor = std::pow(2.0, 32); boost::int32_t freq_word = boost::int32_t(boost::math::round((freq / codec_rate) * scale_factor)); //update the actual frequency -- cgit v1.2.3