2021-03-12 15:55:55 +01:00
|
|
|
#include "file_source.h"
|
2021-03-19 16:15:41 +01:00
|
|
|
#include <volk/volk.h>
|
2021-03-12 15:55:55 +01:00
|
|
|
|
|
|
|
|
namespace dsp
|
|
|
|
|
{
|
2021-06-14 01:10:06 +02:00
|
|
|
FileSourceBlock::FileSourceBlock(std::string file, BasebandType type, int buffer_size, bool iq_swap) : Block(nullptr),
|
|
|
|
|
d_type(type),
|
|
|
|
|
d_buffer_size(buffer_size),
|
|
|
|
|
d_iq_swap(iq_swap)
|
2021-03-12 15:55:55 +01:00
|
|
|
{
|
2022-05-03 23:53:23 +02:00
|
|
|
baseband_reader.set_file(file, type);
|
|
|
|
|
|
|
|
|
|
d_filesize = baseband_reader.filesize;
|
2021-03-12 15:55:55 +01:00
|
|
|
d_progress = 0;
|
|
|
|
|
d_eof = false;
|
|
|
|
|
|
2021-03-12 17:56:29 +01:00
|
|
|
d_got_input = false;
|
2021-03-12 15:55:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileSourceBlock::~FileSourceBlock()
|
|
|
|
|
{
|
2022-05-03 23:53:23 +02:00
|
|
|
baseband_reader.close();
|
2021-03-12 15:55:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FileSourceBlock::work()
|
|
|
|
|
{
|
2022-05-03 23:53:23 +02:00
|
|
|
if (!baseband_reader.is_eof())
|
2021-03-12 15:55:55 +01:00
|
|
|
{
|
2023-01-16 20:50:34 +01:00
|
|
|
int read = baseband_reader.read_samples(output_stream->writeBuf, d_buffer_size);
|
2021-04-05 17:08:29 +02:00
|
|
|
|
|
|
|
|
if (d_iq_swap)
|
2023-01-16 20:50:34 +01:00
|
|
|
for (int i = 0; i < read; i++)
|
2021-10-22 15:26:17 +02:00
|
|
|
output_stream->writeBuf[i] = complex_t(output_stream->writeBuf[i].imag, output_stream->writeBuf[i].real);
|
2021-03-12 15:55:55 +01:00
|
|
|
|
2023-01-16 20:50:34 +01:00
|
|
|
output_stream->swap(read);
|
2021-03-12 15:55:55 +01:00
|
|
|
|
2022-05-03 23:53:23 +02:00
|
|
|
d_progress = baseband_reader.progress;
|
2021-03-12 15:55:55 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
d_eof = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-19 18:26:40 +01:00
|
|
|
uint64_t FileSourceBlock::getFilesize()
|
2021-03-12 15:55:55 +01:00
|
|
|
{
|
|
|
|
|
return d_filesize;
|
|
|
|
|
}
|
2022-05-03 23:53:23 +02:00
|
|
|
|
2021-03-19 18:26:40 +01:00
|
|
|
uint64_t FileSourceBlock::getPosition()
|
2021-03-12 15:55:55 +01:00
|
|
|
{
|
|
|
|
|
return d_progress;
|
|
|
|
|
}
|
2022-05-03 23:53:23 +02:00
|
|
|
|
2021-03-12 15:55:55 +01:00
|
|
|
bool FileSourceBlock::eof()
|
|
|
|
|
{
|
|
|
|
|
return d_eof;
|
|
|
|
|
}
|
|
|
|
|
}
|