mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-11-19 08:14:55 +00:00
Merge branch 'stefanlinden-next' into next
This commit is contained in:
commit
8bc379718f
@ -64,9 +64,14 @@ int FifoReader::work(int noutput_items,
|
|||||||
// ishort == int16_t
|
// ishort == int16_t
|
||||||
items_retrieved = read_interleaved<int16_t>(noutput_items, output_items);
|
items_retrieved = read_interleaved<int16_t>(noutput_items, output_items);
|
||||||
}
|
}
|
||||||
|
else if (sample_type_ == "ibyte") // Does this also work with cbyte?
|
||||||
|
{
|
||||||
|
// ibyte == int8_t
|
||||||
|
items_retrieved = read_interleaved<int8_t>(noutput_items, output_items);
|
||||||
|
}
|
||||||
else if (sample_type_ == "gr_complex")
|
else if (sample_type_ == "gr_complex")
|
||||||
{
|
{
|
||||||
LOG(WARNING) << sample_type_ << " is not yet tested. Please consider removing this warning if tested successfully";
|
// gr_complex == complex<float>
|
||||||
items_retrieved = read_gr_complex(noutput_items, output_items);
|
items_retrieved = read_gr_complex(noutput_items, output_items);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -80,6 +85,7 @@ int FifoReader::work(int noutput_items,
|
|||||||
return this->WORK_CALLED_PRODUCE;
|
return this->WORK_CALLED_PRODUCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// read gr_complex items from fifo
|
// read gr_complex items from fifo
|
||||||
// this fct has duplicate code with the templated read_interleaved fct in header
|
// this fct has duplicate code with the templated read_interleaved fct in header
|
||||||
size_t FifoReader::read_gr_complex(int noutput_items, gr_vector_void_star &output_items)
|
size_t FifoReader::read_gr_complex(int noutput_items, gr_vector_void_star &output_items)
|
||||||
|
@ -51,8 +51,11 @@ private:
|
|||||||
FifoReader(const std::string &file_name, const std::string &sample_type);
|
FifoReader(const std::string &file_name, const std::string &sample_type);
|
||||||
|
|
||||||
size_t read_gr_complex(int noutput_items, gr_vector_void_star &output_items);
|
size_t read_gr_complex(int noutput_items, gr_vector_void_star &output_items);
|
||||||
|
|
||||||
//! function to read data out of FIFO which is stored as interleaved I/Q stream.
|
//! function to read data out of FIFO which is stored as interleaved I/Q stream.
|
||||||
//! template argument determines sample_type
|
//! template argument determines sample_type
|
||||||
|
// Note: template definition necessary in header file
|
||||||
|
// See also: https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
size_t read_interleaved(int noutput_items, gr_vector_void_star &output_items)
|
size_t read_interleaved(int noutput_items, gr_vector_void_star &output_items)
|
||||||
{
|
{
|
||||||
@ -61,15 +64,13 @@ private:
|
|||||||
{
|
{
|
||||||
// TODO: try if performance increases if we copy larger chunks to vector.
|
// TODO: try if performance increases if we copy larger chunks to vector.
|
||||||
// how to read from stream: https://en.cppreference.com/w/cpp/io/basic_ifstream
|
// how to read from stream: https://en.cppreference.com/w/cpp/io/basic_ifstream
|
||||||
std::array<char, 4> buffer; // gr_complex is 32bit = 4*char
|
std::array<char, 2 * sizeof(Type)> buffer;
|
||||||
fifo_.read(reinterpret_cast<char *>(&buffer[0]), buffer.size());
|
fifo_.read(reinterpret_cast<char *>(buffer.data()), buffer.size());
|
||||||
if (fifo_.good())
|
if (fifo_.good())
|
||||||
{
|
{
|
||||||
Type real;
|
auto real = reinterpret_cast<Type const *>(&buffer[0]);
|
||||||
Type imag;
|
auto imag = reinterpret_cast<Type const *>(&buffer[sizeof(Type)]);
|
||||||
memcpy(&real, &buffer[0], sizeof(real));
|
static_cast<gr_complex *>(output_items[0])[n] = gr_complex(*real, *imag);
|
||||||
memcpy(&imag, &buffer[2], sizeof(imag));
|
|
||||||
static_cast<gr_complex *>(output_items.at(0))[n] = gr_complex(real, imag);
|
|
||||||
items_retrieved++;
|
items_retrieved++;
|
||||||
}
|
}
|
||||||
else if (fifo_.eof())
|
else if (fifo_.eof())
|
||||||
|
Loading…
Reference in New Issue
Block a user