mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-10-17 19:30:02 +02:00
a LOT of new stuff
This commit is contained in:
@@ -312,9 +312,17 @@ namespace dsp {
|
||||
|
||||
int inCount = _this->_blockSize;
|
||||
int outCount = _this->outputBlockSize;
|
||||
|
||||
float* taps = _this->_taps.data();
|
||||
|
||||
int interp = _this->_interp;
|
||||
int decim = _this->_decim;
|
||||
float correction = interp;//(float)sqrt((float)interp);
|
||||
|
||||
int tapCount = _this->_taps.size();
|
||||
float* taps = new float[tapCount];
|
||||
for (int i = 0; i < tapCount; i++) {
|
||||
taps[i] = _this->_taps[i] * correction;
|
||||
}
|
||||
|
||||
complex_t* delayBuf = new complex_t[tapCount];
|
||||
|
||||
complex_t* delayStart = &inBuf[std::max<int>(inCount - tapCount, 0)];
|
||||
@@ -322,11 +330,6 @@ namespace dsp {
|
||||
complex_t* delayBufEnd = &delayBuf[std::max<int>(tapCount - inCount, 0)];
|
||||
int moveSize = std::min<int>(inCount, tapCount - inCount) * sizeof(complex_t);
|
||||
int inSize = inCount * sizeof(complex_t);
|
||||
|
||||
int interp = _this->_interp;
|
||||
int decim = _this->_decim;
|
||||
|
||||
float correction = (float)sqrt((float)interp);
|
||||
|
||||
int afterInterp = inCount * interp;
|
||||
int outIndex = 0;
|
||||
@@ -335,12 +338,9 @@ namespace dsp {
|
||||
for (int i = 0; outIndex < outCount; i += decim) {
|
||||
outBuf[outIndex].i = 0;
|
||||
outBuf[outIndex].q = 0;
|
||||
for (int j = 0; j < tapCount; j++) {
|
||||
if ((i - j) % interp != 0) {
|
||||
continue;
|
||||
}
|
||||
outBuf[outIndex].i += GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp).i * taps[j] * correction;
|
||||
outBuf[outIndex].q += GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp).q * taps[j] * correction;
|
||||
for (int j = i % interp; j < tapCount; j += interp) {
|
||||
outBuf[outIndex].i += GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp).i * taps[j];
|
||||
outBuf[outIndex].q += GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp).q * taps[j];
|
||||
}
|
||||
outIndex++;
|
||||
}
|
||||
@@ -358,6 +358,7 @@ namespace dsp {
|
||||
delete[] inBuf;
|
||||
delete[] outBuf;
|
||||
delete[] delayBuf;
|
||||
delete[] taps;
|
||||
}
|
||||
|
||||
std::thread _workerThread;
|
||||
@@ -500,9 +501,17 @@ namespace dsp {
|
||||
|
||||
int inCount = _this->_blockSize;
|
||||
int outCount = _this->outputBlockSize;
|
||||
|
||||
int interp = _this->_interp;
|
||||
int decim = _this->_decim;
|
||||
float correction = interp;//(float)sqrt((float)interp);
|
||||
|
||||
float* taps = _this->_taps.data();
|
||||
int tapCount = _this->_taps.size();
|
||||
float* taps = new float[tapCount];
|
||||
for (int i = 0; i < tapCount; i++) {
|
||||
taps[i] = _this->_taps[i] * correction;
|
||||
}
|
||||
|
||||
float* delayBuf = new float[tapCount];
|
||||
|
||||
float* delayStart = &inBuf[std::max<int>(inCount - tapCount, 0)];
|
||||
@@ -510,26 +519,23 @@ namespace dsp {
|
||||
float* delayBufEnd = &delayBuf[std::max<int>(tapCount - inCount, 0)];
|
||||
int moveSize = std::min<int>(inCount, tapCount - inCount) * sizeof(float);
|
||||
int inSize = inCount * sizeof(float);
|
||||
|
||||
int interp = _this->_interp;
|
||||
int decim = _this->_decim;
|
||||
|
||||
float correction = (float)sqrt((float)interp);
|
||||
|
||||
int afterInterp = inCount * interp;
|
||||
int outIndex = 0;
|
||||
while (true) {
|
||||
if (_this->_input->read(inBuf, inCount) < 0) { break; };
|
||||
|
||||
|
||||
for (int i = 0; outIndex < outCount; i += decim) {
|
||||
outBuf[outIndex] = 0;
|
||||
for (int j = 0; j < tapCount; j++) {
|
||||
if ((i - j) % interp != 0) {
|
||||
continue;
|
||||
}
|
||||
outBuf[outIndex] += GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp) * taps[j] * correction;
|
||||
for (int j = (i % interp); j < tapCount; j += interp) {
|
||||
outBuf[outIndex] += GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp) * taps[j];
|
||||
}
|
||||
outIndex++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
outIndex = 0;
|
||||
if (tapCount > inCount) {
|
||||
memmove(delayBuf, delayBufEnd, moveSize);
|
||||
|
@@ -76,18 +76,19 @@ namespace dsp {
|
||||
bool running = false;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class DynamicSplitter {
|
||||
public:
|
||||
DynamicSplitter() {
|
||||
|
||||
}
|
||||
|
||||
DynamicSplitter(stream<complex_t>* input, int bufferSize) {
|
||||
DynamicSplitter(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;
|
||||
}
|
||||
@@ -128,14 +129,14 @@ namespace dsp {
|
||||
}
|
||||
}
|
||||
|
||||
void bind(stream<complex_t>* stream) {
|
||||
void bind(stream<T>* stream) {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
outputs.push_back(stream);
|
||||
}
|
||||
|
||||
void unbind(stream<complex_t>* stream) {
|
||||
void unbind(stream<T>* stream) {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
@@ -150,7 +151,7 @@ namespace dsp {
|
||||
|
||||
private:
|
||||
static void _worker(DynamicSplitter* _this) {
|
||||
complex_t* buf = new complex_t[_this->_bufferSize];
|
||||
T* buf = new T[_this->_bufferSize];
|
||||
int outputCount = _this->outputs.size();
|
||||
while (true) {
|
||||
if (_this->_in->read(buf, _this->_bufferSize) < 0) { break; };
|
||||
@@ -161,10 +162,146 @@ namespace dsp {
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
stream<complex_t>* _in;
|
||||
stream<T>* _in;
|
||||
int _bufferSize;
|
||||
std::thread _workerThread;
|
||||
bool running = false;
|
||||
std::vector<stream<T>*> outputs;
|
||||
};
|
||||
|
||||
|
||||
class MonoToStereo {
|
||||
public:
|
||||
MonoToStereo() {
|
||||
|
||||
}
|
||||
|
||||
MonoToStereo(stream<float>* input, int bufferSize) {
|
||||
_in = input;
|
||||
_bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
void init(stream<float>* input, int bufferSize) {
|
||||
_in = input;
|
||||
_bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
void start() {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
_workerThread = std::thread(_worker, this);
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
if (!running) {
|
||||
return;
|
||||
}
|
||||
_in->stopReader();
|
||||
output.stopWriter();
|
||||
_workerThread.join();
|
||||
_in->clearReadStop();
|
||||
output.clearWriteStop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
void setBlockSize(int blockSize) {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
_bufferSize = blockSize;
|
||||
output.setMaxLatency(blockSize * 2);
|
||||
}
|
||||
|
||||
stream<StereoFloat_t> output;
|
||||
|
||||
private:
|
||||
static void _worker(MonoToStereo* _this) {
|
||||
float* inBuf = new float[_this->_bufferSize];
|
||||
StereoFloat_t* outBuf = new StereoFloat_t[_this->_bufferSize];
|
||||
while (true) {
|
||||
if (_this->_in->read(inBuf, _this->_bufferSize) < 0) { break; };
|
||||
for (int i = 0; i < _this->_bufferSize; i++) {
|
||||
outBuf[i].l = inBuf[i];
|
||||
outBuf[i].r = inBuf[i];
|
||||
}
|
||||
if (_this->output.write(outBuf, _this->_bufferSize) < 0) { break; };
|
||||
}
|
||||
delete[] inBuf;
|
||||
delete[] outBuf;
|
||||
}
|
||||
|
||||
stream<float>* _in;
|
||||
int _bufferSize;
|
||||
std::thread _workerThread;
|
||||
bool running = false;
|
||||
};
|
||||
|
||||
class StereoToMono {
|
||||
public:
|
||||
StereoToMono() {
|
||||
|
||||
}
|
||||
|
||||
StereoToMono(stream<StereoFloat_t>* input, int bufferSize) {
|
||||
_in = input;
|
||||
_bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
void init(stream<StereoFloat_t>* input, int bufferSize) {
|
||||
_in = input;
|
||||
_bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
void start() {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
_workerThread = std::thread(_worker, this);
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
if (!running) {
|
||||
return;
|
||||
}
|
||||
_in->stopReader();
|
||||
output.stopWriter();
|
||||
_workerThread.join();
|
||||
_in->clearReadStop();
|
||||
output.clearWriteStop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
void setBlockSize(int blockSize) {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
_bufferSize = blockSize;
|
||||
output.setMaxLatency(blockSize * 2);
|
||||
}
|
||||
|
||||
stream<float> output;
|
||||
|
||||
private:
|
||||
static void _worker(StereoToMono* _this) {
|
||||
StereoFloat_t* inBuf = new StereoFloat_t[_this->_bufferSize];
|
||||
float* outBuf = new float[_this->_bufferSize];
|
||||
while (true) {
|
||||
if (_this->_in->read(inBuf, _this->_bufferSize) < 0) { break; };
|
||||
for (int i = 0; i < _this->_bufferSize; i++) {
|
||||
outBuf[i] = (inBuf[i].l + inBuf[i].r) / 2.0f;
|
||||
}
|
||||
if (_this->output.write(outBuf, _this->_bufferSize) < 0) { break; };
|
||||
}
|
||||
delete[] inBuf;
|
||||
delete[] outBuf;
|
||||
}
|
||||
|
||||
stream<StereoFloat_t>* _in;
|
||||
int _bufferSize;
|
||||
std::thread _workerThread;
|
||||
bool running = false;
|
||||
std::vector<stream<complex_t>*> outputs;
|
||||
};
|
||||
};
|
@@ -5,4 +5,9 @@ namespace dsp {
|
||||
float q;
|
||||
float i;
|
||||
};
|
||||
|
||||
struct StereoFloat_t {
|
||||
float l;
|
||||
float r;
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user