#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; } if (out.aquire() < 0) { return -1; } memcpy(out.data, _in->data, count * sizeof(complex_t)); _in->flush(); out.write(count); 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; } if (out.aquire() < 0) { return -1; } volk_32fc_deinterleave_real_32f(out.data, (lv_32fc_t*)_in->data, count); _in->flush(); out.write(count); 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; } if (out.aquire() < 0) { return -1; } volk_32fc_deinterleave_imag_32f(out.data, (lv_32fc_t*)_in->data, count); _in->flush(); out.write(count); return count; } stream out; private: float avg; int count; stream* _in; }; }