#pragma once #include #include namespace dsp { template class Add : public generic_block> { public: Add() {} Add(stream* a, stream* b) { init(a, b); } void init(stream* a, stream* b) { _a = a; _b = b; generic_block>::registerInput(a); generic_block>::registerInput(b); generic_block>::registerOutput(&out); } int run() { int a_count = _a->read(); if (a_count < 0) { return -1; } int b_count = _b->read(); if (b_count < 0) { return -1; } if (a_count != b_count) { _a->flush(); _b->flush(); return 0; } if constexpr (std::is_same_v || std::is_same_v) { volk_32fc_x2_add_32fc((lv_32fc_t*)out.writeBuf, (lv_32fc_t*)_a->readBuf, (lv_32fc_t*)_b->readBuf, a_count); } else { volk_32f_x2_add_32f(out.writeBuf, _a->readBuf, _b->readBuf, a_count); } _a->flush(); _b->flush(); if (!out.swap(a_count)) { return -1; } return a_count; } stream out; private: stream* _a; stream* _b; }; template class Substract : public generic_block> { public: Substract() {} Substract(stream* a, stream* b) { init(a, b); } void init(stream* a, stream* b) { _a = a; _b = b; generic_block>::registerInput(a); generic_block>::registerInput(b); generic_block>::registerOutput(&out); } int run() { int a_count = _a->read(); if (a_count < 0) { return -1; } int b_count = _b->read(); if (b_count < 0) { return -1; } if (a_count != b_count) { _a->flush(); _b->flush(); return 0; } if constexpr (std::is_same_v || std::is_same_v) { volk_32f_x2_subtract_32f((float*)out.writeBuf, (float*)_a->readBuf, (float*)_b->readBuf, a_count * 2); } else { volk_32f_x2_subtract_32f(out.writeBuf, _a->readBuf, _b->readBuf, a_count); } _a->flush(); _b->flush(); if (!out.swap(a_count)) { return -1; } return a_count; } stream out; private: stream* _a; stream* _b; }; template class Multiply : public generic_block> { public: Multiply() {} Multiply(stream* a, stream* b) { init(a, b); } void init(stream* a, stream* b) { _a = a; _b = b; generic_block::registerInput(a); generic_block::registerInput(b); generic_block::registerOutput(&out); } int run() { int a_count = _a->read(); if (a_count < 0) { return -1; } int b_count = _b->read(); if (b_count < 0) { return -1; } if (a_count != b_count) { _a->flush(); _b->flush(); return 0; } if constexpr (std::is_same_v) { volk_32fc_x2_multiply_32fc((lv_32fc_t*)out.writeBuf, (lv_32fc_t*)_a->readBuf, (lv_32fc_t*)_b->readBuf, a_count); } else { volk_32f_x2_multiply_32f(out.writeBuf, _a->readBuf, _b->readBuf, a_count); } _a->flush(); _b->flush(); if (!out.swap(a_count)) { return -1; } return a_count; } stream out; private: stream* _a; stream* _b; }; }