OpenWareLaboratory
CrossFadingCircularBuffer.h
Go to the documentation of this file.
1 #ifndef _CrossFadingCircularBuffer_hpp_
2 #define _CrossFadingCircularBuffer_hpp_
3 
4 #include <stdint.h>
5 #include "CircularBuffer.h"
6 
7 template<typename T>
9 protected:
11 public:
19  void delay(T* out, size_t len, int delay_samples){
20  delay(out, len, CircularBuffer<T>::getDelay(), delay_samples);
21  }
25  void delay(T* in, T* out, size_t len, int delay_samples){
26  CircularBuffer<T>::write(in, len);
27  delay(out, len, CircularBuffer<T>::getDelay(), delay_samples + len);
28  }
32  void delay(T* out, size_t len, int beginDelay, int endDelay){
33  ASSERT(len <= buffer.getSize(), "Buffer too small");
34  FloatArray output(out, len);
35  CircularBuffer<T>::setDelay(beginDelay);
36  CircularBuffer<T>::read(out, len);
37  output.scale(1, 0);
40  buffer.scale(0, 1);
41  output.add(buffer);
42  }
46  void delay(T* in, T* out, size_t len, int beginDelay, int endDelay){
47  CircularBuffer<T>::write(in, len);
48  delay(out, len, beginDelay + len, endDelay + len); // set delays relative to where we started writing
49  }
50  static CrossFadingCircularBuffer<T>* create(size_t len, size_t blocksize){
52  new CrossFadingCircularBuffer<T>(new T[len], len, FloatArray::create(blocksize));
53  obj->clear();
54  return obj;
55  }
58  delete[] obj->data;
59  delete obj;
60  }
61 };
62 
64 
65 #endif /* _CrossFadingCircularBuffer_hpp_ */
CrossFadingCircularBuffer< float > CrossFadingCircularFloatBuffer
void write(DataType c)
DataType read()
void setDelay(int samples)
Set the read index.
void delay(T *out, size_t len, int delay_samples)
Read from buffer with a delay.
void delay(T *in, T *out, size_t len, int delay_samples)
Write to buffer and read with a delay.
void delay(T *in, T *out, size_t len, int beginDelay, int endDelay)
Write to buffer and read with a delay.
static CrossFadingCircularBuffer< T > * create(size_t len, size_t blocksize)
static void destroy(CrossFadingCircularBuffer< T > *obj)
CrossFadingCircularBuffer(T *data, size_t size, FloatArray buffer)
void delay(T *out, size_t len, int beginDelay, int endDelay)
Read from buffer with a delay.
This class contains useful methods for manipulating arrays of floats.
Definition: FloatArray.h:12
void add(FloatArray operand2, FloatArray destination)
Element-wise sum between arrays.
Definition: FloatArray.cpp:231
static void destroy(FloatArray array)
Destroys a FloatArray created with the create() method.
Definition: FloatArray.cpp:472
static FloatArray create(int size)
Creates a new FloatArray.
Definition: FloatArray.cpp:466
void scale(float from, float to, FloatArray destination)
Scale all values along a linear ramp from one value to another.
Definition: FloatArray.cpp:440
size_t getSize() const
Definition: SimpleArray.h:31
T * getData()
Get the data stored in the Array.
Definition: SimpleArray.h:27
#define ASSERT(cond, msg)
Definition: message.h:16