2012-02-18 17:45:37 +00:00
|
|
|
/*!
|
|
|
|
* \file direct_resampler_conditioner.cc
|
|
|
|
* \brief Implementation of an adapter of a direct resampler conditioner block
|
|
|
|
* to a SignalConditionerInterface
|
|
|
|
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2012-02-18 17:45:37 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2012-02-18 17:45:37 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2012-02-18 17:45:37 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2012-02-18 17:45:37 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "direct_resampler_conditioner.h"
|
2018-12-09 21:00:09 +00:00
|
|
|
#include "configuration_interface.h"
|
|
|
|
#include "direct_resampler_conditioner_cb.h"
|
2012-02-18 17:45:37 +00:00
|
|
|
#include "direct_resampler_conditioner_cc.h"
|
2015-02-04 01:12:37 +00:00
|
|
|
#include "direct_resampler_conditioner_cs.h"
|
2018-02-26 02:15:53 +00:00
|
|
|
#include <glog/logging.h>
|
|
|
|
#include <gnuradio/blocks/file_sink.h>
|
2020-02-11 12:20:03 +00:00
|
|
|
#include <volk/volk.h> // for lv_8sc_t
|
2018-02-26 02:15:53 +00:00
|
|
|
#include <cmath>
|
2018-12-08 17:49:31 +00:00
|
|
|
#include <cstdint>
|
2018-02-26 02:15:53 +00:00
|
|
|
#include <limits>
|
2014-01-14 23:22:54 +00:00
|
|
|
|
2012-02-18 17:45:37 +00:00
|
|
|
|
|
|
|
DirectResamplerConditioner::DirectResamplerConditioner(
|
2022-12-08 10:16:40 +00:00
|
|
|
const ConfigurationInterface* configuration,
|
|
|
|
const std::string& role,
|
|
|
|
unsigned int in_stream,
|
|
|
|
unsigned int out_stream)
|
|
|
|
: role_(role),
|
|
|
|
in_stream_(in_stream),
|
|
|
|
out_stream_(out_stream),
|
|
|
|
dump_(configuration->property(role + ".dump", false))
|
2012-02-18 17:45:37 +00:00
|
|
|
{
|
2020-07-09 22:37:55 +00:00
|
|
|
const std::string default_item_type("short");
|
|
|
|
const std::string default_dump_file("./data/signal_conditioner.dat");
|
2020-07-17 08:48:37 +00:00
|
|
|
const double fs_in_deprecated = configuration->property("GNSS-SDR.internal_fs_hz", 2048000.0);
|
|
|
|
const double fs_in = configuration->property("GNSS-SDR.internal_fs_sps", fs_in_deprecated);
|
2022-12-08 10:16:40 +00:00
|
|
|
item_type_ = configuration->property(role + ".item_type", default_item_type);
|
|
|
|
dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file);
|
2017-08-18 10:45:47 +00:00
|
|
|
sample_freq_in_ = configuration->property(role_ + ".sample_freq_in", 4000000.0);
|
2016-08-13 15:25:07 +00:00
|
|
|
sample_freq_out_ = configuration->property(role_ + ".sample_freq_out", fs_in);
|
2022-12-08 10:16:40 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (std::fabs(fs_in - sample_freq_out_) > std::numeric_limits<double>::epsilon())
|
2016-08-13 15:25:07 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
std::string aux_warn = "CONFIGURATION WARNING: Parameters GNSS-SDR.internal_fs_sps and " + role_ + ".sample_freq_out are not set to the same value!";
|
2016-08-13 15:25:07 +00:00
|
|
|
LOG(WARNING) << aux_warn;
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << aux_warn << '\n';
|
2016-08-13 15:25:07 +00:00
|
|
|
}
|
2012-02-18 17:45:37 +00:00
|
|
|
|
2018-12-03 11:52:17 +00:00
|
|
|
if (item_type_ == "gr_complex")
|
2012-02-18 17:45:37 +00:00
|
|
|
{
|
|
|
|
item_size_ = sizeof(gr_complex);
|
2015-02-03 23:29:54 +00:00
|
|
|
resampler_ = direct_resampler_make_conditioner_cc(sample_freq_in_, sample_freq_out_);
|
2012-02-24 16:06:14 +00:00
|
|
|
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() << ")";
|
2012-02-18 17:45:37 +00:00
|
|
|
}
|
2018-12-03 11:52:17 +00:00
|
|
|
else if (item_type_ == "cshort")
|
2015-01-08 18:49:59 +00:00
|
|
|
{
|
2015-02-03 23:29:54 +00:00
|
|
|
item_size_ = sizeof(lv_16sc_t);
|
2015-02-04 01:12:37 +00:00
|
|
|
resampler_ = direct_resampler_make_conditioner_cs(sample_freq_in_, sample_freq_out_);
|
2015-02-03 23:29:54 +00:00
|
|
|
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() << ")";
|
|
|
|
}
|
2018-12-03 11:52:17 +00:00
|
|
|
else if (item_type_ == "cbyte")
|
2015-02-03 23:29:54 +00:00
|
|
|
{
|
|
|
|
item_size_ = sizeof(lv_8sc_t);
|
2015-02-04 01:12:37 +00:00
|
|
|
resampler_ = direct_resampler_make_conditioner_cb(sample_freq_in_, sample_freq_out_);
|
2015-02-03 23:29:54 +00:00
|
|
|
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() << ")";
|
2015-01-08 18:49:59 +00:00
|
|
|
}
|
2012-02-18 17:45:37 +00:00
|
|
|
else
|
|
|
|
{
|
2014-03-16 19:58:29 +00:00
|
|
|
LOG(WARNING) << item_type_ << " unrecognized item type for resampler";
|
2018-12-08 17:49:31 +00:00
|
|
|
item_size_ = sizeof(int16_t);
|
2012-02-18 17:45:37 +00:00
|
|
|
}
|
|
|
|
if (dump_)
|
|
|
|
{
|
|
|
|
DLOG(INFO) << "Dumping output into file " << dump_filename_;
|
2013-07-04 13:47:40 +00:00
|
|
|
file_sink_ = gr::blocks::file_sink::make(item_size_, dump_filename_.c_str());
|
2012-02-18 17:45:37 +00:00
|
|
|
DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")";
|
|
|
|
}
|
2018-06-03 17:11:16 +00:00
|
|
|
if (in_stream_ > 1)
|
|
|
|
{
|
|
|
|
LOG(ERROR) << "This implementation only supports one input stream";
|
|
|
|
}
|
|
|
|
if (out_stream_ > 1)
|
|
|
|
{
|
|
|
|
LOG(ERROR) << "This implementation only supports one output stream";
|
|
|
|
}
|
2012-02-18 17:45:37 +00:00
|
|
|
}
|
2012-10-28 10:56:04 +00:00
|
|
|
|
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
void DirectResamplerConditioner::connect(gr::top_block_sptr top_block)
|
2012-02-18 17:45:37 +00:00
|
|
|
{
|
|
|
|
if (dump_)
|
|
|
|
{
|
|
|
|
top_block->connect(resampler_, 0, file_sink_, 0);
|
|
|
|
DLOG(INFO) << "connected resampler to file sink";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DLOG(INFO) << "nothing to connect internally";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-28 10:56:04 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
void DirectResamplerConditioner::disconnect(gr::top_block_sptr top_block)
|
2012-02-18 17:45:37 +00:00
|
|
|
{
|
|
|
|
if (dump_)
|
|
|
|
{
|
|
|
|
top_block->disconnect(resampler_, 0, file_sink_, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-28 10:56:04 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
gr::basic_block_sptr DirectResamplerConditioner::get_left_block()
|
2012-02-18 17:45:37 +00:00
|
|
|
{
|
|
|
|
return resampler_;
|
|
|
|
}
|
|
|
|
|
2012-10-28 10:56:04 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
gr::basic_block_sptr DirectResamplerConditioner::get_right_block()
|
2012-02-18 17:45:37 +00:00
|
|
|
{
|
|
|
|
return resampler_;
|
|
|
|
}
|