From bc0de50ba6dffaff580cf572db4ced1a4b414cea Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Mon, 20 Sep 2021 20:08:53 +0200 Subject: [PATCH] Fixed missing renamed filed --- core/src/dsp/conversion.h | 345 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 core/src/dsp/conversion.h diff --git a/core/src/dsp/conversion.h b/core/src/dsp/conversion.h new file mode 100644 index 00000000..e12aa470 --- /dev/null +++ b/core/src/dsp/conversion.h @@ -0,0 +1,345 @@ +#pragma once +#include + +namespace dsp { + class ComplexToStereo : public generic_block { + public: + ComplexToStereo() {} + + ComplexToStereo(stream* in) { init(in); } + + static_assert(sizeof(complex_t) == sizeof(stereo_t)); + + void init(stream* in) { + _in = in; + generic_block::registerInput(_in); + generic_block::registerOutput(&out); + generic_block::_block_init = true; + } + + void setInput(stream* in) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + _in = in; + generic_block::registerInput(_in); + generic_block::tempStart(); + } + + int run() { + int count = _in->read(); + if (count < 0) { return -1; } + + memcpy(out.writeBuf, _in->readBuf, count * sizeof(complex_t)); + + _in->flush(); + if (!out.swap(count)) { return -1; } + return count; + } + + stream out; + + private: + stream* _in; + + }; + + class ComplexToReal : public generic_block { + public: + ComplexToReal() {} + + ComplexToReal(stream* in) { init(in); } + + void init(stream* in) { + _in = in; + generic_block::registerInput(_in); + generic_block::registerOutput(&out); + generic_block::_block_init = true; + } + + void setInput(stream* in) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + _in = in; + generic_block::registerInput(_in); + generic_block::tempStart(); + } + + int run() { + int count = _in->read(); + if (count < 0) { return -1; } + + volk_32fc_deinterleave_real_32f(out.writeBuf, (lv_32fc_t*)_in->readBuf, count); + + _in->flush(); + if (!out.swap(count)) { return -1; } + return count; + } + + stream out; + + private: + stream* _in; + + }; + + class ComplexToImag : public generic_block { + public: + ComplexToImag() {} + + ComplexToImag(stream* in) { init(in); } + + void init(stream* in) { + _in = in; + generic_block::registerInput(_in); + generic_block::registerOutput(&out); + generic_block::_block_init = true; + } + + void setInput(stream* in) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + _in = in; + generic_block::registerInput(_in); + generic_block::tempStart(); + } + + int run() { + int count = _in->read(); + if (count < 0) { return -1; } + + volk_32fc_deinterleave_imag_32f(out.writeBuf, (lv_32fc_t*)_in->readBuf, count); + + _in->flush(); + if(!out.swap(count)) { return -1; } + return count; + } + + stream out; + + private: + stream* _in; + + }; + + + class RealToComplex : public generic_block { + public: + RealToComplex() {} + + RealToComplex(stream* in) { init(in); } + + ~RealToComplex() { + if (!generic_block::_block_init) { return; } + generic_block::stop(); + delete[] nullBuffer; + generic_block::_block_init = false; + } + + void init(stream* in) { + _in = in; + nullBuffer = new float[STREAM_BUFFER_SIZE]; + memset(nullBuffer, 0, STREAM_BUFFER_SIZE * sizeof(float)); + generic_block::registerInput(_in); + generic_block::registerOutput(&out); + generic_block::_block_init = true; + } + + void setInput(stream* in) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + _in = in; + generic_block::registerInput(_in); + generic_block::tempStart(); + } + + int run() { + int count = _in->read(); + if (count < 0) { return -1; } + + volk_32f_x2_interleave_32fc((lv_32fc_t*)out.writeBuf, _in->readBuf, nullBuffer, count); + + _in->flush(); + if (!out.swap(count)) { return -1; } + return count; + } + + stream out; + + private: + float* nullBuffer; + stream* _in; + + }; + + class Int16CToComplex : public generic_block { + public: + Int16CToComplex() {} + + Int16CToComplex(stream* in) { init(in); } + + void init(stream* in) { + _in = in; + generic_block::registerInput(_in); + generic_block::registerOutput(&out); + generic_block::_block_init = true; + } + + void setInput(stream* in) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + _in = in; + generic_block::registerInput(_in); + generic_block::tempStart(); + } + + int run() { + int count = _in->read(); + if (count < 0) { return -1; } + + volk_16i_s32f_convert_32f((float*)out.writeBuf, _in->readBuf, 32768.0f, count * 2); + + _in->flush(); + if (!out.swap(count)) { return -1; } + return count; + } + + stream out; + + private: + stream* _in; + + }; + + class ComplexToInt16C : public generic_block { + public: + ComplexToInt16C() {} + + ComplexToInt16C(stream* in) { init(in); } + + void init(stream* in) { + _in = in; + generic_block::registerInput(_in); + generic_block::registerOutput(&out); + generic_block::_block_init = true; + } + + void setInput(stream* in) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + _in = in; + generic_block::registerInput(_in); + generic_block::tempStart(); + } + + int run() { + int count = _in->read(); + if (count < 0) { return -1; } + + volk_32f_s32f_convert_16i(out.writeBuf, (float*)_in->readBuf, 32768.0f, count * 2); + + _in->flush(); + if (!out.swap(count)) { return -1; } + return count; + } + + stream out; + + private: + stream* _in; + + }; + + class Int16ToFloat : public generic_block { + public: + Int16ToFloat() {} + + Int16ToFloat(stream* in) { init(in); } + + void init(stream* in) { + _in = in; + generic_block::registerInput(_in); + generic_block::registerOutput(&out); + generic_block::_block_init = true; + } + + void setInput(stream* in) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + _in = in; + generic_block::registerInput(_in); + generic_block::tempStart(); + } + + int run() { + int count = _in->read(); + if (count < 0) { return -1; } + + volk_16i_s32f_convert_32f(out.writeBuf, _in->readBuf, 32768.0f, count); + + _in->flush(); + if (!out.swap(count)) { return -1; } + return count; + } + + stream out; + + private: + stream* _in; + + }; + + class FloatToInt16 : public generic_block { + public: + FloatToInt16() {} + + FloatToInt16(stream* in) { init(in); } + + void init(stream* in) { + _in = in; + generic_block::registerInput(_in); + generic_block::registerOutput(&out); + generic_block::_block_init = true; + } + + void setInput(stream* in) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + _in = in; + generic_block::registerInput(_in); + generic_block::tempStart(); + } + + int run() { + int count = _in->read(); + if (count < 0) { return -1; } + + volk_32f_s32f_convert_16i(out.writeBuf, _in->readBuf, 32768.0f, count); + + _in->flush(); + if (!out.swap(count)) { return -1; } + return count; + } + + stream out; + + private: + stream* _in; + + }; +} \ No newline at end of file