diff --git a/src/algorithms/signal_source/gnuradio_blocks/fifo_reader.cc b/src/algorithms/signal_source/gnuradio_blocks/fifo_reader.cc index 4eb7d53cf..583fe6810 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/fifo_reader.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/fifo_reader.cc @@ -64,9 +64,14 @@ int FifoReader::work(int noutput_items, // ishort == int16_t items_retrieved = read_interleaved(noutput_items, output_items); } + else if (sample_type_ == "ibyte") // Does this also work with cbyte? + { + // ibyte == int8_t + items_retrieved = read_interleaved(noutput_items, output_items); + } 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 items_retrieved = read_gr_complex(noutput_items, output_items); } else @@ -80,6 +85,7 @@ int FifoReader::work(int noutput_items, return this->WORK_CALLED_PRODUCE; } + // read gr_complex items from fifo // 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) diff --git a/src/algorithms/signal_source/gnuradio_blocks/fifo_reader.h b/src/algorithms/signal_source/gnuradio_blocks/fifo_reader.h index 9e289ebf5..276970191 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/fifo_reader.h +++ b/src/algorithms/signal_source/gnuradio_blocks/fifo_reader.h @@ -51,8 +51,11 @@ private: 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); + //! function to read data out of FIFO which is stored as interleaved I/Q stream. //! 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 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. // how to read from stream: https://en.cppreference.com/w/cpp/io/basic_ifstream - std::array buffer; // gr_complex is 32bit = 4*char - fifo_.read(reinterpret_cast(&buffer[0]), buffer.size()); + std::array buffer; + fifo_.read(reinterpret_cast(buffer.data()), buffer.size()); if (fifo_.good()) { - Type real; - Type imag; - memcpy(&real, &buffer[0], sizeof(real)); - memcpy(&imag, &buffer[2], sizeof(imag)); - static_cast(output_items.at(0))[n] = gr_complex(real, imag); + auto real = reinterpret_cast(&buffer[0]); + auto imag = reinterpret_cast(&buffer[sizeof(Type)]); + static_cast(output_items[0])[n] = gr_complex(*real, *imag); items_retrieved++; } else if (fifo_.eof())