mirror of
				https://github.com/gnss-sdr/gnss-sdr
				synced 2025-10-31 15:23:04 +00:00 
			
		
		
		
	Adding a resampler for cbytes and cshorts
This commit is contained in:
		| @@ -25,6 +25,7 @@ include_directories( | |||||||
|      ${GLOG_INCLUDE_DIRS} |      ${GLOG_INCLUDE_DIRS} | ||||||
|      ${GFlags_INCLUDE_DIRS} |      ${GFlags_INCLUDE_DIRS} | ||||||
|      ${GNURADIO_RUNTIME_INCLUDE_DIRS} |      ${GNURADIO_RUNTIME_INCLUDE_DIRS} | ||||||
|  |      ${VOLK_INCLUDE_DIRS} | ||||||
| ) | ) | ||||||
|  |  | ||||||
| file(GLOB RESAMPLER_ADAPTER_HEADERS "*.h") | file(GLOB RESAMPLER_ADAPTER_HEADERS "*.h") | ||||||
|   | |||||||
| @@ -32,8 +32,10 @@ | |||||||
| #include "direct_resampler_conditioner.h" | #include "direct_resampler_conditioner.h" | ||||||
| #include <glog/logging.h> | #include <glog/logging.h> | ||||||
| #include <gnuradio/blocks/file_sink.h> | #include <gnuradio/blocks/file_sink.h> | ||||||
|  | #include <volk/volk.h> | ||||||
| #include "direct_resampler_conditioner_cc.h" | #include "direct_resampler_conditioner_cc.h" | ||||||
| #include "direct_resampler_conditioner_ss.h" | #include "direct_resampler_conditioner_ss.h" | ||||||
|  | #include "direct_resampler_conditioner_bb.h" | ||||||
| #include "configuration_interface.h" | #include "configuration_interface.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -56,19 +58,29 @@ DirectResamplerConditioner::DirectResamplerConditioner( | |||||||
|     if (item_type_.compare("gr_complex") == 0) |     if (item_type_.compare("gr_complex") == 0) | ||||||
|         { |         { | ||||||
|             item_size_ = sizeof(gr_complex); |             item_size_ = sizeof(gr_complex); | ||||||
|             resampler_ = direct_resampler_make_conditioner_cc(sample_freq_in_, |             resampler_ = direct_resampler_make_conditioner_cc(sample_freq_in_, sample_freq_out_); | ||||||
|                     sample_freq_out_); |  | ||||||
|             DLOG(INFO) << "sample_freq_in " << sample_freq_in_; |             DLOG(INFO) << "sample_freq_in " << sample_freq_in_; | ||||||
|             DLOG(INFO) << "sample_freq_out" << sample_freq_out_; |             DLOG(INFO) << "sample_freq_out" << sample_freq_out_; | ||||||
|             DLOG(INFO) << "Item size " << item_size_; |             DLOG(INFO) << "Item size " << item_size_; | ||||||
|             DLOG(INFO) << "resampler(" << resampler_->unique_id() << ")"; |             DLOG(INFO) << "resampler(" << resampler_->unique_id() << ")"; | ||||||
|  |  | ||||||
|         } |         } | ||||||
|     else if (item_type_.compare("short") == 0) |     else if (item_type_.compare("cshort") == 0) | ||||||
|         { |         { | ||||||
|             item_size_ = sizeof(short); |             item_size_ = sizeof(lv_16sc_t); | ||||||
|             resampler_ = direct_resampler_make_conditioner_ss(sample_freq_in_, |             resampler_ = direct_resampler_make_conditioner_ss(sample_freq_in_, sample_freq_out_); | ||||||
|                     sample_freq_out_); |             DLOG(INFO) << "sample_freq_in " << sample_freq_in_; | ||||||
|  |             DLOG(INFO) << "sample_freq_out" << sample_freq_out_; | ||||||
|  |             DLOG(INFO) << "Item size " << item_size_; | ||||||
|  |             DLOG(INFO) << "resampler(" << resampler_->unique_id() << ")"; | ||||||
|  |         } | ||||||
|  |     else if (item_type_.compare("cbyte") == 0) | ||||||
|  |         { | ||||||
|  |             item_size_ = sizeof(lv_8sc_t); | ||||||
|  |             resampler_ = direct_resampler_make_conditioner_bb(sample_freq_in_, sample_freq_out_); | ||||||
|  |             DLOG(INFO) << "sample_freq_in " << sample_freq_in_; | ||||||
|  |             DLOG(INFO) << "sample_freq_out" << sample_freq_out_; | ||||||
|  |             DLOG(INFO) << "Item size " << item_size_; | ||||||
|  |             DLOG(INFO) << "resampler(" << resampler_->unique_id() << ")"; | ||||||
|         } |         } | ||||||
|     else |     else | ||||||
|         { |         { | ||||||
|   | |||||||
| @@ -20,6 +20,7 @@ | |||||||
| set(RESAMPLER_GR_BLOCKS_SOURCES  | set(RESAMPLER_GR_BLOCKS_SOURCES  | ||||||
|      direct_resampler_conditioner_cc.cc |      direct_resampler_conditioner_cc.cc | ||||||
|      direct_resampler_conditioner_ss.cc |      direct_resampler_conditioner_ss.cc | ||||||
|  |      direct_resampler_conditioner_bb.cc | ||||||
| ) | ) | ||||||
|  |  | ||||||
| include_directories( | include_directories( | ||||||
| @@ -27,6 +28,7 @@ include_directories( | |||||||
|      ${GLOG_INCLUDE_DIRS} |      ${GLOG_INCLUDE_DIRS} | ||||||
|      ${GFlags_INCLUDE_DIRS} |      ${GFlags_INCLUDE_DIRS} | ||||||
|      ${GNURADIO_RUNTIME_INCLUDE_DIRS} |      ${GNURADIO_RUNTIME_INCLUDE_DIRS} | ||||||
|  |      ${VOLK_INCLUDE_DIRS} | ||||||
| ) | ) | ||||||
|  |  | ||||||
| file(GLOB RESAMPLER_GR_BLOCKS_HEADERS "*.h") | file(GLOB RESAMPLER_GR_BLOCKS_HEADERS "*.h") | ||||||
|   | |||||||
| @@ -0,0 +1,139 @@ | |||||||
|  | /*! | ||||||
|  |  * \file direct_resampler_conditioner_bb.cc | ||||||
|  |  * \brief Nearest neighborhood resampler with std::complex<signed char> | ||||||
|  |  * input and std::complex<signed char> output | ||||||
|  |  * \author Luis Esteve, 2011. luis(at)epsilon-formacion.com | ||||||
|  |  * | ||||||
|  |  * Detailed description of the file here if needed. | ||||||
|  |  * | ||||||
|  |  * ------------------------------------------------------------------------- | ||||||
|  |  * | ||||||
|  |  * Copyright (C) 2010-2015  (see AUTHORS file for a list of contributors) | ||||||
|  |  * | ||||||
|  |  * GNSS-SDR is a software defined Global Navigation | ||||||
|  |  *          Satellite Systems receiver | ||||||
|  |  * | ||||||
|  |  * This file is part of GNSS-SDR. | ||||||
|  |  * | ||||||
|  |  * GNSS-SDR 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, either version 3 of the License, or | ||||||
|  |  * (at your option) any later version. | ||||||
|  |  * | ||||||
|  |  * GNSS-SDR 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 for more details. | ||||||
|  |  * | ||||||
|  |  * You should have received a copy of the GNU General Public License | ||||||
|  |  * along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>. | ||||||
|  |  * | ||||||
|  |  * ------------------------------------------------------------------------- | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #include "direct_resampler_conditioner_bb.h" | ||||||
|  | #include <algorithm> | ||||||
|  | #include <iostream> | ||||||
|  | #include <gnuradio/io_signature.h> | ||||||
|  | #include <glog/logging.h> | ||||||
|  | #include <volk/volk.h> | ||||||
|  |  | ||||||
|  | using google::LogMessage; | ||||||
|  |  | ||||||
|  | direct_resampler_conditioner_bb_sptr direct_resampler_make_conditioner_bb( | ||||||
|  |         double sample_freq_in, double sample_freq_out) | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     return direct_resampler_conditioner_bb_sptr( | ||||||
|  |             new direct_resampler_conditioner_bb(sample_freq_in, | ||||||
|  |                     sample_freq_out)); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | direct_resampler_conditioner_bb::direct_resampler_conditioner_bb( | ||||||
|  |         double sample_freq_in, double sample_freq_out) : | ||||||
|  |     gr::block("direct_resampler_make_conditioner_bb", gr::io_signature::make(1, | ||||||
|  |             1, sizeof(lv_8sc_t)), gr::io_signature::make(1, 1, sizeof(lv_8sc_t))), | ||||||
|  |             d_sample_freq_in(sample_freq_in), d_sample_freq_out( | ||||||
|  |                     sample_freq_out), d_phase(0), d_lphase(0), d_history(1) | ||||||
|  | { | ||||||
|  |     const double two_32 = 4294967296.0; | ||||||
|  |     // Computes the phase step multiplying the resampling ratio by 2^32 = 4294967296 | ||||||
|  |     if (d_sample_freq_in >= d_sample_freq_out) | ||||||
|  |     { | ||||||
|  |         d_phase_step = static_cast<unsigned int>(floor(two_32 * sample_freq_out / sample_freq_in)); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         d_phase_step = static_cast<unsigned int>(floor(two_32 * sample_freq_in / sample_freq_out)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     set_relative_rate(1.0 * sample_freq_out / sample_freq_in); | ||||||
|  |     set_output_multiple(1); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | direct_resampler_conditioner_bb::~direct_resampler_conditioner_bb() | ||||||
|  | { | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void direct_resampler_conditioner_bb::forecast(int noutput_items, | ||||||
|  |         gr_vector_int &ninput_items_required) | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     int nreqd = std::max(static_cast<unsigned>(1), static_cast<int>(static_cast<double>(noutput_items + 1) | ||||||
|  |             * sample_freq_in() / sample_freq_out()) + history() - 1); | ||||||
|  |     unsigned ninputs = ninput_items_required.size(); | ||||||
|  |  | ||||||
|  |     for (unsigned i = 0; i < ninputs; i++) | ||||||
|  |     { | ||||||
|  |         ninput_items_required[i] = nreqd; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int direct_resampler_conditioner_bb::general_work(int noutput_items, | ||||||
|  |         gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, | ||||||
|  |         gr_vector_void_star &output_items) | ||||||
|  | { | ||||||
|  |  | ||||||
|  |     const lv_8sc_t *in = (const lv_8sc_t *)input_items[0]; | ||||||
|  |     lv_8sc_t *out = (lv_8sc_t *)output_items[0]; | ||||||
|  |  | ||||||
|  |     int lcv = 0; | ||||||
|  |     int count = 0; | ||||||
|  |  | ||||||
|  |     if (d_sample_freq_in >= d_sample_freq_out) | ||||||
|  |     { | ||||||
|  |         while ((lcv < noutput_items)) | ||||||
|  |         { | ||||||
|  |             if (d_phase <= d_lphase) | ||||||
|  |             { | ||||||
|  |                 out[lcv] = *in; | ||||||
|  |                 lcv++; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             d_lphase = d_phase; | ||||||
|  |             d_phase += d_phase_step; | ||||||
|  |             in++; | ||||||
|  |             count++; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         while ((lcv < noutput_items)) | ||||||
|  |         { | ||||||
|  |             d_lphase = d_phase; | ||||||
|  |             d_phase += d_phase_step; | ||||||
|  |             if (d_phase <= d_lphase) | ||||||
|  |             { | ||||||
|  |                 in++; | ||||||
|  |                 count++; | ||||||
|  |             } | ||||||
|  |             out[lcv] = *in; | ||||||
|  |             lcv++; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     consume_each(std::min(count, ninput_items[0])); | ||||||
|  |     return lcv; | ||||||
|  | } | ||||||
| @@ -0,0 +1,86 @@ | |||||||
|  | /*! | ||||||
|  |  * \file direct_resampler_conditioner_bb.h | ||||||
|  |  * \brief Nearest neighborhood resampler with | ||||||
|  |  *        std::complex<signed char> input and std::complex<signed char> output | ||||||
|  |  * \author Luis Esteve, 2011. luis(at)epsilon-formacion.com | ||||||
|  |  * | ||||||
|  |  * ------------------------------------------------------------------------- | ||||||
|  |  * | ||||||
|  |  * Copyright (C) 2010-2015  (see AUTHORS file for a list of contributors) | ||||||
|  |  * | ||||||
|  |  * GNSS-SDR is a software defined Global Navigation | ||||||
|  |  *          Satellite Systems receiver | ||||||
|  |  * | ||||||
|  |  * This file is part of GNSS-SDR. | ||||||
|  |  * | ||||||
|  |  * GNSS-SDR 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, either version 3 of the License, or | ||||||
|  |  * (at your option) any later version. | ||||||
|  |  * | ||||||
|  |  * GNSS-SDR 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 for more details. | ||||||
|  |  * | ||||||
|  |  * You should have received a copy of the GNU General Public License | ||||||
|  |  * along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>. | ||||||
|  |  * | ||||||
|  |  * ------------------------------------------------------------------------- | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #ifndef GNSS_SDR_DIRECT_RESAMPLER_CONDITIONER_BB_H | ||||||
|  | #define GNSS_SDR_DIRECT_RESAMPLER_CONDITIONER_BB_H | ||||||
|  |  | ||||||
|  | #include <gnuradio/block.h> | ||||||
|  |  | ||||||
|  | class direct_resampler_conditioner_bb; | ||||||
|  | typedef boost::shared_ptr<direct_resampler_conditioner_bb> | ||||||
|  |         direct_resampler_conditioner_bb_sptr; | ||||||
|  |  | ||||||
|  | direct_resampler_conditioner_bb_sptr | ||||||
|  | direct_resampler_make_conditioner_bb(double sample_freq_in, | ||||||
|  |         double sample_freq_out); | ||||||
|  | /*! | ||||||
|  |  * \brief This class implements a direct resampler conditioner for std::complex<signed char> | ||||||
|  |  * | ||||||
|  |  * Direct resampling without interpolation | ||||||
|  |  */ | ||||||
|  | class direct_resampler_conditioner_bb: public gr::block | ||||||
|  | { | ||||||
|  |  | ||||||
|  | private: | ||||||
|  |  | ||||||
|  |     friend direct_resampler_conditioner_bb_sptr | ||||||
|  |     direct_resampler_make_conditioner_bb(double sample_freq_in, | ||||||
|  |             double sample_freq_out); | ||||||
|  |  | ||||||
|  |     double d_sample_freq_in; | ||||||
|  |     double d_sample_freq_out; | ||||||
|  |     unsigned int d_phase; | ||||||
|  |     unsigned int d_lphase; | ||||||
|  |     unsigned int d_phase_step; | ||||||
|  |     unsigned int d_history; | ||||||
|  |  | ||||||
|  |     direct_resampler_conditioner_bb(double sample_freq_in, | ||||||
|  |             double sample_freq_out); | ||||||
|  |  | ||||||
|  | public: | ||||||
|  |  | ||||||
|  |     ~direct_resampler_conditioner_bb(); | ||||||
|  |  | ||||||
|  |     unsigned int sample_freq_in() const | ||||||
|  |     { | ||||||
|  |         return d_sample_freq_in; | ||||||
|  |     } | ||||||
|  |     unsigned int sample_freq_out() const | ||||||
|  |     { | ||||||
|  |         return d_sample_freq_out; | ||||||
|  |     } | ||||||
|  |     void forecast(int noutput_items, gr_vector_int &ninput_items_required); | ||||||
|  |     int general_work(int noutput_items, gr_vector_int &ninput_items, | ||||||
|  |             gr_vector_const_void_star &input_items, | ||||||
|  |             gr_vector_void_star &output_items); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | #endif /* GNSS_SDR_DIRECT_RESAMPLER_CONDITIONER_SS_H */ | ||||||
| @@ -1,7 +1,7 @@ | |||||||
| /*! | /*! | ||||||
|  * \file direct_resampler_conditioner_ss.cc |  * \file direct_resampler_conditioner_ss.cc | ||||||
|  * \brief Nearest neighborhood resampler with |  * \brief Nearest neighborhood resampler with | ||||||
|  *        short input and short output |  *        complex short input and complex short output | ||||||
|  * \author Luis Esteve, 2011. luis(at)epsilon-formacion.com |  * \author Luis Esteve, 2011. luis(at)epsilon-formacion.com | ||||||
|  * |  * | ||||||
|  * Detailed description of the file here if needed. |  * Detailed description of the file here if needed. | ||||||
| @@ -37,6 +37,7 @@ | |||||||
| #include <iostream> | #include <iostream> | ||||||
| #include <gnuradio/io_signature.h> | #include <gnuradio/io_signature.h> | ||||||
| #include <glog/logging.h> | #include <glog/logging.h> | ||||||
|  | #include <volk/volk.h> | ||||||
|  |  | ||||||
| using google::LogMessage; | using google::LogMessage; | ||||||
|  |  | ||||||
| @@ -52,7 +53,7 @@ direct_resampler_conditioner_ss_sptr direct_resampler_make_conditioner_ss( | |||||||
| direct_resampler_conditioner_ss::direct_resampler_conditioner_ss( | direct_resampler_conditioner_ss::direct_resampler_conditioner_ss( | ||||||
|         double sample_freq_in, double sample_freq_out) : |         double sample_freq_in, double sample_freq_out) : | ||||||
|     gr::block("direct_resampler_make_conditioner_ss", gr::io_signature::make(1, |     gr::block("direct_resampler_make_conditioner_ss", gr::io_signature::make(1, | ||||||
|             1, sizeof(short)), gr::io_signature::make(1, 1, sizeof(short))), |             1, sizeof(lv_16sc_t)), gr::io_signature::make(1, 1, sizeof(lv_16sc_t))), | ||||||
|             d_sample_freq_in(sample_freq_in), d_sample_freq_out( |             d_sample_freq_in(sample_freq_in), d_sample_freq_out( | ||||||
|                     sample_freq_out), d_phase(0), d_lphase(0), d_history(1) |                     sample_freq_out), d_phase(0), d_lphase(0), d_history(1) | ||||||
| { | { | ||||||
| @@ -95,8 +96,8 @@ int direct_resampler_conditioner_ss::general_work(int noutput_items, | |||||||
|         gr_vector_void_star &output_items) |         gr_vector_void_star &output_items) | ||||||
| { | { | ||||||
|  |  | ||||||
|     const signed short *in = (const signed short *)input_items[0]; |     const lv_16sc_t *in = (const lv_16sc_t *)input_items[0]; | ||||||
|     signed short *out = (signed short *)output_items[0]; |     lv_16sc_t *out = (lv_16sc_t *)output_items[0]; | ||||||
|  |  | ||||||
|     int lcv = 0; |     int lcv = 0; | ||||||
|     int count = 0; |     int count = 0; | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| /*! | /*! | ||||||
|  * \file direct_resampler_conditioner_ss.h |  * \file direct_resampler_conditioner_ss.h | ||||||
|  * \brief Nearest neighborhood resampler with |  * \brief Nearest neighborhood resampler with | ||||||
|  *        short input and short output |  *        std::complex<short> input and std::complex<short> output | ||||||
|  * \author Luis Esteve, 2011. luis(at)epsilon-formacion.com |  * \author Luis Esteve, 2011. luis(at)epsilon-formacion.com | ||||||
|  * |  * | ||||||
|  * ------------------------------------------------------------------------- |  * ------------------------------------------------------------------------- | ||||||
| @@ -42,7 +42,7 @@ direct_resampler_conditioner_ss_sptr | |||||||
| direct_resampler_make_conditioner_ss(double sample_freq_in, | direct_resampler_make_conditioner_ss(double sample_freq_in, | ||||||
|         double sample_freq_out); |         double sample_freq_out); | ||||||
| /*! | /*! | ||||||
|  * \brief This class implements a direct resampler conditioner for shorts |  * \brief This class implements a direct resampler conditioner for std::complex<short> | ||||||
|  * |  * | ||||||
|  * Direct resampling without interpolation |  * Direct resampling without interpolation | ||||||
|  */ |  */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Carles Fernandez
					Carles Fernandez