OpenWareLaboratory
FloatArray.h
Go to the documentation of this file.
1 #ifndef __FloatArray_h__
2 #define __FloatArray_h__
3 
4 #include <cstddef>
5 #include "SimpleArray.h"
6 
12 class FloatArray : public SimpleArray<float> {
13 public:
15  FloatArray(float* data, size_t size) :
16  SimpleArray(data, size) {}
17 
23  void setAll(float value);
24 
29  void clear(){
30  setAll(0);
31  }
32 
39  void getMin(float* value, int* index);
40 
46  void getMax(float* value, int* index);
47 
52  float getMinValue();
53 
58  float getMaxValue();
59 
64  int getMinIndex();
65 
70  int getMaxIndex();
71 
77  void rectify(FloatArray& destination);
78 
83  void rectify(){
84  rectify(*this);
85  }
86 
92  void reverse(FloatArray& destination);
93 
98  void reverse(); //in place
99 
105  void reciprocal(FloatArray& destination);
106 
111  void reciprocal(){
112  reciprocal(*this);
113  }
114 
121  void negate(FloatArray& destination);
122 
127  void negate(){
128  negate(*this);
129  }
130 
135  void noise();
136 
143  void noise(float min, float max);
144 
149  float getRms();
150 
155  float getMean();
156 
161  float getSum();
162 
167  float getPower();
168 
173  float getStandardDeviation();
174 
179  float getVariance();
180 
184  void clip();
185 
190  void clip(float range);
191 
197  void clip(float min, float max);
198 
203  void softclip(FloatArray destination);
204 
209  void softclip(){
210  softclip(*this);
211  }
212 
219  void add(FloatArray operand2, FloatArray destination);
220 
226  void add(FloatArray operand2); //in-place
227 
234  void add(float scalar, FloatArray destination);
235 
241  void add(float scalar);
242 
249  void subtract(FloatArray operand2, FloatArray destination);
250 
251 
257  void subtract(FloatArray operand2); //in-place
258 
264  void subtract(float scalar);
265 
272  void multiply(FloatArray operand2, FloatArray destination);
273 
279  void multiply(FloatArray operand2); //in-place
280 
286  void multiply(float scalar);
287 
294  void multiply(float scalar, FloatArray destination);
295 
303  void convolve(FloatArray operand2, FloatArray destination);
304 
316  void convolve(FloatArray operand2, FloatArray destination, int offset, size_t samples);
317 
325  void correlate(FloatArray operand2, FloatArray destination);
326 
334  void correlateInitialized(FloatArray operand2, FloatArray destination);
335 
340  void gainToDecibel(FloatArray destination);
341 
346  void decibelToGain(FloatArray destination);
347 
359  FloatArray subArray(int offset, size_t length);
364  void ramp(float from, float to);
365 
369  void scale(float from, float to, FloatArray destination);
370 
374  void scale(float from, float to){
375  scale(from, to, *this);
376  }
377 
381  void tanh(FloatArray destination);
382 
386  void tanh(){
387  tanh(*this);
388  }
389 
397  static FloatArray create(int size);
398 
405  static void destroy(FloatArray array);
406 };
407 
408 #endif // __FloatArray_h__
#define min(a, b)
Definition: basicmaths.h:38
#define max(a, b)
Definition: basicmaths.h:41
This class contains useful methods for manipulating arrays of floats.
Definition: FloatArray.h:12
void reverse()
Reverse the array.
Definition: FloatArray.cpp:99
float getStandardDeviation()
Standard deviation of the array.
Definition: FloatArray.cpp:166
void clear()
Clear the array.
Definition: FloatArray.h:29
void negate()
Negate the array.
Definition: FloatArray.h:127
void noise()
Random values Fills the array with random values in the range [-1, 1)
Definition: FloatArray.cpp:340
void multiply(FloatArray operand2, FloatArray destination)
Element-wise multiplication between arrays.
Definition: FloatArray.cpp:290
float getRms()
Root mean square value of the array.
Definition: FloatArray.cpp:113
int getMinIndex()
Get the index of the minimum value in the array.
Definition: FloatArray.cpp:33
void decibelToGain(FloatArray destination)
Convert decibel to gains values: gain = 10^(dB/20) -6dB = 0.5, 0dB = 1.0, +6dB = 2....
Definition: FloatArray.cpp:426
float getPower()
Power of the array.
Definition: FloatArray.cpp:151
float getMinValue()
Get the minimum value in the array.
Definition: FloatArray.cpp:25
void scale(float from, float to)
In-place scale.
Definition: FloatArray.h:374
void add(FloatArray operand2, FloatArray destination)
Element-wise sum between arrays.
Definition: FloatArray.cpp:231
float getVariance()
Variance of the array.
Definition: FloatArray.cpp:177
FloatArray(float *data, size_t size)
Definition: FloatArray.h:15
float getSum()
Sum of the array.
Definition: FloatArray.cpp:129
void reciprocal()
Reciprocal of the array, in-place version.
Definition: FloatArray.h:111
int getMaxIndex()
Get the index of the maximum value in the array.
Definition: FloatArray.cpp:69
void ramp(float from, float to)
Create a linear ramp from one value to another.
Definition: FloatArray.cpp:432
static void destroy(FloatArray array)
Destroys a FloatArray created with the create() method.
Definition: FloatArray.cpp:472
void rectify()
Absolute value of the array, in-place version.
Definition: FloatArray.h:83
void gainToDecibel(FloatArray destination)
Convert gains to decibel values: dB = log10(gain)*20 Gain 0.5 = -6dB, 1.0 = 0dB, 2....
Definition: FloatArray.cpp:420
void correlateInitialized(FloatArray operand2, FloatArray destination)
Correlation between arrays.
Definition: FloatArray.cpp:404
float getMean()
Mean of the array.
Definition: FloatArray.cpp:136
static FloatArray create(int size)
Creates a new FloatArray.
Definition: FloatArray.cpp:466
void subtract(FloatArray operand2, FloatArray destination)
Element-wise difference between arrays.
Definition: FloatArray.cpp:263
void clip()
Clips the elements in the array in the range [-1, 1].
Definition: FloatArray.cpp:193
void correlate(FloatArray operand2, FloatArray destination)
Correlation between arrays.
Definition: FloatArray.cpp:398
void scale(float from, float to, FloatArray destination)
Scale all values along a linear ramp from one value to another.
Definition: FloatArray.cpp:440
void getMax(float *value, int *index)
Get the maximum value in the array and its index.
Definition: FloatArray.cpp:41
void softclip()
Applies a cubic soft-clip algorithm to all elements in the array which limits them to the range [-1,...
Definition: FloatArray.h:209
void convolve(FloatArray operand2, FloatArray destination)
Convolution between arrays.
Definition: FloatArray.cpp:352
FloatArray subArray(int offset, size_t length)
A subset of the array.
Definition: FloatArray.cpp:215
void tanh()
In-place tanh.
Definition: FloatArray.h:386
void setAll(float value)
Set all the values in the array.
Definition: FloatArray.cpp:220
void getMin(float *value, int *index)
Get the minimum value in the array and its index.
Definition: FloatArray.cpp:6
float getMaxValue()
Get the maximum value in the array.
Definition: FloatArray.cpp:61
SimpleArray holds a pointer to an array and the array size, and is designed to be passed by value.
Definition: SimpleArray.h:14