mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-11-13 22:12:51 +01:00
Bug fix in resampler
This commit is contained in:
parent
355a348ba0
commit
f1fd6fce7a
@ -12,16 +12,12 @@ else()
|
|||||||
link_libraries(pthread)
|
link_libraries(pthread)
|
||||||
link_libraries(GL)
|
link_libraries(GL)
|
||||||
link_libraries(GLEW)
|
link_libraries(GLEW)
|
||||||
|
|
||||||
# GLFW3
|
|
||||||
link_libraries(glfw)
|
link_libraries(glfw)
|
||||||
|
|
||||||
# FFTW3
|
|
||||||
link_libraries(fftw3)
|
link_libraries(fftw3)
|
||||||
link_libraries(fftw3f)
|
link_libraries(fftw3f)
|
||||||
|
|
||||||
# PortAudio
|
|
||||||
link_libraries(portaudio)
|
link_libraries(portaudio)
|
||||||
|
link_libraries(X11)
|
||||||
|
link_libraries(Xxf86vm)
|
||||||
endif (MSVC)
|
endif (MSVC)
|
||||||
|
|
||||||
link_libraries(volk)
|
link_libraries(volk)
|
||||||
|
@ -310,49 +310,53 @@ namespace dsp {
|
|||||||
complex_t* inBuf = new complex_t[_this->_blockSize];
|
complex_t* inBuf = new complex_t[_this->_blockSize];
|
||||||
complex_t* outBuf = new complex_t[_this->outputBlockSize];
|
complex_t* outBuf = new complex_t[_this->outputBlockSize];
|
||||||
|
|
||||||
|
int inCount = _this->_blockSize;
|
||||||
int outCount = _this->outputBlockSize;
|
int outCount = _this->outputBlockSize;
|
||||||
|
|
||||||
printf("%d %d\n", _this->_blockSize, _this->outputBlockSize);
|
|
||||||
|
|
||||||
float* taps = _this->_taps.data();
|
float* taps = _this->_taps.data();
|
||||||
int tapCount = _this->_taps.size();
|
int tapCount = _this->_taps.size();
|
||||||
complex_t* delayBuf = new complex_t[tapCount];
|
complex_t* delayBuf = new complex_t[tapCount];
|
||||||
|
|
||||||
complex_t* delayStart = &inBuf[_this->_blockSize - tapCount];
|
complex_t* delayStart = &inBuf[std::max<int>(inCount - tapCount, 0)];
|
||||||
int delaySize = tapCount * sizeof(complex_t);
|
int delaySize = tapCount * sizeof(complex_t);
|
||||||
|
complex_t* delayBufEnd = &delayBuf[std::max<int>(tapCount - inCount, 0)];
|
||||||
|
int moveSize = (tapCount - inCount) * sizeof(complex_t);
|
||||||
|
int inSize = inCount * sizeof(complex_t);
|
||||||
|
|
||||||
int interp = _this->_interp;
|
int interp = _this->_interp;
|
||||||
int decim = _this->_decim;
|
int decim = _this->_decim;
|
||||||
|
|
||||||
float correction = (float)sqrt((float)interp);
|
float correction = (float)sqrt((float)interp);
|
||||||
|
|
||||||
int afterInterp = _this->_blockSize * interp;
|
printf("Resamp: %d %d", inCount, _this->outputBlockSize);
|
||||||
|
|
||||||
|
int afterInterp = inCount * interp;
|
||||||
int outIndex = 0;
|
int outIndex = 0;
|
||||||
|
|
||||||
complex_t val;
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (_this->_input->read(inBuf, _this->_blockSize) < 0) { break; };
|
if (_this->_input->read(inBuf, inCount) < 0) { break; };
|
||||||
for (int i = 0; outIndex < outCount; i += decim) {
|
for (int i = 0; outIndex < outCount; i += decim) {
|
||||||
outBuf[outIndex].q = 0;
|
|
||||||
outBuf[outIndex].i = 0;
|
outBuf[outIndex].i = 0;
|
||||||
|
outBuf[outIndex].q = 0;
|
||||||
for (int j = 0; j < tapCount; j++) {
|
for (int j = 0; j < tapCount; j++) {
|
||||||
if ((i - j) % interp != 0) {
|
if ((i - j) % interp != 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
val = GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp);
|
outBuf[outIndex].i += GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp).i * taps[j] * correction;
|
||||||
outBuf[outIndex].i += val.i * taps[j] * correction;
|
outBuf[outIndex].q += GET_FROM_RIGHT_BUF(inBuf, delayBuf, tapCount, (i - j) / interp).q * taps[j] * correction;
|
||||||
outBuf[outIndex].q += val.q * taps[j] * correction;
|
|
||||||
}
|
}
|
||||||
outIndex++;
|
outIndex++;
|
||||||
}
|
}
|
||||||
outIndex = 0;
|
outIndex = 0;
|
||||||
|
if (tapCount > inCount) {
|
||||||
|
memmove(delayBuf, delayBufEnd, moveSize);
|
||||||
|
memcpy(delayBufEnd, delayStart, inSize);
|
||||||
|
}
|
||||||
|
else {
|
||||||
memcpy(delayBuf, delayStart, delaySize);
|
memcpy(delayBuf, delayStart, delaySize);
|
||||||
if (_this->output.write(outBuf, _this->outputBlockSize) < 0) { break; };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("DEBUG: %d\n", delaySize);
|
if (_this->output.write(outBuf, _this->outputBlockSize) < 0) { break; };
|
||||||
|
}
|
||||||
delete[] inBuf;
|
delete[] inBuf;
|
||||||
delete[] outBuf;
|
delete[] outBuf;
|
||||||
delete[] delayBuf;
|
delete[] delayBuf;
|
||||||
@ -500,26 +504,30 @@ namespace dsp {
|
|||||||
float* inBuf = new float[_this->_blockSize];
|
float* inBuf = new float[_this->_blockSize];
|
||||||
float* outBuf = new float[_this->outputBlockSize];
|
float* outBuf = new float[_this->outputBlockSize];
|
||||||
|
|
||||||
|
int inCount = _this->_blockSize;
|
||||||
int outCount = _this->outputBlockSize;
|
int outCount = _this->outputBlockSize;
|
||||||
|
|
||||||
float* taps = _this->_taps.data();
|
float* taps = _this->_taps.data();
|
||||||
int tapCount = _this->_taps.size();
|
int tapCount = _this->_taps.size();
|
||||||
float* delayBuf = new float[tapCount];
|
float* delayBuf = new float[tapCount];
|
||||||
|
|
||||||
float* delayStart = &inBuf[_this->_blockSize - tapCount];
|
float* delayStart = &inBuf[std::max<int>(inCount - tapCount, 0)];
|
||||||
int delaySize = tapCount * sizeof(float);
|
int delaySize = tapCount * sizeof(float);
|
||||||
|
float* delayBufEnd = &delayBuf[std::max<int>(tapCount - inCount, 0)];
|
||||||
|
int moveSize = (tapCount - inCount) * sizeof(float);
|
||||||
|
int inSize = inCount * sizeof(float);
|
||||||
|
|
||||||
int interp = _this->_interp;
|
int interp = _this->_interp;
|
||||||
int decim = _this->_decim;
|
int decim = _this->_decim;
|
||||||
|
|
||||||
float correction = (float)sqrt((float)interp);
|
float correction = (float)sqrt((float)interp);
|
||||||
|
|
||||||
printf("FloatResamp: %d %d", _this->_blockSize, _this->outputBlockSize);
|
printf("FloatResamp: %d %d", inCount, _this->outputBlockSize);
|
||||||
|
|
||||||
int afterInterp = _this->_blockSize * interp;
|
int afterInterp = inCount * interp;
|
||||||
int outIndex = 0;
|
int outIndex = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (_this->_input->read(inBuf, _this->_blockSize) < 0) { break; };
|
if (_this->_input->read(inBuf, inCount) < 0) { break; };
|
||||||
for (int i = 0; outIndex < outCount; i += decim) {
|
for (int i = 0; outIndex < outCount; i += decim) {
|
||||||
outBuf[outIndex] = 0;
|
outBuf[outIndex] = 0;
|
||||||
for (int j = 0; j < tapCount; j++) {
|
for (int j = 0; j < tapCount; j++) {
|
||||||
@ -531,7 +539,14 @@ namespace dsp {
|
|||||||
outIndex++;
|
outIndex++;
|
||||||
}
|
}
|
||||||
outIndex = 0;
|
outIndex = 0;
|
||||||
|
if (tapCount > inCount) {
|
||||||
|
memmove(delayBuf, delayBufEnd, moveSize);
|
||||||
|
memcpy(delayBufEnd, delayStart, inSize);
|
||||||
|
}
|
||||||
|
else {
|
||||||
memcpy(delayBuf, delayStart, delaySize);
|
memcpy(delayBuf, delayStart, delaySize);
|
||||||
|
}
|
||||||
|
|
||||||
if (_this->output.write(outBuf, _this->outputBlockSize) < 0) { break; };
|
if (_this->output.write(outBuf, _this->outputBlockSize) < 0) { break; };
|
||||||
}
|
}
|
||||||
delete[] inBuf;
|
delete[] inBuf;
|
||||||
@ -551,13 +566,4 @@ namespace dsp {
|
|||||||
int _blockSize;
|
int _blockSize;
|
||||||
bool running = false;
|
bool running = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user