This commit is contained in:
Ryzerth
2020-11-02 16:16:21 +01:00
parent 75f8a45119
commit fc9bc496cb
6 changed files with 89 additions and 21 deletions

View File

@ -1,7 +1,7 @@
#pragma once
#include <dsp/block.h>
#include <dsp/window.h>
#include <spdlog/
#include <spdlog/spdlog.h>
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;

View File

@ -96,16 +96,23 @@ namespace dsp {
}
int run() {
if constexpr (std::is_same_v<T, float>) { 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<T, float>) { 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<T, float>) {
for (int i = 0; outIndex < outCount; i += _decim) {
@ -129,6 +136,8 @@ namespace dsp {
}
out.write(count);
if constexpr (std::is_same_v<T, float>) { spdlog::warn("======= RESAMP WRITTEN ========"); }
memmove(buffer, &buffer[count], tapCount * sizeof(T));
return count;

View File

@ -96,4 +96,38 @@ namespace dsp {
stream<T>* _in;
};
template <class T>
class NullSink : public generic_block<NullSink<T>> {
public:
NullSink() {}
NullSink(stream<T>* in) { init(in); }
~NullSink() { generic_block<NullSink<T>>::stop(); }
void init(stream<T>* in) {
_in = in;
generic_block<NullSink<T>>::registerInput(_in);
}
void setInput(stream<T>* in) {
std::lock_guard<std::mutex> lck(generic_block<NullSink<T>>::ctrlMtx);
generic_block<NullSink<T>>::tempStop();
_in = in;
generic_block<NullSink<T>>::tempStart();
}
int run() {
count = _in->read();
if (count < 0) { return -1; }
_in->flush();
return count;
}
private:
int count;
stream<T>* _in;
};
}

View File

@ -35,10 +35,13 @@ namespace dsp {
}
void write(int size) {
std::lock_guard<std::mutex> lck(sigMtx);
contentSize = size;
dataReady = true;
cv.notify_all();
{
std::lock_guard<std::mutex> 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<std::mutex> lck(sigMtx);
dataReady = false;
cv.notify_all();
{
std::lock_guard<std::mutex> lck(sigMtx);
dataReady = false;
lck.~lock_guard();
}
cv.notify_one();
}
void stopReader() {
std::lock_guard<std::mutex> lck(sigMtx);
readerStop = true;
cv.notify_all();
{
std::lock_guard<std::mutex> lck(sigMtx);
readerStop = true;
lck.~lock_guard();
}
cv.notify_one();
}
void clearReadStop() {
@ -66,9 +75,12 @@ namespace dsp {
}
void stopWriter() {
std::lock_guard<std::mutex> lck(sigMtx);
writerStop = true;
cv.notify_all();
{
std::lock_guard<std::mutex> lck(sigMtx);
writerStop = true;
lck.~lock_guard();
}
cv.notify_one();
}
void clearWriteStop() {
@ -80,12 +92,12 @@ namespace dsp {
private:
void waitReady() {
std::unique_lock<std::mutex> lck(sigMtx);
cv.wait(lck, [this]{ return !dataReady || writerStop; });
cv.wait(lck, [this]{ return (!dataReady || writerStop); });
}
void waitData() {
std::unique_lock<std::mutex> lck(sigMtx);
cv.wait(lck, [this]{ return dataReady || readerStop; });
cv.wait(lck, [this]{ return (dataReady || readerStop); });
}
std::mutex sigMtx;