#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; } if (out.aquire() < 0) { return -1; } for (int i = 0; i < count; i++) { out.data[i].l = _in->data[i]; out.data[i].r = _in->data[i]; } _in->flush(); out.write(count); 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; } if (out.aquire() < 0) { return -1; } for (int i = 0; i < count; i++) { out.data[i] = (_in->data[i].l + _in->data[i].r) / 2.0f; } _in->flush(); out.write(count); return count; } stream out; private: int count; stream* _in; }; }