diff --git a/core/src/dsp/filter.h b/core/src/dsp/filter.h index 35ac6cb0..a303f101 100644 --- a/core/src/dsp/filter.h +++ b/core/src/dsp/filter.h @@ -1,7 +1,7 @@ #pragma once #include #include -#include namespace dsp { @@ -127,8 +127,11 @@ namespace dsp { } int run() { + spdlog::warn("+++++++++++++ DEEMP READING"); count = _in->read(); - if (count < 0) { return -1; } + if (count < 0) { spdlog::warn("++++++++++ DEEMP EXIT"); return -1; } + + spdlog::warn("+++++++++++++ DEEMP PROC"); if (bypass) { if (out.aquire() < 0) { return -1; } @@ -146,6 +149,8 @@ namespace dsp { } lastOut = out.data[count - 1]; + spdlog::warn("+++++++++++++ DEEMP DONE"); + _in->flush(); out.write(count); return count; diff --git a/core/src/dsp/resampling.h b/core/src/dsp/resampling.h index f74e7568..affd3d86 100644 --- a/core/src/dsp/resampling.h +++ b/core/src/dsp/resampling.h @@ -96,16 +96,23 @@ namespace dsp { } int run() { + if constexpr (std::is_same_v) { spdlog::warn("======= RESAMP WAITING ========"); } count = _in->read(); - if (count < 0) { return -1; } + if (count < 0) { + return -1; + } int outCount = calcOutSize(count); memcpy(bufStart, _in->data, count * sizeof(T)); _in->flush(); + if constexpr (std::is_same_v) { spdlog::warn("======= RESAMP GOT DATA ========"); } + // Write to output - if (out.aquire() < 0) { return -1; } + if (out.aquire() < 0) { + return -1; + } int outIndex = 0; if constexpr (std::is_same_v) { for (int i = 0; outIndex < outCount; i += _decim) { @@ -129,6 +136,8 @@ namespace dsp { } out.write(count); + if constexpr (std::is_same_v) { spdlog::warn("======= RESAMP WRITTEN ========"); } + memmove(buffer, &buffer[count], tapCount * sizeof(T)); return count; diff --git a/core/src/dsp/sink.h b/core/src/dsp/sink.h index ce50bf0b..1d362721 100644 --- a/core/src/dsp/sink.h +++ b/core/src/dsp/sink.h @@ -96,4 +96,38 @@ namespace dsp { stream* _in; }; + + template + class NullSink : public generic_block> { + public: + NullSink() {} + + NullSink(stream* in) { init(in); } + + ~NullSink() { generic_block>::stop(); } + + void init(stream* in) { + _in = in; + generic_block>::registerInput(_in); + } + + void setInput(stream* in) { + std::lock_guard lck(generic_block>::ctrlMtx); + generic_block>::tempStop(); + _in = in; + generic_block>::tempStart(); + } + + int run() { + count = _in->read(); + if (count < 0) { return -1; } + _in->flush(); + return count; + } + + private: + int count; + stream* _in; + + }; } \ No newline at end of file diff --git a/core/src/dsp/stream.h b/core/src/dsp/stream.h index 4dc3b36d..71cf5656 100644 --- a/core/src/dsp/stream.h +++ b/core/src/dsp/stream.h @@ -35,10 +35,13 @@ namespace dsp { } void write(int size) { - std::lock_guard lck(sigMtx); - contentSize = size; - dataReady = true; - cv.notify_all(); + { + std::lock_guard lck(sigMtx); + contentSize = size; + dataReady = true; + lck.~lock_guard(); + } + cv.notify_one(); } int read() { @@ -50,15 +53,21 @@ namespace dsp { } void flush() { - std::lock_guard lck(sigMtx); - dataReady = false; - cv.notify_all(); + { + std::lock_guard lck(sigMtx); + dataReady = false; + lck.~lock_guard(); + } + cv.notify_one(); } void stopReader() { - std::lock_guard lck(sigMtx); - readerStop = true; - cv.notify_all(); + { + std::lock_guard lck(sigMtx); + readerStop = true; + lck.~lock_guard(); + } + cv.notify_one(); } void clearReadStop() { @@ -66,9 +75,12 @@ namespace dsp { } void stopWriter() { - std::lock_guard lck(sigMtx); - writerStop = true; - cv.notify_all(); + { + std::lock_guard lck(sigMtx); + writerStop = true; + lck.~lock_guard(); + } + cv.notify_one(); } void clearWriteStop() { @@ -80,12 +92,12 @@ namespace dsp { private: void waitReady() { std::unique_lock lck(sigMtx); - cv.wait(lck, [this]{ return !dataReady || writerStop; }); + cv.wait(lck, [this]{ return (!dataReady || writerStop); }); } void waitData() { std::unique_lock lck(sigMtx); - cv.wait(lck, [this]{ return dataReady || readerStop; }); + cv.wait(lck, [this]{ return (dataReady || readerStop); }); } std::mutex sigMtx; diff --git a/radio/src/path.cpp b/radio/src/path.cpp index 1faad6fd..86e3ec79 100644 --- a/radio/src/path.cpp +++ b/radio/src/path.cpp @@ -1,5 +1,6 @@ #include #include +#include SigPath::SigPath() { @@ -45,11 +46,13 @@ void SigPath::init(std::string vfoName, uint64_t sampleRate, int blockSize) { ssbDemod.init(vfo->output, 6000, 3000, dsp::SSBDemod::MODE_USB); audioWin.init(24000, 24000, 200000); - audioResamp.init(&demod.out, &audioWin, 200000, 48000); + audioResamp.init(&DUMMY_STREAM, &audioWin, 200000, 48000); audioWin.setSampleRate(audioResamp.getInterpolation() * 200000); audioResamp.updateWindow(&audioWin); deemp.init(&audioResamp.out, 48000, 50e-6); + + ns.init(&demod.out); outputSampleRate = audio::registerMonoStream(&deemp.out, vfoName, vfoName, sampleRateChangeHandler, this); @@ -284,6 +287,7 @@ void SigPath::setBandwidth(float bandWidth) { void SigPath::start() { demod.start(); audioResamp.start(); - deemp.start(); + //deemp.start(); + ns.start(); audio::startStream(vfoName); } \ No newline at end of file diff --git a/radio/src/path.h b/radio/src/path.h index 21e6a257..d6bb96f6 100644 --- a/radio/src/path.h +++ b/radio/src/path.h @@ -63,6 +63,10 @@ private: dsp::filter_window::BlackmanWindow audioWin; dsp::PolyphaseResampler audioResamp; + // Debug + dsp::NullSink ns; + dsp::stream DUMMY_STREAM; + std::string vfoName; float sampleRate;