Fixed DSP

This commit is contained in:
Ryzerth 2020-11-04 00:42:39 +01:00
parent 5d320fdd53
commit 3156236745
10 changed files with 25 additions and 34 deletions

View File

@ -37,7 +37,7 @@ namespace dsp {
_in = in; _in = in;
_sampleRate = sampleRate; _sampleRate = sampleRate;
_deviation = deviation; _deviation = deviation;
phasorSpeed = (_sampleRate / _deviation) / (2 * FL_M_PI); phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
generic_block<FMDemod>::registerInput(_in); generic_block<FMDemod>::registerInput(_in);
generic_block<FMDemod>::registerOutput(&out); generic_block<FMDemod>::registerOutput(&out);
} }
@ -55,7 +55,7 @@ namespace dsp {
std::lock_guard<std::mutex> lck(generic_block<FMDemod>::ctrlMtx); std::lock_guard<std::mutex> lck(generic_block<FMDemod>::ctrlMtx);
generic_block<FMDemod>::tempStop(); generic_block<FMDemod>::tempStop();
_sampleRate = sampleRate; _sampleRate = sampleRate;
phasorSpeed = (_sampleRate / _deviation) / (2 * FL_M_PI); phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
generic_block<FMDemod>::tempStart(); generic_block<FMDemod>::tempStart();
} }
@ -67,7 +67,7 @@ namespace dsp {
std::lock_guard<std::mutex> lck(generic_block<FMDemod>::ctrlMtx); std::lock_guard<std::mutex> lck(generic_block<FMDemod>::ctrlMtx);
generic_block<FMDemod>::tempStop(); generic_block<FMDemod>::tempStop();
_deviation = deviation; _deviation = deviation;
phasorSpeed = (_sampleRate / _deviation) / (2 * FL_M_PI); phasorSpeed = (2 * FL_M_PI) / (_sampleRate / _deviation);
generic_block<FMDemod>::tempStart(); generic_block<FMDemod>::tempStart();
} }
@ -87,8 +87,9 @@ namespace dsp {
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
currentPhase = fast_arctan2(_in->data[i].i, _in->data[i].q); currentPhase = fast_arctan2(_in->data[i].i, _in->data[i].q);
diff = currentPhase - phase; diff = currentPhase - phase;
if (diff > FL_M_PI) { out.data[i] = (diff - 2 * FL_M_PI) * phasorSpeed; } if (diff > 3.1415926535f) { diff -= 2 * 3.1415926535f; }
else if (diff <= -FL_M_PI) { out.data[i] = (diff + 2 * FL_M_PI) * phasorSpeed; } else if (diff <= -3.1415926535f) { diff += 2 * 3.1415926535f; }
out.data[i] = diff / phasorSpeed;
phase = currentPhase; phase = currentPhase;
} }

View File

