#pragma once #include namespace dsp { class ComplexToStereo : public generic_block { public: ComplexToStereo() {} ComplexToStereo(stream* in) { init(in); } ~ComplexToStereo() { generic_block::stop(); } static_assert(sizeof(complex_t) == sizeof(stereo_t)); void init(stream* in) { _in = in; generic_block::registerInput(_in); generic_block::registerOutput(&out); } void setInput(stream* in) { 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() { 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: float avg; int count; stream* _in; }; class ComplexToReal : public generic_block { public: ComplexToReal() {} ComplexToReal(stream* in) { init(in); } ~ComplexToReal() { generic_block::stop(); } void init(stream* in) { _in = in; generic_block::registerInput(_in); generic_block::registerOutput(&out); } void setInput(stream* in) { 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() { 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: float avg; int count; stream* _in; }; class ComplexToImag : public generic_block { public: ComplexToImag() {} ComplexToImag(stream* in) { init(in); } ~ComplexToImag() { generic_block::stop(); } void init(stream* in) { _in = in; generic_block::registerInput(_in); generic_block::registerOutput(&out); } void setInput(stream* in) { 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() { 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: float avg; int count; stream* _in; }; class RealToComplex : public generic_block { public: RealToComplex() {} RealToComplex(stream* in) { init(in); } ~RealToComplex() { delete[] nullBuffer; generic_block::stop(); } 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); } void setInput(stream* in) { 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() { 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 avg; int count; float* nullBuffer; stream* _in; }; }