mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2024-11-10 12:47:40 +01:00
finally fixed the waterfall7
This commit is contained in:
parent
3156236745
commit
ef968ac1fb
@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dsp/block.h>
|
#include <dsp/block.h>
|
||||||
|
#include <dsp/buffer.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <numeric>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace dsp {
|
namespace dsp {
|
||||||
@ -62,18 +64,22 @@ namespace dsp {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: I'm not proud of this, it's BAD and just taken from the previous DSP, but it works...
|
||||||
template <class T>
|
template <class T>
|
||||||
class Reshaper : public generic_block<Reshaper<T>> {
|
class Reshaper : public generic_block<Reshaper<T>> {
|
||||||
public:
|
public:
|
||||||
Reshaper() {}
|
Reshaper() {}
|
||||||
|
|
||||||
Reshaper(stream<T>* in) { init(in); }
|
Reshaper(stream<T>* in, int keep, int skip) { init(in, keep, skip); }
|
||||||
|
|
||||||
~Reshaper() { generic_block<Reshaper<T>>::stop(); }
|
~Reshaper() { generic_block<Reshaper<T>>::stop(); }
|
||||||
|
|
||||||
void init(stream<T>* in) {
|
void init(stream<T>* in, int keep, int skip) {
|
||||||
_in = in;
|
_in = in;
|
||||||
buffer = (T*)volk_malloc(STREAM_BUFFER_SIZE * sizeof(T), volk_get_alignment());
|
_keep = keep;
|
||||||
|
_skip = skip;
|
||||||
|
ringBuf.init(keep * 2);
|
||||||
generic_block<Reshaper<T>>::registerInput(_in);
|
generic_block<Reshaper<T>>::registerInput(_in);
|
||||||
generic_block<Reshaper<T>>::registerOutput(&out);
|
generic_block<Reshaper<T>>::registerOutput(&out);
|
||||||
}
|
}
|
||||||
@ -87,19 +93,92 @@ namespace dsp {
|
|||||||
generic_block<Reshaper<T>>::tempStart();
|
generic_block<Reshaper<T>>::tempStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setKeep(int keep) {
|
||||||
|
std::lock_guard<std::mutex> lck(generic_block<Reshaper<T>>::ctrlMtx);
|
||||||
|
generic_block<Reshaper<T>>::tempStop();
|
||||||
|
generic_block<Reshaper<T>>::unregisterInput(_in);
|
||||||
|
_keep = keep;
|
||||||
|
generic_block<Reshaper<T>>::registerInput(_in);
|
||||||
|
generic_block<Reshaper<T>>::tempStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setSkip(int skip) {
|
||||||
|
std::lock_guard<std::mutex> lck(generic_block<Reshaper<T>>::ctrlMtx);
|
||||||
|
generic_block<Reshaper<T>>::tempStop();
|
||||||
|
generic_block<Reshaper<T>>::unregisterInput(_in);
|
||||||
|
_skip = skip;
|
||||||
|
generic_block<Reshaper<T>>::registerInput(_in);
|
||||||
|
generic_block<Reshaper<T>>::tempStart();
|
||||||
|
}
|
||||||
|
|
||||||
int run() {
|
int run() {
|
||||||
int count = _in->read();
|
int count = _in->read();
|
||||||
|
if (count < 0) { return -1; }
|
||||||
|
ringBuf.write(_in->data, count);
|
||||||
_in->flush();
|
_in->flush();
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stream<T> out;
|
stream<T> out;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void doStart() {
|
||||||
|
workThread = std::thread(&Reshaper<T>::loop, this);
|
||||||
|
bufferWorkerThread = std::thread(&Reshaper<T>::bufferWorker, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
while (run() >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doStop() {
|
||||||
|
_in->stopReader();
|
||||||
|
ringBuf.stopReader();
|
||||||
|
out.stopWriter();
|
||||||
|
ringBuf.stopWriter();
|
||||||
|
|
||||||
|
if (workThread.joinable()) {
|
||||||
|
workThread.join();
|
||||||
|
}
|
||||||
|
if (bufferWorkerThread.joinable()) {
|
||||||
|
bufferWorkerThread.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
_in->clearReadStop();
|
||||||
|
ringBuf.clearReadStop();
|
||||||
|
out.clearWriteStop();
|
||||||
|
ringBuf.clearWriteStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void bufferWorker() {
|
||||||
|
complex_t* buf = new complex_t[_keep];
|
||||||
|
bool delay = _skip < 0;
|
||||||
|
|
||||||
|
int readCount = std::min<int>(_keep + _skip, _keep);
|
||||||
|
int skip = std::max<int>(_skip, 0);
|
||||||
|
int delaySize = (-_skip) * sizeof(complex_t);
|
||||||
|
|
||||||
|
complex_t* start = &buf[std::max<int>(-_skip, 0)];
|
||||||
|
complex_t* delayStart = &buf[_keep + _skip];
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
if (delay) {
|
||||||
|
memmove(buf, delayStart, delaySize);
|
||||||
|
}
|
||||||
|
if (ringBuf.readAndSkip(start, readCount, skip) < 0) { break; };
|
||||||
|
if (out.aquire() < 0) { break; }
|
||||||
|
memcpy(out.data, buf, _keep * sizeof(complex_t));
|
||||||
|
out.write(_keep);
|
||||||
|
}
|
||||||
|
delete[] buf;
|
||||||
|
}
|
||||||
|
|
||||||
stream<T>* _in;
|
stream<T>* _in;
|
||||||
T* buffer;
|
|
||||||
int _outBlockSize;
|
int _outBlockSize;
|
||||||
int readCount;
|
RingBuffer<T> ringBuf;
|
||||||
|
std::thread bufferWorkerThread;
|
||||||
|
std::thread workThread;
|
||||||
|
int _keep, _skip;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -48,6 +48,10 @@ int fftSize = 8192 * 8;
|
|||||||
std::vector<float> _data;
|
std::vector<float> _data;
|
||||||
std::vector<float> fftTaps;
|
std::vector<float> fftTaps;
|
||||||
void fftHandler(dsp::complex_t* samples, int count, void* ctx) {
|
void fftHandler(dsp::complex_t* samples, int count, void* ctx) {
|
||||||
|
if (count < fftSize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(fft_in, samples, count * sizeof(dsp::complex_t));
|
||||||
fftwf_execute(p);
|
fftwf_execute(p);
|
||||||
int half = fftSize / 2;
|
int half = fftSize / 2;
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ void SignalPath::init(uint64_t sampleRate, int fftRate, int fftSize, dsp::stream
|
|||||||
|
|
||||||
split.init(input);
|
split.init(input);
|
||||||
|
|
||||||
reshape.init(&fftStream);
|
reshape.init(&fftStream, fftSize, (sampleRate / fftRate) - fftSize);
|
||||||
|
split.bindStream(&fftStream);
|
||||||
fftHandlerSink.init(&reshape.out, fftHandler, NULL);
|
fftHandlerSink.init(&reshape.out, fftHandler, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,16 +21,14 @@ void SignalPath::setSampleRate(double sampleRate) {
|
|||||||
this->sampleRate = sampleRate;
|
this->sampleRate = sampleRate;
|
||||||
|
|
||||||
split.stop();
|
split.stop();
|
||||||
//fftBlockDec.stop();
|
|
||||||
//fftHandlerSink.stop();
|
|
||||||
|
|
||||||
for (auto const& [name, vfo] : vfos) {
|
for (auto const& [name, vfo] : vfos) {
|
||||||
vfo.vfo->stop();
|
vfo.vfo->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Claculate skip to maintain a constant fft rate
|
// Claculate skip to maintain a constant fft rate
|
||||||
//int skip = (sampleRate / fftRate) - fftSize;
|
int skip = (sampleRate / fftRate) - fftSize;
|
||||||
//fftBlockDec.setSkip(skip);
|
reshape.setSkip(skip);
|
||||||
|
|
||||||
// TODO: Tell modules that the block size has changed (maybe?)
|
// TODO: Tell modules that the block size has changed (maybe?)
|
||||||
|
|
||||||
@ -38,8 +37,6 @@ void SignalPath::setSampleRate(double sampleRate) {
|
|||||||
vfo.vfo->start();
|
vfo.vfo->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
//fftHandlerSink.start();
|
|
||||||
//fftBlockDec.start();
|
|
||||||
split.start();
|
split.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"Radio": {
|
"Radio": {
|
||||||
"device": "Speakers (Realtek High Definiti",
|
"device": "Speakers (Realtek High Definiti",
|
||||||
"sampleRate": 48000.0,
|
"sampleRate": 48000.0,
|
||||||
"volume": 0.51953125
|
"volume": 0.7265625
|
||||||
},
|
},
|
||||||
"Radio 1": {
|
"Radio 1": {
|
||||||
"device": "Speakers (Realtek High Definition Audio)",
|
"device": "Speakers (Realtek High Definition Audio)",
|
||||||
@ -32,7 +32,7 @@
|
|||||||
"Display"
|
"Display"
|
||||||
],
|
],
|
||||||
"menuWidth": 300,
|
"menuWidth": 300,
|
||||||
"min": -100.0,
|
"min": -52.20588302612305,
|
||||||
"showWaterfall": true,
|
"showWaterfall": true,
|
||||||
"source": "",
|
"source": "",
|
||||||
"sourceSettings": {},
|
"sourceSettings": {},
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -19,9 +19,9 @@
|
|||||||
},
|
},
|
||||||
"HackRF One #0 901868dc282c8f8b": {
|
"HackRF One #0 901868dc282c8f8b": {
|
||||||
"gains": {
|
"gains": {
|
||||||
"AMP": 13.86299991607666,
|
"AMP": 0.0,
|
||||||
"LNA": 24.711999893188477,
|
"LNA": 24.711999893188477,
|
||||||
"VGA": 14.282999992370605
|
"VGA": 16.02899932861328
|
||||||
},
|
},
|
||||||
"sampleRate": 8000000.0
|
"sampleRate": 8000000.0
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user