fixing audio bug

This commit is contained in:
Ryzerth
2020-11-02 21:13:28 +01:00
parent 35c7f0e3cf
commit cee6af1e14
15 changed files with 50 additions and 75 deletions

View File

@ -1,7 +1,7 @@
#pragma once
#include <dsp/block.h>
#define RING_BUF_SZ
#define RING_BUF_SZ 1000000
namespace dsp {
template <class T>

View File

@ -1,6 +1,8 @@
#pragma once
#include <dsp/block.h>
#include <spdlog/spdlog.h>
#define FAST_ATAN2_COEF1 FL_M_PI / 4.0f
#define FAST_ATAN2_COEF2 3.0f * FAST_ATAN2_COEF1

View File

@ -2,6 +2,8 @@
#include <dsp/block.h>
#include <dsp/window.h>
#include <spdlog/spdlog.h>
namespace dsp {
template <class T>
@ -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);
}

View File

@ -1,6 +1,8 @@
#pragma once
#include <dsp/block.h>
#include <spdlog/spdlog.h>
namespace dsp {
class FrequencyXlator : public generic_block<FrequencyXlator> {
public:

View File

@ -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<PolyphaseResampler<T>>::registerInput(_in);
@ -80,6 +80,8 @@ namespace dsp {
}
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;
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<PolyphaseResampler<T>>::tempStart();
}
int calcOutSize(int in) {
@ -97,10 +100,8 @@ namespace dsp {
}
int run() {
if constexpr (std::is_same_v<T, float>) { spdlog::warn("--------- RESAMP START --------"); }
count = _in->read();
if (count < 0) {
if constexpr (std::is_same_v<T, float>) { spdlog::warn("--------- RESAMP STOP --------"); }
return -1;
}
@ -114,16 +115,21 @@ namespace dsp {
return -1;
}
int outIndex = 0;
if constexpr (std::is_same_v<T, float>) {
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<T, float>) {
// // 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<T, complex_t>) {
static_assert(std::is_same_v<T, complex_t>);
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));

View File

@ -1,6 +1,7 @@
#pragma once
#include <dsp/block.h>
#include <cstring>
#include <spdlog/spdlog.h>
namespace dsp {
template <class T>

View File

@ -63,6 +63,7 @@ namespace dsp {
void init(stream<T>* in) {
_in = in;
data.init(480); // TODO: Use an argument
generic_block<RingBufferSink<T>>::registerInput(_in);
}