diff --git a/core/src/dsp/buffer.h b/core/src/dsp/buffer.h index eb376778..c8c5b1a7 100644 --- a/core/src/dsp/buffer.h +++ b/core/src/dsp/buffer.h @@ -1,7 +1,7 @@ #pragma once #include -#define RING_BUF_SZ +#define RING_BUF_SZ 1000000 namespace dsp { template diff --git a/core/src/dsp/demodulator.h b/core/src/dsp/demodulator.h index 5bc8361b..c2914a95 100644 --- a/core/src/dsp/demodulator.h +++ b/core/src/dsp/demodulator.h @@ -1,6 +1,8 @@ #pragma once #include +#include + #define FAST_ATAN2_COEF1 FL_M_PI / 4.0f #define FAST_ATAN2_COEF2 3.0f * FAST_ATAN2_COEF1 diff --git a/core/src/dsp/filter.h b/core/src/dsp/filter.h index f9077d5b..e530b295 100644 --- a/core/src/dsp/filter.h +++ b/core/src/dsp/filter.h @@ -2,6 +2,8 @@ #include #include +#include + namespace dsp { template @@ -133,8 +135,9 @@ namespace dsp { count = _in->read(); if (count < 0) { return -1; } - if (bypass) { - if (out.aquire() < 0) { return -1; } + if (bypass || true) { + if (out.aquire() < 0) { return -1; } + memcpy(out.data, _in->data, count * sizeof(float)); _in->flush(); out.write(count); } diff --git a/core/src/dsp/processing.h b/core/src/dsp/processing.h index b066c3bb..2574ddbf 100644 --- a/core/src/dsp/processing.h +++ b/core/src/dsp/processing.h @@ -1,6 +1,8 @@ #pragma once #include +#include + namespace dsp { class FrequencyXlator : public generic_block { public: diff --git a/core/src/dsp/resampling.h b/core/src/dsp/resampling.h index 338ea82e..02da3c26 100644 --- a/core/src/dsp/resampling.h +++ b/core/src/dsp/resampling.h @@ -23,19 +23,19 @@ namespace dsp { _inSampleRate = inSampleRate; _outSampleRate = outSampleRate; + int _gcd = std::gcd((int)_inSampleRate, (int)_outSampleRate); + _interp = _outSampleRate / _gcd; + _decim = _inSampleRate / _gcd; + tapCount = _window->getTapCount(); taps = (float*)volk_malloc(tapCount * sizeof(float), volk_get_alignment()); _window->createTaps(taps, tapCount); for (int i = 0; i < tapCount / 2; i++) { float tap = taps[tapCount - i - 1]; - taps[tapCount - i - 1] = taps[i]; - taps[i] = tap; + taps[tapCount - i - 1] = taps[i] * (float)_interp; + taps[i] = tap * (float)_interp; } - int _gcd = std::gcd((int)_inSampleRate, (int)_outSampleRate); - _interp = _outSampleRate / _gcd; - _decim = _inSampleRate / _gcd; - buffer = (T*)volk_malloc(STREAM_BUFFER_SIZE * sizeof(T) * 2, volk_get_alignment()); bufStart = &buffer[tapCount]; generic_block>::registerInput(_in); @@ -80,6 +80,8 @@ namespace dsp { } void updateWindow(dsp::filter_window::generic_window* window) { + std::lock_guard lck(generic_block>::ctrlMtx); + generic_block>::tempStop(); _window = window; volk_free(taps); tapCount = window->getTapCount(); @@ -87,9 +89,10 @@ namespace dsp { window->createTaps(taps, tapCount); for (int i = 0; i < tapCount / 2; i++) { float tap = taps[tapCount - i - 1]; - taps[tapCount - i - 1] = taps[i]; - taps[i] = tap; + taps[tapCount - i - 1] = taps[i] * (float)_interp; + taps[i] = tap * (float)_interp; } + generic_block>::tempStart(); } int calcOutSize(int in) { @@ -97,10 +100,8 @@ namespace dsp { } int run() { - if constexpr (std::is_same_v) { spdlog::warn("--------- RESAMP START --------"); } count = _in->read(); if (count < 0) { - if constexpr (std::is_same_v) { spdlog::warn("--------- RESAMP STOP --------"); } return -1; } @@ -114,16 +115,21 @@ namespace dsp { return -1; } int outIndex = 0; - if constexpr (std::is_same_v) { - for (int i = 0; outIndex < outCount; i += _decim) { - out.data[outIndex] = 0; - for (int j = i % _interp; j < tapCount; j += _interp) { - out.data[outIndex] += buffer[((i - j) / _interp) + tapCount] * taps[j]; - } - outIndex++; - } - } + // if constexpr (std::is_same_v) { + // // for (int i = 0; outIndex < outCount; i += _decim) { + // // out.data[outIndex] = 0; + // // for (int j = i % _interp; j < tapCount; j += _interp) { + // // out.data[outIndex] += buffer[((i - j) / _interp) + tapCount] * taps[j]; + // // } + // // outIndex++; + // // } + // for (int i = 0; i < outCount; i++) { + // out.data[i] = 1.0f; + // } + // } if constexpr (std::is_same_v) { + static_assert(std::is_same_v); + spdlog::warn("{0}", outCount); for (int i = 0; outIndex < outCount; i += _decim) { out.data[outIndex].i = 0; out.data[outIndex].q = 0; @@ -134,7 +140,7 @@ namespace dsp { outIndex++; } } - out.write(count); + out.write(outCount); memmove(buffer, &buffer[count], tapCount * sizeof(T)); diff --git a/core/src/dsp/routing.h b/core/src/dsp/routing.h index 64302ac5..42e0f616 100644 --- a/core/src/dsp/routing.h +++ b/core/src/dsp/routing.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace dsp { template diff --git a/core/src/dsp/sink.h b/core/src/dsp/sink.h index 868b2cec..c7e0ac44 100644 --- a/core/src/dsp/sink.h +++ b/core/src/dsp/sink.h @@ -63,6 +63,7 @@ namespace dsp { void init(stream* in) { _in = in; + data.init(480); // TODO: Use an argument generic_block>::registerInput(_in); } diff --git a/core/src/io/audio.h b/core/src/io/audio.h index e6fd495a..09be58ad 100644 --- a/core/src/io/audio.h +++ b/core/src/io/audio.h @@ -28,62 +28,17 @@ namespace io { } - AudioSink(int bufferSize) { - _bufferSize = bufferSize; - monoBuffer = new float[_bufferSize]; - stereoBuffer = new dsp::stereo_t[_bufferSize]; - _volume = 1.0f; - Pa_Initialize(); - - devTxtList = ""; - int devCount = Pa_GetDeviceCount(); - devIndex = Pa_GetDefaultOutputDevice(); - const PaDeviceInfo *deviceInfo; - PaStreamParameters outputParams; - outputParams.sampleFormat = paFloat32; - outputParams.hostApiSpecificStreamInfo = NULL; - for(int i = 0; i < devCount; i++) { - deviceInfo = Pa_GetDeviceInfo(i); - if (deviceInfo->maxOutputChannels < 1) { - continue; - } - AudioDevice_t dev; - dev.name = deviceInfo->name; - dev.index = i; - dev.channels = std::min(deviceInfo->maxOutputChannels, 2); - dev.sampleRates.clear(); - dev.txtSampleRates = ""; - for (int j = 0; j < 6; j++) { - outputParams.channelCount = dev.channels; - outputParams.device = dev.index; - outputParams.suggestedLatency = deviceInfo->defaultLowOutputLatency; - PaError err = Pa_IsFormatSupported(NULL, &outputParams, POSSIBLE_SAMP_RATE[j]); - if (err != paFormatIsSupported) { - continue; - } - dev.sampleRates.push_back(POSSIBLE_SAMP_RATE[j]); - dev.txtSampleRates += std::to_string((int)POSSIBLE_SAMP_RATE[j]); - dev.txtSampleRates += '\0'; - } - if (dev.sampleRates.size() == 0) { - continue; - } - if (i == devIndex) { - devListIndex = devices.size(); - defaultDev = devListIndex; - } - devices.push_back(dev); - deviceNames.push_back(deviceInfo->name); - devTxtList += deviceInfo->name; - devTxtList += '\0'; - } - } + AudioSink(int bufferSize) { init(bufferSize); } void init(int bufferSize) { _bufferSize = bufferSize; monoBuffer = new float[_bufferSize]; stereoBuffer = new dsp::stereo_t[_bufferSize]; _volume = 1.0f; + + monoSink.init(&monoDummy); + stereoSink.init(&stereoDummy); + Pa_Initialize(); devTxtList = ""; @@ -343,6 +298,8 @@ namespace io { int defaultDev; double _sampleRate; int _bufferSize; + dsp::stream monoDummy; + dsp::stream stereoDummy; dsp::RingBufferSink monoSink; dsp::RingBufferSink stereoSink; float* monoBuffer; diff --git a/radio/src/path.cpp b/radio/src/path.cpp index c2a982ae..2bcd298b 100644 --- a/radio/src/path.cpp +++ b/radio/src/path.cpp @@ -286,5 +286,6 @@ void SigPath::start() { demod.start(); audioResamp.start(); deemp.start(); + //ns.start(); audio::startStream(vfoName); } \ No newline at end of file diff --git a/radio/src/path.h b/radio/src/path.h index 21e6a257..5b21c098 100644 --- a/radio/src/path.h +++ b/radio/src/path.h @@ -63,6 +63,8 @@ private: dsp::filter_window::BlackmanWindow audioWin; dsp::PolyphaseResampler audioResamp; + dsp::NullSink ns; + std::string vfoName; float sampleRate; diff --git a/root_dev/config.json b/root_dev/config.json index 703ab607..8f687bdc 100644 --- a/root_dev/config.json +++ b/root_dev/config.json @@ -3,7 +3,7 @@ "Radio": { "device": "default", "sampleRate": 48000.0, - "volume": 0.0 + "volume": 1.0 }, "Radio 1": { "device": "Speakers (Realtek High Definition Audio)", @@ -18,7 +18,7 @@ }, "bandPlan": "General", "bandPlanEnabled": true, - "fftHeight": 298, + "fftHeight": 296, "frequency": 99000000, "max": 0.0, "maximized": false, diff --git a/root_dev/recordings/audio_19-16-25_02-11-2020.wav b/root_dev/recordings/audio_19-16-25_02-11-2020.wav new file mode 100644 index 00000000..578536fb Binary files /dev/null and b/root_dev/recordings/audio_19-16-25_02-11-2020.wav differ diff --git a/root_dev/recordings/audio_20-21-27_02-11-2020.wav b/root_dev/recordings/audio_20-21-27_02-11-2020.wav new file mode 100644 index 00000000..74d9a1c1 Binary files /dev/null and b/root_dev/recordings/audio_20-21-27_02-11-2020.wav differ diff --git a/root_dev/recordings/audio_20-21-55_02-11-2020.wav b/root_dev/recordings/audio_20-21-55_02-11-2020.wav new file mode 100644 index 00000000..3abba16f Binary files /dev/null and b/root_dev/recordings/audio_20-21-55_02-11-2020.wav differ diff --git a/root_dev/recordings/baseband_20-21-19_02-11-2020.wav b/root_dev/recordings/baseband_20-21-19_02-11-2020.wav new file mode 100644 index 00000000..89730c67 Binary files /dev/null and b/root_dev/recordings/baseband_20-21-19_02-11-2020.wav differ