OpenWareLaboratory
ShortArray.h
Go to the documentation of this file.
1 #ifndef __ShortArray_h__
2 #define __ShortArray_h__
3 
4 #include <stdint.h>
5 #include "FloatArray.h"
6 
12 class ShortArray : public SimpleArray<int16_t> {
13 public:
15  ShortArray(int16_t* data, size_t size) :
16  SimpleArray(data, size) {}
17 
22  void clear(){
23  setAll(0);
24  }
25 
32  void getMin(int16_t* value, int* index);
33 
39  void getMax(int16_t* value, int* index);
40 
45  int16_t getMinValue();
46 
51  int16_t getMaxValue();
52 
57  int getMinIndex();
58 
63  int getMaxIndex();
64 
65  int16_t getDb(); //TODO: not implemented
66 
72  void rectify(ShortArray& destination);
73 
78  void rectify(); //in place
79 
85  void reverse(ShortArray& destination);
86 
91  void reverse(); //in place
92 
98  void reciprocal(ShortArray& destination);
99 
104  void reciprocal();
105 
111  void negate(ShortArray& destination);
112 
117  void negate();
118 
123  void noise();
124 
131  void noise(int16_t min, int16_t max);
132 
137  int16_t getRms();
138 
143  int16_t getMean();
144 
149  int64_t getPower();
150 
155  int16_t getStandardDeviation();
156 
161  int16_t getVariance();
162 
167  void clip(int16_t range);
168 
174  void clip(int16_t min, int16_t max);
175 
182  void add(ShortArray operand2, ShortArray destination);
183 
189  void add(ShortArray operand2); //in-place
190 
196  void add(int16_t scalar);
197 
204  void subtract(ShortArray operand2, ShortArray destination);
205 
206 
212  void subtract(ShortArray operand2); //in-place
213 
219  void subtract(int16_t scalar);
220 
227  void multiply(ShortArray operand2, ShortArray destination);
228 
234  void multiply(ShortArray operand2); //in-place
235 
241  void multiply(int16_t scalar);
242 
249  void convolve(ShortArray operand2, ShortArray destination);
250 
261  void convolve(ShortArray operand2, ShortArray destination, int offset, size_t samples);
262 
269  void correlate(ShortArray operand2, ShortArray destination);
270 
278  void correlateInitialized(ShortArray operand2, ShortArray destination);
279 
285  void setAll(int16_t value);
286 
298  ShortArray subArray(int offset, size_t length);
299 
305  void toFloat(FloatArray destination);
306 
312  void fromFloat(FloatArray source);
313 
320  void setFloatValue(uint32_t n, float value);
321 
328  float getFloatValue(uint32_t n);
329 
338  void insert(ShortArray source, int destinationOffset, size_t samples);
339 
348  void insert(ShortArray source, int sourceOffset, int destinationOffset, size_t samples);
349 
358  void move(int fromIndex, int toIndex, size_t length);
359 
365  void shift(int shiftValue);
366 
374  static ShortArray create(int size);
375 
382  static void destroy(ShortArray array);
383 };
384 
385 
386 #endif // __ShortArray_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
This class contains useful methods for manipulating arrays of int16_ts.
Definition: ShortArray.h:12
int16_t getMean()
Mean of the array.
Definition: ShortArray.cpp:149
void correlate(ShortArray operand2, ShortArray destination)
Correlation between arrays.
Definition: ShortArray.cpp:511
void rectify()
Absolute value of the array.
Definition: ShortArray.cpp:100
void setFloatValue(uint32_t n, float value)
Converts a float to int16 and stores it.
Definition: ShortArray.cpp:547
void setAll(int16_t value)
Set all the values in the array.
Definition: ShortArray.cpp:231
int16_t getStandardDeviation()
Standard deviation of the array.
Definition: ShortArray.cpp:181
void noise()
Random values Fills the array with random values in the range [-1, 1)
Definition: ShortArray.cpp:451
void fromFloat(FloatArray source)
Copies the content of a FloatArray into a ShortArray, converting the float elements to fixed-point 1....
Definition: ShortArray.cpp:555
void toFloat(FloatArray destination)
Copies the content of the array to a FloatArray, interpreting the content of the ShortArray as 1....
Definition: ShortArray.cpp:567
int getMinIndex()
Get the index of the minimum value in the array.
Definition: ShortArray.cpp:44
void shift(int shiftValue)
Bitshift the array values, saturating.
Definition: ShortArray.cpp:532
void insert(ShortArray source, int sourceOffset, int destinationOffset, size_t samples)
Copies the content of an array into a subset of the array.
void clip(int16_t range)
Clips the elements in the array in the range [-**range**, range].
Definition: ShortArray.cpp:208
static void destroy(ShortArray array)
Destroys a ShortArray created with the create() method.
Definition: ShortArray.cpp:585
ShortArray subArray(int offset, size_t length)
A subset of the array.
Definition: ShortArray.cpp:226
void clear()
Clear the array.
Definition: ShortArray.h:22
void subtract(ShortArray operand2, ShortArray destination)
Element-wise difference between arrays.
Definition: ShortArray.cpp:318
void multiply(ShortArray operand2, ShortArray destination)
Element-wise multiplication between arrays.
Definition: ShortArray.cpp:399
void insert(ShortArray source, int destinationOffset, size_t samples)
Copies the content of an array into a subset of the array.
int16_t getMaxValue()
Get the maximum value in the array.
Definition: ShortArray.cpp:72
float getFloatValue(uint32_t n)
Returns an element of the array converted to float.
Definition: ShortArray.cpp:551
void reciprocal()
Reciprocal of the array.
Definition: ShortArray.cpp:129
int16_t getMinValue()
Get the minimum value in the array.
Definition: ShortArray.cpp:36
int16_t getVariance()
Variance of the array.
Definition: ShortArray.cpp:192
int16_t getRms()
Root mean square value of the array.
Definition: ShortArray.cpp:133
static ShortArray create(int size)
Creates a new ShortArray.
Definition: ShortArray.cpp:579
void getMax(int16_t *value, int *index)
Get the maximum value in the array and its index.
Definition: ShortArray.cpp:52
int64_t getPower()
Power of the array.
Definition: ShortArray.cpp:165
void move(int fromIndex, int toIndex, size_t length)
Copies values within an array.
int getMaxIndex()
Get the index of the maximum value in the array.
Definition: ShortArray.cpp:80
void negate()
Negate the array.
Definition: ShortArray.cpp:446
void correlateInitialized(ShortArray operand2, ShortArray destination)
Correlation between arrays.
Definition: ShortArray.cpp:516
void getMin(int16_t *value, int *index)
Get the minimum value in the array and its index.
Definition: ShortArray.cpp:17
int16_t getDb()
ShortArray(int16_t *data, size_t size)
Definition: ShortArray.h:15
void convolve(ShortArray operand2, ShortArray destination)
Convolution between arrays.
Definition: ShortArray.cpp:464
void add(ShortArray operand2, ShortArray destination)
Element-wise sum between arrays.
Definition: ShortArray.cpp:242
void reverse()
Reverse the array.
Definition: ShortArray.cpp:115
SimpleArray holds a pointer to an array and the array size, and is designed to be passed by value.
Definition: SimpleArray.h:14