buffer implementation

This commit is contained in:
AlexandreRouma
2025-09-03 16:01:48 -04:00
parent 9acafbbee9
commit ab030b8816
4 changed files with 148 additions and 2 deletions

53
dsp/buffer.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include "buffer.h"
namespace dsp {
template <class T>
Buffer<T>::Buffer() {
}
template <class T>
Buffer<T>::Buffer(size_t size, bool zero = false) {
}
template <class T>
Buffer<T>::Buffer(T* taps, int count) {
}
template <class T>
Buffer<T>::Buffer(const Buffer<T>& b) {
}
template <class T>
Buffer<T>::Buffer(Buffer<T>&& b) {
}
template <class T>
Buffer<T>::~Buffer() {
}
template <class T>
Buffer<T>& Buffer<T>::operator=(const Buffer<T>& b) {
}
template <class T>
Buffer<T>& Buffer<T>::operator=(Buffer<T>&& b) {
}
template <class T>
void Buffer<T>::realloc(size_t size, bool zero = false) {
}
template <class T>
void Buffer<T>::free() {
}
}

83
dsp/buffer.h Normal file
View File

@@ -0,0 +1,83 @@
#pragma once
#include <stddef.h>
namespace dsp {
/**
* Sample buffer aligned for efficient DSP use.
* This class is NOT thread-safe.
*/
template <class T>
class Buffer {
public:
// Default constructor
Buffer();
/**
* Create a sample buffer of a given capacity.
* @param size Number of samples.
* @param zero Zero out the buffer.
*/
Buffer(size_t size, bool zero = false);
/**
* Create a buffer from an array.
* @param taps Array containing the samples.
* @param count Number of samples to load.
*/
Buffer(T* taps, int count);
// Copy constructor
Buffer(const Buffer<T>& b);
// Move constructor
Buffer(Buffer<T>&& b);
// Destructor
virtual ~Buffer();
// Copy assignment operator
Buffer<T>& operator=(const Buffer<T>& b);
// Move assignment operator
Buffer<T>& operator=(Buffer<T>&& b);
/**
* Re-allocate the buffer conserving the existing data.
* @param size Number of samples.
* @param zero Zero out additional samples.
*/
void realloc(size_t size, bool zero = false);
/**
* Free the buffer.
*/
void free();
/**
* Get the number of samples in the buffer.
*/
inline int size() const { return capacity; }
/**
* Get a pointer to the samples.
*/
inline const T* data() const { return buffer; }
/**
* Cast to bool.
* @return True if the buffer contains samples, false if it is empty.
*/
inline operator bool() const { return capacity; }
/**
* 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]; }
private:
size_t capacity = 0;
T* buffer = NULL;
};
}

View File

@@ -1,4 +1,5 @@
#pragma once
#include <stddef.h>
namespace dsp {
/**
@@ -16,7 +17,7 @@ namespace dsp {
* @param count Number of taps.
* @param zero Zero out the taps.
*/
Taps(int count, bool zero = true);
Taps(int count, bool zero = false);
/**
* Create a tap bank from an array.
@@ -64,6 +65,6 @@ namespace dsp {
void reallocate(int count);
int count = 0;
T* buffer = nullptr;
T* buffer = NULL;
};
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "../taps.h"
namespace dsp {
class RootRaisedCosine : public Taps<float> {
public:
};
}