@ -135,11 +135,12 @@ namespace dsp {
count = _in->read(); count = _in->read();
if (count < 0) { return -1; } if (count < 0) { return -1; }
if (bypass || true) { if (bypass) {
if (out.aquire() < 0) { return -1; } if (out.aquire() < 0) { return -1; }
memcpy(out.data, _in->data, count * sizeof(float)); memcpy(out.data, _in->data, count * sizeof(float));
_in->flush(); _in->flush();
out.write(count); out.write(count);
return count;
} }
if (isnan(lastOut)) { if (isnan(lastOut)) {

View File

@ -29,14 +29,10 @@ namespace dsp {
tapCount = _window->getTapCount(); tapCount = _window->getTapCount();
taps = (float*)volk_malloc(tapCount * sizeof(float), volk_get_alignment()); taps = (float*)volk_malloc(tapCount * sizeof(float), volk_get_alignment());
_window->createTaps(taps, tapCount); _window->createTaps(taps, tapCount, _interp);
for (int i = 0; i < tapCount / 2; i++) {
float tap = taps[tapCount - i - 1];
taps[tapCount - i - 1] = taps[i] * (float)_interp;
taps[i] = tap * (float)_interp;
}
buffer = (T*)volk_malloc(STREAM_BUFFER_SIZE * sizeof(T) * 2, volk_get_alignment()); buffer = (T*)volk_malloc(STREAM_BUFFER_SIZE * sizeof(T) * 2, volk_get_alignment());
memset(buffer, 0, STREAM_BUFFER_SIZE * sizeof(T) * 2);
bufStart = &buffer[tapCount]; bufStart = &buffer[tapCount];
generic_block<PolyphaseResampler<T>>::registerInput(_in); generic_block<PolyphaseResampler<T>>::registerInput(_in);
generic_block<PolyphaseResampler<T>>::registerOutput(&out); generic_block<PolyphaseResampler<T>>::registerOutput(&out);
@ -86,12 +82,7 @@ namespace dsp {
volk_free(taps); volk_free(taps);
tapCount = window->getTapCount(); tapCount = window->getTapCount();
taps = (float*)volk_malloc(tapCount * sizeof(float), volk_get_alignment()); taps = (float*)volk_malloc(tapCount * sizeof(float), volk_get_alignment());
window->createTaps(taps, tapCount); window->createTaps(taps, tapCount, _interp);
for (int i = 0; i < tapCount / 2; i++) {
float tap = taps[tapCount - i - 1];
taps[tapCount - i - 1] = taps[i] * (float)_interp;
taps[i] = tap * (float)_interp;
}
bufStart = &buffer[tapCount]; bufStart = &buffer[tapCount];
generic_block<PolyphaseResampler<T>>::tempStart(); generic_block<PolyphaseResampler<T>>::tempStart();
} }
@ -117,9 +108,6 @@ namespace dsp {
} }
int outIndex = 0; int outIndex = 0;
if constexpr (std::is_same_v<T, float>) { if constexpr (std::is_same_v<T, float>) {
for (int i = 0; i < count; i++) {
buffer[tapCount + i] = 1.0f;
}
for (int i = 0; outIndex < outCount; i += _decim) { for (int i = 0; outIndex < outCount; i += _decim) {
out.data[outIndex] = 0; out.data[outIndex] = 0;
for (int j = i % _interp; j < tapCount; j += _interp) { for (int j = i % _interp; j < tapCount; j += _interp) {

View File

@ -6,7 +6,7 @@ namespace dsp {
class generic_window { class generic_window {
public: public:
virtual int getTapCount() { return -1; } virtual int getTapCount() { return -1; }
virtual void createTaps(float* taps, int tapCount) {} virtual void createTaps(float* taps, int tapCount, float factor = 1.0f) {}
}; };
class BlackmanWindow : public filter_window::generic_window { class BlackmanWindow : public filter_window::generic_window {
@ -48,7 +48,7 @@ namespace dsp {
return _M; return _M;
} }
void createTaps(float* taps, int tapCount) { void createTaps(float* taps, int tapCount, float factor = 1.0f) {
float fc = _cutoff / _sampleRate; float fc = _cutoff / _sampleRate;
if (fc > 1.0f) { if (fc > 1.0f) {
fc = 1.0f; fc = 1.0f;
@ -59,10 +59,11 @@ namespace dsp {
for (int i = 0; i < tapCount; i++) { for (int i = 0; i < tapCount; i++) {
val = (sin(2.0f * FL_M_PI * fc * ((float)i - (tc / 2))) / ((float)i - (tc / 2))) * val = (sin(2.0f * FL_M_PI * fc * ((float)i - (tc / 2))) / ((float)i - (tc / 2))) *
(0.42f - (0.5f * cos(2.0f * FL_M_PI / tc)) + (0.8f * cos(4.0f * FL_M_PI / tc))); (0.42f - (0.5f * cos(2.0f * FL_M_PI / tc)) + (0.8f * cos(4.0f * FL_M_PI / tc)));
taps[tapCount - i - 1] = val; // tapCount - i - 1 taps[i] = val; // tapCount - i - 1
sum += val; sum += val;
} }
for (int i = 0; i < tapCount; i++) { for (int i = 0; i < tapCount; i++) {
taps[i] *= factor;
taps[i] /= sum; taps[i] /= sum;
} }
} }

View File

@ -179,13 +179,13 @@ private:
while (true) { while (true) {
int count = _this->audioStream->read(); int count = _this->audioStream->read();
if (count < 0) { break; } if (count < 0) { break; }
for (int i = 0; i < 1024; i++) { for (int i = 0; i < 240; i++) {
sampleBuf[(i * 2) + 0] = _this->audioStream->data[i].l * 0x7FFF; sampleBuf[(i * 2) + 0] = _this->audioStream->data[i].l * 0x7FFF;
sampleBuf[(i * 2) + 1] = _this->audioStream->data[i].r * 0x7FFF; sampleBuf[(i * 2) + 1] = _this->audioStream->data[i].r * 0x7FFF;
} }
_this->audioStream->flush(); _this->audioStream->flush();
_this->samplesWritten += 1024; _this->samplesWritten += 240;
_this->writer->writeSamples(sampleBuf, 2048 * sizeof(int16_t)); _this->writer->writeSamples(sampleBuf, 480 * sizeof(int16_t));
} }
delete[] sampleBuf; delete[] sampleBuf;
} }

View File

@ -1,9 +1,9 @@
{ {
"audio": { "audio": {
"Radio": { "Radio": {
"device": "default", "device": "Speakers (Realtek High Definiti",
"sampleRate": 48000.0, "sampleRate": 48000.0,
"volume": 1.0 "volume": 0.51953125
}, },
"Radio 1": { "Radio 1": {
"device": "Speakers (Realtek High Definition Audio)", "device": "Speakers (Realtek High Definition Audio)",

View File

@ -1,6 +1,6 @@
{ {
"Radio": "./radio/RelWithDebInfo/radio.dll", "Radio": "./radio/Release/radio.dll",
"Recorder": "./recorder/RelWithDebInfo/recorder.dll", "Recorder": "./recorder/Release/recorder.dll",
"Soapy": "./soapy/RelWithDebInfo/soapy.dll", "Soapy": "./soapy/Release/soapy.dll",
"RTLTCPSource": "./rtl_tcp_source/RelWithDebInfo/rtl_tcp_source.dll" "RTLTCPSource": "./rtl_tcp_source/Release/rtl_tcp_source.dll"
} }

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,5 @@
{ {
"device": "Generic RTL2832U OEM :: 00000001", "device": "HackRF One #0 901868dc282c8f8b",
"devices": { "devices": {
"AirSpy HF+ [c852435de0224af7]": { "AirSpy HF+ [c852435de0224af7]": {
"gains": { "gains": {