#pragma once #include namespace dsp { class MonoToStereo : public generic_block { public: MonoToStereo() {} MonoToStereo(stream* in) { init(in); } ~MonoToStereo() { 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; } for (int i = 0; i < count; i++) { out.writeBuf[i].l = _in->readBuf[i]; out.writeBuf[i].r = _in->readBuf[i]; } _in->flush(); if (!out.swap(count)) { return -1; } return count; } stream out; private: int count; stream* _in; }; class StereoToMono : public generic_block { public: StereoToMono() {} StereoToMono(stream* in) { init(in); } ~StereoToMono() { 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; } for (int i = 0; i < count; i++) { out.writeBuf[i] = (_in->readBuf[i].l + _in->readBuf[i].r) / 2.0f; } _in->flush(); if (!out.swap(count)) { return -1; } return count; } stream out; private: int count; stream* _in; }; }