This commit is contained in:
AlexandreRouma
2025-09-16 19:56:41 -04:00
parent ae39eed0cb
commit 80f2d752c1
4 changed files with 58 additions and 6 deletions

View File

@@ -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;

View File

@@ -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.

View File

@@ -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

View File

@@ -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?