satdump/src-core/common/dsp/freq_shift.cpp

36 lines
979 B
C++
Raw Normal View History

2021-06-09 00:33:52 +02:00
#include "freq_shift.h"
#include <volk/volk.h>
#include <cmath>
2021-06-09 18:30:25 +02:00
#ifndef M_PI
#define M_PI 3.14159265358979323846 /* pi */
#endif
2021-06-09 00:33:52 +02:00
namespace dsp
{
2021-10-22 15:26:17 +02:00
FreqShiftBlock::FreqShiftBlock(std::shared_ptr<dsp::stream<complex_t>> input, float samplerate, float shift) : Block(input)
2021-06-09 00:33:52 +02:00
{
2021-10-22 15:26:17 +02:00
phase = complex_t(1, 0);
2021-11-28 12:55:32 +01:00
phase_delta = complex_t(cos(2.0f * M_PI * (shift / samplerate)), sin(2.0f * M_PI * (shift / samplerate)));
2021-06-09 00:33:52 +02:00
}
void FreqShiftBlock::work()
{
int nsamples = input_stream->read();
if (nsamples <= 0)
2021-08-13 10:55:45 +02:00
{
input_stream->flush();
2021-06-09 00:33:52 +02:00
return;
2021-08-13 10:55:45 +02:00
}
2021-10-22 15:26:17 +02:00
volk_32fc_s32fc_x2_rotator_32fc((lv_32fc_t *)output_stream->writeBuf, (lv_32fc_t *)input_stream->readBuf, phase_delta, (lv_32fc_t *)&phase, nsamples);
2021-06-09 00:33:52 +02:00
input_stream->flush();
output_stream->swap(nsamples);
}
2022-03-29 15:49:18 +02:00
void FreqShiftBlock::set_freq_raw(float freq)
{
phase_delta = complex_t(cosf(freq), sinf(freq));
}
2021-06-09 00:33:52 +02:00
}