fixed linux bugs

This commit is contained in:
AlexandreRouma
2020-10-24 14:51:55 +02:00
parent 0d45217dfd
commit edbc0c149d
9 changed files with 165 additions and 75 deletions

View File

@ -176,4 +176,76 @@ namespace dsp {
}
};
template <class T>
class Reshaper {
public:
Reshaper() {
}
void init(int outBlockSize, dsp::stream<T>* input) {
outputBlockSize = outBlockSize;
in = input;
out.init(outputBlockSize * 2);
}
void setOutputBlockSize(int blockSize) {
if (running) {
return;
}
outputBlockSize = blockSize;
out.setMaxLatency(outputBlockSize * 2);
}
void setInput(dsp::stream<T>* input) {
if (running) {
return;
}
in = input;
}
void start() {
if (running) {
return;
}
workerThread = std::thread(_worker, this);
running = true;
}
void stop() {
if (!running) {
return;
}
in->stopReader();
out.stopWriter();
workerThread.join();
in->clearReadStop();
out.clearWriteStop();
running = false;
}
dsp::stream<T> out;
private:
static void _worker(Reshaper* _this) {
T* buf = new T[_this->outputBlockSize];
while (true) {
if (_this->in->read(buf, _this->outputBlockSize) < 0) { break; }
if (_this->out.write(buf, _this->outputBlockSize) < 0) { break; }
}
delete[] buf;
}
int outputBlockSize;
bool running = false;
std::thread workerThread;
dsp::stream<T>* in;
};
};

View File

@ -3,6 +3,8 @@
#include <dsp/stream.h>
#include <dsp/types.h>
#include <vector>
#include <spdlog/spdlog.h>
namespace dsp {
class HandlerSink {
@ -61,18 +63,19 @@ namespace dsp {
bool running = false;
};
template <class T>
class NullSink {
public:
NullSink() {
}
NullSink(stream<complex_t>* input, int bufferSize) {
NullSink(stream<T>* input, int bufferSize) {
_in = input;
_bufferSize = bufferSize;
}
void init(stream<complex_t>* input, int bufferSize) {
void init(stream<T>* input, int bufferSize) {
_in = input;
_bufferSize = bufferSize;
}
@ -85,13 +88,14 @@ namespace dsp {
private:
static void _worker(NullSink* _this) {
complex_t* buf = new complex_t[_this->_bufferSize];
T* buf = new T[_this->_bufferSize];
while (true) {
//spdlog::info("NS: Reading...");
_this->_in->read(buf, _this->_bufferSize);
}
}
stream<complex_t>* _in;
stream<T>* _in;
int _bufferSize;
std::thread _workerThread;
};
@ -113,6 +117,7 @@ namespace dsp {
}
void start() {
spdlog::info("NS: Starting...");
_workerThread = std::thread(_worker, this);
}
@ -120,8 +125,10 @@ namespace dsp {
private:
static void _worker(FloatNullSink* _this) {
spdlog::info("NS: Started!");
float* buf = new float[_this->_bufferSize];
while (true) {
spdlog::info("NS: Reading...");
_this->_in->read(buf, _this->_bufferSize);
}
}