forked from sdr/gr-osmosdr
file: allow changing the sample rate when throttle=true
this is dangerous from signal processing perspective and should be used with caution.
This commit is contained in:
parent
c904d26eb4
commit
60120746aa
|
@ -26,7 +26,6 @@
|
||||||
|
|
||||||
#include <gnuradio/io_signature.h>
|
#include <gnuradio/io_signature.h>
|
||||||
#include <gnuradio/blocks/file_source.h>
|
#include <gnuradio/blocks/file_source.h>
|
||||||
#include <gnuradio/blocks/throttle.h>
|
|
||||||
|
|
||||||
#include "file_source_c.h"
|
#include "file_source_c.h"
|
||||||
|
|
||||||
|
@ -73,19 +72,21 @@ file_source_c::file_source_c(const std::string &args) :
|
||||||
if (_freq < 0)
|
if (_freq < 0)
|
||||||
throw std::runtime_error("Parameter 'freq' may not be negative.");
|
throw std::runtime_error("Parameter 'freq' may not be negative.");
|
||||||
|
|
||||||
if (0 == _rate)
|
if (0 == _rate && throttle)
|
||||||
throw std::runtime_error("Parameter 'rate' is missing in arguments.");
|
throw std::runtime_error("Parameter 'rate' is missing in arguments.");
|
||||||
|
|
||||||
|
_file_rate = _rate;
|
||||||
|
|
||||||
gr::blocks::file_source::sptr src = \
|
gr::blocks::file_source::sptr src = \
|
||||||
gr::blocks::file_source::make( sizeof(gr_complex),
|
gr::blocks::file_source::make( sizeof(gr_complex),
|
||||||
filename.c_str(),
|
filename.c_str(),
|
||||||
repeat );
|
repeat );
|
||||||
|
|
||||||
if (throttle) {
|
_throttle = gr::blocks::throttle::make( sizeof(gr_complex), _file_rate );
|
||||||
gr::blocks::throttle::sptr throttle = gr::blocks::throttle::make( sizeof(gr_complex), _rate );
|
|
||||||
|
|
||||||
connect( src, 0, throttle, 0 );
|
if (throttle) {
|
||||||
connect( throttle, 0, self(), 0 );
|
connect( src, 0, _throttle, 0 );
|
||||||
|
connect( _throttle, 0, self(), 0 );
|
||||||
} else {
|
} else {
|
||||||
connect( src, 0, self(), 0 );
|
connect( src, 0, self(), 0 );
|
||||||
}
|
}
|
||||||
|
@ -104,7 +105,8 @@ std::vector<std::string> file_source_c::get_devices()
|
||||||
{
|
{
|
||||||
std::vector<std::string> devices;
|
std::vector<std::string> devices;
|
||||||
|
|
||||||
std::string args = "file='/path/to/your/file',rate=1e6,freq=100e6,repeat=true,throttle=true";
|
std::string args = "file='/path/to/your/file'";
|
||||||
|
args += ",rate=1e6,freq=100e6,repeat=true,throttle=true";
|
||||||
args += ",label='Complex Sampled (IQ) File'";
|
args += ",label='Complex Sampled (IQ) File'";
|
||||||
devices.push_back( args );
|
devices.push_back( args );
|
||||||
|
|
||||||
|
@ -120,13 +122,24 @@ osmosdr::meta_range_t file_source_c::get_sample_rates( void )
|
||||||
{
|
{
|
||||||
osmosdr::meta_range_t range;
|
osmosdr::meta_range_t range;
|
||||||
|
|
||||||
range += osmosdr::range_t( get_sample_rate() );
|
range += osmosdr::range_t( _file_rate ); /* always return file's original rate */
|
||||||
|
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
double file_source_c::set_sample_rate( double rate )
|
double file_source_c::set_sample_rate( double rate )
|
||||||
{
|
{
|
||||||
|
if ( _file_rate != rate )
|
||||||
|
{
|
||||||
|
std::cerr << boost::format("WARNING: Overriding original sample rate of %g with %g")
|
||||||
|
% _file_rate % rate
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
_throttle->set_sample_rate( rate );
|
||||||
|
|
||||||
|
_rate = rate;
|
||||||
|
|
||||||
return get_sample_rate();
|
return get_sample_rate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#define FILE_SOURCE_C_H
|
#define FILE_SOURCE_C_H
|
||||||
|
|
||||||
#include <gnuradio/hier_block2.h>
|
#include <gnuradio/hier_block2.h>
|
||||||
|
#include <gnuradio/blocks/throttle.h>
|
||||||
|
|
||||||
#include "source_iface.h"
|
#include "source_iface.h"
|
||||||
|
|
||||||
|
@ -71,6 +72,8 @@ public:
|
||||||
std::string get_antenna( size_t chan = 0 );
|
std::string get_antenna( size_t chan = 0 );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
gr::blocks::throttle::sptr _throttle;
|
||||||
|
double _file_rate;
|
||||||
double _freq, _rate;
|
double _freq, _rate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue