mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-02-09 07:38:43 +01:00
fixing audio bug
This commit is contained in:
parent
35c7f0e3cf
commit
cee6af1e14
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dsp/block.h>
|
#include <dsp/block.h>
|
||||||
|
|
||||||
#define RING_BUF_SZ
|
#define RING_BUF_SZ 1000000
|
||||||
|
|
||||||
namespace dsp {
|
namespace dsp {
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dsp/block.h>
|
#include <dsp/block.h>
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#define FAST_ATAN2_COEF1 FL_M_PI / 4.0f
|
#define FAST_ATAN2_COEF1 FL_M_PI / 4.0f
|
||||||
#define FAST_ATAN2_COEF2 3.0f * FAST_ATAN2_COEF1
|
#define FAST_ATAN2_COEF2 3.0f * FAST_ATAN2_COEF1
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include <dsp/block.h>
|
#include <dsp/block.h>
|
||||||
#include <dsp/window.h>
|
#include <dsp/window.h>
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace dsp {
|
namespace dsp {
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@ -133,8 +135,9 @@ namespace dsp {
|
|||||||
count = _in->read();
|
count = _in->read();
|
||||||
if (count < 0) { return -1; }
|
if (count < 0) { return -1; }
|
||||||
|
|
||||||
if (bypass) {
|
if (bypass || true) {
|
||||||
if (out.aquire() < 0) { return -1; }
|
if (out.aquire() < 0) { return -1; }
|
||||||
|
memcpy(out.data, _in->data, count * sizeof(float));
|
||||||
_in->flush();
|
_in->flush();
|
||||||
out.write(count);
|
out.write(count);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dsp/block.h>
|
#include <dsp/block.h>
|
||||||
|
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace dsp {
|
namespace dsp {
|
||||||
class FrequencyXlator : public generic_block<FrequencyXlator> {
|
class FrequencyXlator : public generic_block<FrequencyXlator> {
|
||||||
public:
|
public:
|
||||||
|
@ -23,19 +23,19 @@ namespace dsp {
|
|||||||
_inSampleRate = inSampleRate;
|
_inSampleRate = inSampleRate;
|
||||||
_outSampleRate = outSampleRate;
|
_outSampleRate = outSampleRate;
|
||||||
|
|
||||||
|
int _gcd = std::gcd((int)_inSampleRate, (int)_outSampleRate);
|
||||||
|
_interp = _outSampleRate / _gcd;
|
||||||
|
_decim = _inSampleRate / _gcd;
|
||||||
|
|
||||||
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);
|
||||||
for (int i = 0; i < tapCount / 2; i++) {
|
for (int i = 0; i < tapCount / 2; i++) {
|
||||||
float tap = taps[tapCount - i - 1];
|
float tap = taps[tapCount - i - 1];
|
||||||
taps[tapCount - i - 1] = taps[i];
|
taps[tapCount - i - 1] = taps[i] * (float)_interp;
|
||||||
taps[i] = tap;
|
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());
|
buffer = (T*)volk_malloc(STREAM_BUFFER_SIZE * sizeof(T) * 2, volk_get_alignment());
|
||||||
bufStart = &buffer[tapCount];
|
bufStart = &buffer[tapCount];
|
||||||
generic_block<PolyphaseResampler<T>>::registerInput(_in);
|
generic_block<PolyphaseResampler<T>>::registerInput(_in);
|
||||||
@ -80,6 +80,8 @@ namespace dsp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateWindow(dsp::filter_window::generic_window* window) {
|
void updateWindow(dsp::filter_window::generic_window* window) {
|
||||||
|
std::lock_guard<std::mutex> lck(generic_block<PolyphaseResampler<T>>::ctrlMtx);
|
||||||
|
generic_block<PolyphaseResampler<T>>::tempStop();
|
||||||
_window = window;
|
_window = window;
|
||||||
volk_free(taps);
|
volk_free(taps);
|
||||||
tapCount = window->getTapCount();
|
tapCount = window->getTapCount();
|
||||||
@ -87,9 +89,10 @@ namespace dsp {
|
|||||||
window->createTaps(taps, tapCount);
|
window->createTaps(taps, tapCount);
|
||||||
for (int i = 0; i < tapCount / 2; i++) {
|
for (int i = 0; i < tapCount / 2; i++) {
|
||||||
float tap = taps[tapCount - i - 1];
|
float tap = taps[tapCount - i - 1];
|
||||||
taps[tapCount - i - 1] = taps[i];
|
taps[tapCount - i - 1] = taps[i] * (float)_interp;
|
||||||
taps[i] = tap;
|
taps[i] = tap * (float)_interp;
|
||||||
}
|
}
|
||||||
|
generic_block<PolyphaseResampler<T>>::tempStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
int calcOutSize(int in) {
|
int calcOutSize(int in) {
|
||||||
@ -97,10 +100,8 @@ namespace dsp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int run() {
|
int run() {
|
||||||
if constexpr (std::is_same_v<T, float>) { spdlog::warn("--------- RESAMP START --------"); }
|
|
||||||
count = _in->read();
|
count = _in->read();
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
if constexpr (std::is_same_v<T, float>) { spdlog::warn("--------- RESAMP STOP --------"); }
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,16 +115,21 @@ namespace dsp {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
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; 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) {
|
||||||
out.data[outIndex] += buffer[((i - j) / _interp) + tapCount] * taps[j];
|
// // out.data[outIndex] += buffer[((i - j) / _interp) + tapCount] * taps[j];
|
||||||
}
|
// // }
|
||||||
outIndex++;
|
// // outIndex++;
|
||||||
}
|
// // }
|
||||||
}
|
// for (int i = 0; i < outCount; i++) {
|
||||||
|
// out.data[i] = 1.0f;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
if constexpr (std::is_same_v<T, complex_t>) {
|
if constexpr (std::is_same_v<T, complex_t>) {
|
||||||
|
static_assert(std::is_same_v<T, complex_t>);
|
||||||
|
spdlog::warn("{0}", outCount);
|
||||||
for (int i = 0; outIndex < outCount; i += _decim) {
|
for (int i = 0; outIndex < outCount; i += _decim) {
|
||||||
out.data[outIndex].i = 0;
|
out.data[outIndex].i = 0;
|
||||||
out.data[outIndex].q = 0;
|
out.data[outIndex].q = 0;
|
||||||
@ -134,7 +140,7 @@ namespace dsp {
|
|||||||
outIndex++;
|
outIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.write(count);
|
out.write(outCount);
|
||||||
|
|
||||||
memmove(buffer, &buffer[count], tapCount * sizeof(T));
|
memmove(buffer, &buffer[count], tapCount * sizeof(T));
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <dsp/block.h>
|
#include <dsp/block.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
namespace dsp {
|
namespace dsp {
|
||||||
template <class T>
|
template <class T>
|
||||||
|
@ -63,6 +63,7 @@ namespace dsp {
|
|||||||
|
|
||||||
void init(stream<T>* in) {
|
void init(stream<T>* in) {
|
||||||
_in = in;
|
_in = in;
|
||||||
|
data.init(480); // TODO: Use an argument
|
||||||
generic_block<RingBufferSink<T>>::registerInput(_in);
|
generic_block<RingBufferSink<T>>::registerInput(_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,62 +28,17 @@ namespace io {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioSink(int bufferSize) {
|
AudioSink(int bufferSize) { init(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<int>(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';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void init(int bufferSize) {
|
void init(int bufferSize) {
|
||||||
_bufferSize = bufferSize;
|
_bufferSize = bufferSize;
|
||||||
monoBuffer = new float[_bufferSize];
|
monoBuffer = new float[_bufferSize];
|
||||||
stereoBuffer = new dsp::stereo_t[_bufferSize];
|
stereoBuffer = new dsp::stereo_t[_bufferSize];
|
||||||
_volume = 1.0f;
|
_volume = 1.0f;
|
||||||
|
|
||||||
|
monoSink.init(&monoDummy);
|
||||||
|
stereoSink.init(&stereoDummy);
|
||||||
|
|
||||||
Pa_Initialize();
|
Pa_Initialize();
|
||||||
|
|
||||||
devTxtList = "";
|
devTxtList = "";
|
||||||
@ -343,6 +298,8 @@ namespace io {
|
|||||||
int defaultDev;
|
int defaultDev;
|
||||||
double _sampleRate;
|
double _sampleRate;
|
||||||
int _bufferSize;
|
int _bufferSize;
|
||||||
|
dsp::stream<float> monoDummy;
|
||||||
|
dsp::stream<dsp::stereo_t> stereoDummy;
|
||||||
dsp::RingBufferSink<float> monoSink;
|
dsp::RingBufferSink<float> monoSink;
|
||||||
dsp::RingBufferSink<dsp::stereo_t> stereoSink;
|
dsp::RingBufferSink<dsp::stereo_t> stereoSink;
|
||||||
float* monoBuffer;
|
float* monoBuffer;
|
||||||
|
@ -286,5 +286,6 @@ void SigPath::start() {
|
|||||||
demod.start();
|
demod.start();
|
||||||
audioResamp.start();
|
audioResamp.start();
|
||||||
deemp.start();
|
deemp.start();
|
||||||
|
//ns.start();
|
||||||
audio::startStream(vfoName);
|
audio::startStream(vfoName);
|
||||||
}
|
}
|
@ -63,6 +63,8 @@ private:
|
|||||||
dsp::filter_window::BlackmanWindow audioWin;
|
dsp::filter_window::BlackmanWindow audioWin;
|
||||||
dsp::PolyphaseResampler<float> audioResamp;
|
dsp::PolyphaseResampler<float> audioResamp;
|
||||||
|
|
||||||
|
dsp::NullSink<float> ns;
|
||||||
|
|
||||||
std::string vfoName;
|
std::string vfoName;
|
||||||
|
|
||||||
float sampleRate;
|
float sampleRate;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"Radio": {
|
"Radio": {
|
||||||
"device": "default",
|
"device": "default",
|
||||||
"sampleRate": 48000.0,
|
"sampleRate": 48000.0,
|
||||||
"volume": 0.0
|
"volume": 1.0
|
||||||
},
|
},
|
||||||
"Radio 1": {
|
"Radio 1": {
|
||||||
"device": "Speakers (Realtek High Definition Audio)",
|
"device": "Speakers (Realtek High Definition Audio)",
|
||||||
@ -18,7 +18,7 @@
|
|||||||
},
|
},
|
||||||
"bandPlan": "General",
|
"bandPlan": "General",
|
||||||
"bandPlanEnabled": true,
|
"bandPlanEnabled": true,
|
||||||
"fftHeight": 298,
|
"fftHeight": 296,
|
||||||
"frequency": 99000000,
|
"frequency": 99000000,
|
||||||
"max": 0.0,
|
"max": 0.0,
|
||||||
"maximized": false,
|
"maximized": false,
|
||||||
|
BIN
root_dev/recordings/audio_19-16-25_02-11-2020.wav
Normal file
BIN
root_dev/recordings/audio_19-16-25_02-11-2020.wav
Normal file
Binary file not shown.
BIN
root_dev/recordings/audio_20-21-27_02-11-2020.wav
Normal file
BIN
root_dev/recordings/audio_20-21-27_02-11-2020.wav
Normal file
Binary file not shown.
BIN
root_dev/recordings/audio_20-21-55_02-11-2020.wav
Normal file
BIN
root_dev/recordings/audio_20-21-55_02-11-2020.wav
Normal file
Binary file not shown.
BIN
root_dev/recordings/baseband_20-21-19_02-11-2020.wav
Normal file
BIN
root_dev/recordings/baseband_20-21-19_02-11-2020.wav
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user