24 Buffers(
int buffer_count,
int buffer_length,
bool blocking=
true,
bool synchronized =
true){
25 this->buffer_count = buffer_count;
26 this->buffer_length = buffer_length;
28 emptyBuffers =
new Queue<T*>(buffer_count, blocking,
synchronized);
29 filledBuffers =
new Queue<T*>(buffer_count, blocking,
synchronized);
32 for (
int j=0;j<buffer_count;j++) {
33 T* new_buffer =
new T[buffer_length];
34 emptyBuffers->
push(new_buffer);
40 if (emptyBuffers!=
nullptr)
delete emptyBuffers;
41 if (filledBuffers!=
nullptr)
delete filledBuffers;
47 emptyBuffers->
push(buffer);
53 emptyBuffers->
pop(buffer);
60 filledBuffers->
push(buffer);
66 filledBuffers->
pop(buffer);
103 SoundBuffer(
int buffer_count,
int buffer_length,
double amplifier = 1.0, T clip=0) :
Buffers<T>(buffer_count, buffer_length, true, true){
104 this->amplifier = amplifier;
105 this->clip = abs(clip);
113 T avg_value =
avg(buffer,len);
124 double avg( T* buffer,
int len){
126 for (
int j=0;j<len;j++){
135 for (
int j=0;j<len;j++){
136 T value = (
static_cast<double>(buffer[j]) - avg_value) * amplifier;
146 for (
int j=0;j<len;j++){
147 buffer[j] = (
static_cast<double>(buffer[j]) - avg_value) * amplifier;
We are managing a 2 collections of memory arrays: One for the available buffers which can be requeste...
Definition: Buffers.h:14
virtual void addEmpty(T *buffer)
Makes the buffer available as empty.
Definition: Buffers.h:45
virtual T * getFull()
Retrieves the next available data.
Definition: Buffers.h:64
Buffers(int buffer_count, int buffer_length, bool blocking=true, bool synchronized=true)
Construct a new Buffers object.
Definition: Buffers.h:24
virtual void addFull(T *buffer)
Adds the buffer to the list of available data.
Definition: Buffers.h:58
virtual int bufferLength()
Provides the length of each buffer.
Definition: Buffers.h:71
~Buffers()
Destructor.
Definition: Buffers.h:39
virtual T * getEmpty()
Retrieves an empty buffer.
Definition: Buffers.h:51
bool pop(T &data)
Gets the next element (from the head) and removes it from the queue.
Definition: PicoQueue.h:75
bool push(T &data)
Adds an element (at the end) of the queue.
Definition: PicoQueue.h:63
SoundBuffer where the data is standardized, amplified and clipped.
Definition: Buffers.h:93
double avg(T *buffer, int len)
calculate the average over all samples
Definition: Buffers.h:124
T * getFull()
provides the buffer which contains the sound samples - the recorded values are standardized
Definition: Buffers.h:109
void standardize(T *buffer, double avg_value, int len)
make sure that the center is at 0 and that the peaks are clipped
Definition: Buffers.h:133
SoundBuffer(int buffer_count, int buffer_length, double amplifier=1.0, T clip=0)
Construct a new Sound Buffer object.
Definition: Buffers.h:103
Pico Arduino Framework.
Definition: Arduino.cpp:26