From 80f2d752c1fb5452c14bab1cbb36ebd416ea9d30 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Tue, 16 Sep 2025 19:56:41 -0400 Subject: [PATCH] bugfix --- dsp/buffer.h | 5 +++-- dsp/complex.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++- dsp/window.cpp | 8 +++++++- todo.txt | 4 ++-- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/dsp/buffer.h b/dsp/buffer.h index e113bc9..caea3af 100644 --- a/dsp/buffer.h +++ b/dsp/buffer.h @@ -6,6 +6,7 @@ namespace dsp { * Re-allocation behavior of buffers. */ enum ReallocBehavior { + // Discard the exiting content of the buffer. REALLOC_DISCARD = 0, @@ -105,14 +106,14 @@ namespace dsp { * @param index Index of the tap * @return Tap at index. */ - inline T& operator[](int index) { return buffer[index]; } + inline T& operator[](uintptr_t index) { return buffer[index]; } /** * Get a sample by index. * @param index Index of the tap * @return Tap at index. */ - inline const T& operator[](int index) const { return buffer[index]; } + inline const T& operator[](uintptr_t index) const { return buffer[index]; } private: size_t capacity = 0; diff --git a/dsp/complex.h b/dsp/complex.h index 7287b02..c0c1fd1 100644 --- a/dsp/complex.h +++ b/dsp/complex.h @@ -55,7 +55,52 @@ namespace dsp { re = b; } - // TODO: Define in-place operators + // In-place real add operator + inline constexpr void operator+=(float b) { + re += b; + } + + // In-place real subtract operator + inline constexpr void operator-=(float b) { + re -= b; + } + + // In-place real multiply operator + inline constexpr void operator*=(float b) { + re *= b; + im *= b; + } + + // In-place real divide operator + inline constexpr void operator/=(float b) { + re /= b; + im /= b; + } + + // In-place complex add operator + inline constexpr void operator+=(const dsp::Complex& b) { + re += b.re; + im += b.im; + } + + // In-place complex subtract operator + inline constexpr void operator-=(const dsp::Complex& b) { + re -= b.re; + im -= b.im; + } + + // In-place real multiply operator + inline constexpr void operator*=(const dsp::Complex& b) { + re = re*b.re - im*b.im; + im = im*b.re + re*b.im; + } + + // In-place real divide operator + inline constexpr void operator/=(const dsp::Complex& b) { + float denom = b.re*b.re + b.im*b.im; + re = (re*b.re + im*b.im) / denom; + im = (im*b.re - re*b.im) / denom; + } /** * Real component. diff --git a/dsp/window.cpp b/dsp/window.cpp index fc0c153..15719ab 100644 --- a/dsp/window.cpp +++ b/dsp/window.cpp @@ -23,11 +23,17 @@ namespace dsp { Window& Window::operator=(const Window& b) { // Copy the definition def = b.def; + + // Return self + return *this; } Window& Window::operator=(Window&& b) { // Move the definition def = std::move(b.def); + + // Return self + return *this; } void Window::generate(float* data, size_t len) const { @@ -53,7 +59,7 @@ namespace dsp { } } template void Window::apply(float* data, size_t len) const; - //template void Window::apply(Complex* data, size_t len) const; + template void Window::apply(Complex* data, size_t len) const; void Window::define() { // Ensure an error is thrown if the undefined window is used diff --git a/todo.txt b/todo.txt index 824563e..58f6d02 100644 --- a/todo.txt +++ b/todo.txt @@ -1,6 +1,6 @@ -Create buffer class that replaces the BufferSet struct +Replaces the BufferSet struct using the Buffer class -Move the fixes from the SFAP library's stream.c to this one +Move the fixes from the SFAP library's stream.c to this one? Think a lot about how multichannel streams are to be handled. Doing it all in one thread might not be possible so perhapse a built-in synchronisation system is worth it?