diff --git a/dsp/buffer.cpp b/dsp/buffer.cpp new file mode 100644 index 0000000..fe8b6f7 --- /dev/null +++ b/dsp/buffer.cpp @@ -0,0 +1,53 @@ +#include "buffer.h" + +namespace dsp { + template + Buffer::Buffer() { + + } + + template + Buffer::Buffer(size_t size, bool zero = false) { + + } + + template + Buffer::Buffer(T* taps, int count) { + + } + + template + Buffer::Buffer(const Buffer& b) { + + } + + template + Buffer::Buffer(Buffer&& b) { + + } + + template + Buffer::~Buffer() { + + } + + template + Buffer& Buffer::operator=(const Buffer& b) { + + } + + template + Buffer& Buffer::operator=(Buffer&& b) { + + } + + template + void Buffer::realloc(size_t size, bool zero = false) { + + } + + template + void Buffer::free() { + + } +} \ No newline at end of file diff --git a/dsp/buffer.h b/dsp/buffer.h new file mode 100644 index 0000000..708626b --- /dev/null +++ b/dsp/buffer.h @@ -0,0 +1,83 @@ +#pragma once +#include + +namespace dsp { + /** + * Sample buffer aligned for efficient DSP use. + * This class is NOT thread-safe. + */ + template + 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& b); + + // Move constructor + Buffer(Buffer&& b); + + // Destructor + virtual ~Buffer(); + + // Copy assignment operator + Buffer& operator=(const Buffer& b); + + // Move assignment operator + Buffer& operator=(Buffer&& 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; + }; +} \ No newline at end of file diff --git a/dsp/taps.h b/dsp/taps.h index af4c53a..736ca5d 100644 --- a/dsp/taps.h +++ b/dsp/taps.h @@ -1,4 +1,5 @@ #pragma once +#include 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; }; } \ No newline at end of file diff --git a/dsp/taps/root_raised_cosine.h b/dsp/taps/root_raised_cosine.h new file mode 100644 index 0000000..018fe1a --- /dev/null +++ b/dsp/taps/root_raised_cosine.h @@ -0,0 +1,9 @@ +#pragma once +#include "../taps.h" + +namespace dsp { + class RootRaisedCosine : public Taps { + public: + + }; +}