OpenWareLaboratory
|
This class contains useful methods for manipulating arrays of int16_ts. More...
Public Member Functions | |
void | add (int16_t scalar) |
Array-scalar sum. More... | |
void | add (ShortArray operand2) |
Element-wise sum between arrays. More... | |
void | add (ShortArray operand2, ShortArray destination) |
Element-wise sum between arrays. More... | |
void | clear () |
Clear the array. More... | |
void | clip (int16_t min, int16_t max) |
Clips the elements in the array in the range [min, max]. More... | |
void | clip (int16_t range) |
Clips the elements in the array in the range [-**range**, range]. More... | |
void | convolve (ShortArray operand2, ShortArray destination) |
Convolution between arrays. More... | |
void | convolve (ShortArray operand2, ShortArray destination, int offset, size_t samples) |
Partial convolution between arrays. More... | |
void | copyFrom (SimpleArray< int16_t > source) |
Copies the content of another array into this array. More... | |
void | copyTo (SimpleArray< int16_t > destination) |
Copies the content of this array to another array. More... | |
void | correlate (ShortArray operand2, ShortArray destination) |
Correlation between arrays. More... | |
void | correlateInitialized (ShortArray operand2, ShortArray destination) |
Correlation between arrays. More... | |
bool | equals (const SimpleArray< int16_t > &other) const |
Compares two arrays. More... | |
void | fromFloat (FloatArray source) |
Copies the content of a FloatArray into a ShortArray, converting the float elements to fixed-point 1.15. More... | |
int16_t * | getData () |
Get the data stored in the Array. More... | |
int16_t | getDb () |
int16_t | getElement (size_t index) |
Get a single value stored in the array. More... | |
float | getFloatValue (uint32_t n) |
Returns an element of the array converted to float. More... | |
void | getMax (int16_t *value, int *index) |
Get the maximum value in the array and its index. More... | |
int | getMaxIndex () |
Get the index of the maximum value in the array. More... | |
int16_t | getMaxValue () |
Get the maximum value in the array. More... | |
int16_t | getMean () |
Mean of the array. More... | |
void | getMin (int16_t *value, int *index) |
Get the minimum value in the array and its index. More... | |
int | getMinIndex () |
Get the index of the minimum value in the array. More... | |
int16_t | getMinValue () |
Get the minimum value in the array. More... | |
int64_t | getPower () |
Power of the array. More... | |
int16_t | getRms () |
Root mean square value of the array. More... | |
size_t | getSize () const |
int16_t | getStandardDeviation () |
Standard deviation of the array. More... | |
int16_t | getVariance () |
Variance of the array. More... | |
void | insert (ShortArray source, int destinationOffset, size_t samples) |
Copies the content of an array into a subset of the array. More... | |
void | insert (ShortArray source, int sourceOffset, int destinationOffset, size_t samples) |
Copies the content of an array into a subset of the array. More... | |
void | insert (SimpleArray< int16_t > source, int destinationOffset, size_t len) |
Copies the content of an array into a subset of the array. More... | |
void | insert (SimpleArray< int16_t > source, int sourceOffset, int destinationOffset, size_t len) |
Copies the content of an array into a subset of the array. More... | |
bool | isEmpty () const |
void | move (int fromIndex, int toIndex, size_t length) |
Copies values within an array. More... | |
void | multiply (int16_t scalar) |
Array-scalar multiplication. More... | |
void | multiply (ShortArray operand2) |
Element-wise multiplication between arrays. More... | |
void | multiply (ShortArray operand2, ShortArray destination) |
Element-wise multiplication between arrays. More... | |
void | negate () |
Negate the array. More... | |
void | negate (ShortArray &destination) |
Negate the array. More... | |
void | noise () |
Random values Fills the array with random values in the range [-1, 1) More... | |
void | noise (int16_t min, int16_t max) |
Random values in range. More... | |
operator int16_t * () | |
Casting operator to T*. More... | |
void | reciprocal () |
Reciprocal of the array. More... | |
void | reciprocal (ShortArray &destination) |
Reciprocal of the array. More... | |
void | rectify () |
Absolute value of the array. More... | |
void | rectify (ShortArray &destination) |
Absolute value of the array. More... | |
void | reverse () |
Reverse the array. More... | |
void | reverse (ShortArray &destination) |
Reverse the array Copies the elements of the array in reversed order into destination. More... | |
void | setAll (int16_t value) |
Set all the values in the array. More... | |
void | setElement (size_t index, int16_t value) |
Set a single value in the array. More... | |
void | setFloatValue (uint32_t n, float value) |
Converts a float to int16 and stores it. More... | |
void | shift (int shiftValue) |
Bitshift the array values, saturating. More... | |
ShortArray () | |
ShortArray (int16_t *data, size_t size) | |
ShortArray | subArray (int offset, size_t length) |
A subset of the array. More... | |
void | subtract (int16_t scalar) |
Array-scalar subtraction. More... | |
void | subtract (ShortArray operand2) |
Element-wise difference between arrays. More... | |
void | subtract (ShortArray operand2, ShortArray destination) |
Element-wise difference between arrays. More... | |
void | toFloat (FloatArray destination) |
Copies the content of the array to a FloatArray, interpreting the content of the ShortArray as 1.15. More... | |
Static Public Member Functions | |
static void | copy (int16_t *dst, int16_t *src, size_t len) |
Optimised array copy for datatype T. More... | |
static ShortArray | create (int size) |
Creates a new ShortArray. More... | |
static void | destroy (ShortArray array) |
Destroys a ShortArray created with the create() method. More... | |
Protected Attributes | |
int16_t * | data |
size_t | size |
This class contains useful methods for manipulating arrays of int16_ts.
It also provides a convenient handle to the array pointer and the size of the array. ShortArray objects can be passed by value without copying the contents of the array.
Definition at line 12 of file ShortArray.h.
|
inline |
Definition at line 14 of file ShortArray.h.
Referenced by subArray().
|
inline |
Definition at line 15 of file ShortArray.h.
void ShortArray::add | ( | int16_t | scalar | ) |
Array-scalar sum.
Adds scalar to the values in the array.
scalar | value to be added to the array |
Definition at line 264 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, saturateTo16(), and SimpleArray< int16_t >::size.
void ShortArray::add | ( | ShortArray | operand2 | ) |
Element-wise sum between arrays.
Adds each element of operand2 to the corresponding element in the array.
operand2 | second operand for the sum |
Definition at line 259 of file ShortArray.cpp.
References add().
void ShortArray::add | ( | ShortArray | operand2, |
ShortArray | destination | ||
) |
Element-wise sum between arrays.
Sets each element in destination to the sum of the corresponding element of the array and operand2
[in] | operand2 | second operand for the sum |
[out] | destination | the destination array |
Definition at line 242 of file ShortArray.cpp.
References ASSERT, SimpleArray< T >::data, SimpleArray< int16_t >::data, saturateTo16(), SimpleArray< int16_t >::size, and SimpleArray< T >::size.
Referenced by add().
|
inline |
Clear the array.
Set all the values in the array to 0.
Definition at line 22 of file ShortArray.h.
References setAll().
Referenced by create().
void ShortArray::clip | ( | int16_t | min, |
int16_t | max | ||
) |
Clips the elements in the array in the range [min, max].
min | minimum value |
max | maximum value |
Definition at line 217 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, max, min, and SimpleArray< int16_t >::size.
void ShortArray::clip | ( | int16_t | range | ) |
Clips the elements in the array in the range [-**range**, range].
range | clipping value. |
Definition at line 208 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, max, and SimpleArray< int16_t >::size.
void ShortArray::convolve | ( | ShortArray | operand2, |
ShortArray | destination | ||
) |
Convolution between arrays.
Sets destination to the result of the convolution between the array and operand2
[in] | operand2 | the second operand for the convolution |
[out] | destination | array. It must have a minimum size of this+other-1. |
Definition at line 464 of file ShortArray.cpp.
References ASSERT, SimpleArray< T >::data, SimpleArray< int16_t >::data, SimpleArray< T >::getSize(), SimpleArray< int16_t >::size, and SimpleArray< T >::size.
Referenced by correlateInitialized().
void ShortArray::convolve | ( | ShortArray | operand2, |
ShortArray | destination, | ||
int | offset, | ||
size_t | samples | ||
) |
Partial convolution between arrays.
Perform partial convolution: start at offset and compute samples values.
[in] | operand2 | the second operand for the convolution. |
[out] | destination | the destination array. |
[in] | offset | first output sample to compute |
[in] | samples | number of samples to compute |
Definition at line 483 of file ShortArray.cpp.
References ASSERT, SimpleArray< T >::data, SimpleArray< int16_t >::data, SimpleArray< T >::getData(), SimpleArray< T >::getSize(), SimpleArray< int16_t >::size, and SimpleArray< T >::size.
|
inlinestaticinherited |
Optimised array copy for datatype T.
Copy four at a time to minimise loop overheads and allow SIMD optimisations. This performs well on external RAM but is slower on internal memory compared to memcpy.
Definition at line 134 of file SimpleArray.h.
|
inlineinherited |
Copies the content of another array into this array.
This array needs to be at least as big as the other array.
[in] | source | the source array |
Definition at line 86 of file SimpleArray.h.
|
inlineinherited |
Copies the content of this array to another array.
The other array needs to be at least as big as this array.
[out] | destination | the destination array |
Definition at line 76 of file SimpleArray.h.
void ShortArray::correlate | ( | ShortArray | operand2, |
ShortArray | destination | ||
) |
Correlation between arrays.
Sets destination to the correlation of the array and operand2.
[in] | operand2 | the second operand for the correlation |
[out] | destination | the destination array. It must have a minimum size of 2*max(srcALen, srcBLen)-1 |
Definition at line 511 of file ShortArray.cpp.
References correlateInitialized(), and setAll().
void ShortArray::correlateInitialized | ( | ShortArray | operand2, |
ShortArray | destination | ||
) |
Correlation between arrays.
Sets destination to the correlation of this array and operand2.
[in] | operand2 | the second operand for the correlation |
[out] | destination | array. It must have a minimum size of 2*max(srcALen, srcBLen)-1 |
Definition at line 516 of file ShortArray.cpp.
References ASSERT, convolve(), SimpleArray< T >::data, SimpleArray< int16_t >::data, reverse(), SimpleArray< int16_t >::size, and SimpleArray< T >::size.
Referenced by correlate().
|
static |
Creates a new ShortArray.
Allocates size*sizeof(int16_t) bytes of memory and returns a ShortArray that points to it.
size | the size of the new ShortArray. |
Definition at line 579 of file ShortArray.cpp.
References clear(), and SimpleArray< int16_t >::size.
|
static |
Destroys a ShortArray created with the create() method.
array | the ShortArray to be destroyed. |
Definition at line 585 of file ShortArray.cpp.
References SimpleArray< T >::data.
|
inlineinherited |
Compares two arrays.
Performs an element-wise comparison of the values contained in the arrays.
other | the array to compare against. |
Definition at line 61 of file SimpleArray.h.
void ShortArray::fromFloat | ( | FloatArray | source | ) |
Copies the content of a FloatArray into a ShortArray, converting the float elements to fixed-point 1.15.
[in] | source | the source array |
Definition at line 555 of file ShortArray.cpp.
References ASSERT, SimpleArray< int16_t >::data, SimpleArray< T >::getSize(), setFloatValue(), and SimpleArray< int16_t >::size.
|
inlineinherited |
Get the data stored in the Array.
Definition at line 27 of file SimpleArray.h.
int16_t ShortArray::getDb | ( | ) |
|
inlineinherited |
Get a single value stored in the array.
index |
Definition at line 43 of file SimpleArray.h.
float ShortArray::getFloatValue | ( | uint32_t | n | ) |
Returns an element of the array converted to float.
n | the array element to read. |
Definition at line 551 of file ShortArray.cpp.
References SimpleArray< int16_t >::data.
Referenced by toFloat().
void ShortArray::getMax | ( | int16_t * | value, |
int * | index | ||
) |
Get the maximum value in the array and its index.
[out] | value | will be set to the maximum value after the call |
[out] | index | will be set to the index of the maximum value after the call |
Definition at line 52 of file ShortArray.cpp.
References ASSERT, SimpleArray< int16_t >::data, and SimpleArray< int16_t >::size.
Referenced by getMaxIndex(), and getMaxValue().
int ShortArray::getMaxIndex | ( | ) |
Get the index of the maximum value in the array.
Definition at line 80 of file ShortArray.cpp.
References getMax().
int16_t ShortArray::getMaxValue | ( | ) |
Get the maximum value in the array.
Definition at line 72 of file ShortArray.cpp.
References getMax().
int16_t ShortArray::getMean | ( | ) |
Mean of the array.
Gets the mean (or average) of the values in the array.
Definition at line 149 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, saturateTo16(), and SimpleArray< int16_t >::size.
void ShortArray::getMin | ( | int16_t * | value, |
int * | index | ||
) |
Get the minimum value in the array and its index.
[out] | value | will be set to the minimum value after the call |
[out] | index | will be set to the index of the minimum value after the call |
Definition at line 17 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, and SimpleArray< int16_t >::size.
Referenced by getMinIndex(), and getMinValue().
int ShortArray::getMinIndex | ( | ) |
Get the index of the minimum value in the array.
Definition at line 44 of file ShortArray.cpp.
References getMin().
int16_t ShortArray::getMinValue | ( | ) |
Get the minimum value in the array.
Definition at line 36 of file ShortArray.cpp.
References getMin().
int64_t ShortArray::getPower | ( | ) |
Power of the array.
Gets the power of the values in the array.
Definition at line 165 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, saturateTo16(), and SimpleArray< int16_t >::size.
Referenced by getVariance().
int16_t ShortArray::getRms | ( | ) |
Root mean square value of the array.
Gets the root mean square of the values in the array.
Definition at line 133 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, saturateTo16(), and SimpleArray< int16_t >::size.
|
inlineinherited |
Definition at line 31 of file SimpleArray.h.
int16_t ShortArray::getStandardDeviation | ( | ) |
Standard deviation of the array.
Gets the standard deviation of the values in the array.
Definition at line 181 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, getVariance(), and SimpleArray< int16_t >::size.
int16_t ShortArray::getVariance | ( | ) |
Variance of the array.
Gets the variance of the values in the array.
Definition at line 192 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, getPower(), and SimpleArray< int16_t >::size.
Referenced by getStandardDeviation().
void ShortArray::insert | ( | ShortArray | source, |
int | destinationOffset, | ||
size_t | samples | ||
) |
Copies the content of an array into a subset of the array.
Copies samples elements from source to destinationOffset in the current array.
[in] | source | the source array |
[in] | destinationOffset | the offset into the destination array |
[in] | samples | the number of samples to copy |
void ShortArray::insert | ( | ShortArray | source, |
int | sourceOffset, | ||
int | destinationOffset, | ||
size_t | samples | ||
) |
Copies the content of an array into a subset of the array.
Copies samples elements starting from sourceOffset of source to destinationOffset in the current array.
[in] | source | the source array |
[in] | sourceOffset | the offset into the source array |
[in] | destinationOffset | the offset into the destination array |
[in] | samples | the number of samples to copy |
|
inlineinherited |
Copies the content of an array into a subset of the array.
Copies len elements from source to destinationOffset in the current array.
[in] | source | the source array |
[in] | destinationOffset | the offset into the destination array |
[in] | len | the number of samples to copy |
Definition at line 99 of file SimpleArray.h.
|
inlineinherited |
Copies the content of an array into a subset of the array.
Copies len elements starting from sourceOffset of source to destinationOffset in the current array.
[in] | source | the source array |
[in] | sourceOffset | the offset into the source array |
[in] | destinationOffset | the offset into the destination array |
[in] | len | the number of samples to copy |
Definition at line 111 of file SimpleArray.h.
|
inlineinherited |
Definition at line 35 of file SimpleArray.h.
void ShortArray::move | ( | int | fromIndex, |
int | toIndex, | ||
size_t | length | ||
) |
Copies values within an array.
Copies length values starting from index fromIndex to locations starting with index toIndex
[in] | fromIndex | the first element to copy |
[in] | toIndex | the destination of the first element |
[in] | length | the number of elements to copy |
void ShortArray::multiply | ( | int16_t | scalar | ) |
Array-scalar multiplication.
Multiplies the values in the array by scalar.
scalar | to be multiplied with the array elements |
Definition at line 422 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, saturateTo16(), and SimpleArray< int16_t >::size.
void ShortArray::multiply | ( | ShortArray | operand2 | ) |
Element-wise multiplication between arrays.
Multiplies each element in the array by the corresponding element in operand2.
operand2 | second operand for the sum |
Definition at line 417 of file ShortArray.cpp.
References multiply().
void ShortArray::multiply | ( | ShortArray | operand2, |
ShortArray | destination | ||
) |
Element-wise multiplication between arrays.
Sets each element in destination to the product of the corresponding element of the array and operand2
[in] | operand2 | second operand for the product |
[out] | destination | the destination array |
Definition at line 399 of file ShortArray.cpp.
References ASSERT, SimpleArray< T >::data, SimpleArray< int16_t >::data, saturateTo16(), SimpleArray< int16_t >::size, and SimpleArray< T >::size.
Referenced by multiply().
void ShortArray::negate | ( | ) |
Negate the array.
Sets each element in the array to its opposite.
Definition at line 446 of file ShortArray.cpp.
void ShortArray::negate | ( | ShortArray & | destination | ) |
Negate the array.
Stores the opposite of the elements in the array into destination.
[out] | destination | the destination array. |
Definition at line 436 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, SimpleArray< T >::getData(), and SimpleArray< int16_t >::size.
void ShortArray::noise | ( | ) |
Random values Fills the array with random values in the range [-1, 1)
Definition at line 451 of file ShortArray.cpp.
void ShortArray::noise | ( | int16_t | min, |
int16_t | max | ||
) |
Random values in range.
Fills the array with random values in the range [min, max)
min | minimum value in the range |
max | maximum value in the range |
Definition at line 455 of file ShortArray.cpp.
References abs, SimpleArray< int16_t >::data, max, min, and SimpleArray< int16_t >::size.
|
inlineinherited |
Casting operator to T*.
Definition at line 157 of file SimpleArray.h.
void ShortArray::reciprocal | ( | ) |
Reciprocal of the array.
Sets each element in the array to its reciprocal.
Definition at line 129 of file ShortArray.cpp.
void ShortArray::reciprocal | ( | ShortArray & | destination | ) |
Reciprocal of the array.
Stores the reciprocal of the elements in the array into destination.
[out] | destination | the destination array. |
Definition at line 123 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, SimpleArray< int16_t >::getData(), and SimpleArray< int16_t >::getSize().
void ShortArray::rectify | ( | ) |
Absolute value of the array.
Sets each element in the array to its absolute value.
Definition at line 100 of file ShortArray.cpp.
void ShortArray::rectify | ( | ShortArray & | destination | ) |
Absolute value of the array.
Stores the absolute value of the elements in the array into destination.
[out] | destination | the destination array. |
Definition at line 88 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, SimpleArray< T >::getData(), SimpleArray< T >::getSize(), min, and SimpleArray< int16_t >::size.
void ShortArray::reverse | ( | ) |
Reverse the array.
Reverses the order of the elements in the array.
Definition at line 115 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, and SimpleArray< int16_t >::size.
Referenced by reverse().
void ShortArray::reverse | ( | ShortArray & | destination | ) |
Reverse the array Copies the elements of the array in reversed order into destination.
[out] | destination | the destination array. |
Definition at line 105 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, reverse(), and SimpleArray< int16_t >::size.
Referenced by correlateInitialized().
void ShortArray::setAll | ( | int16_t | value | ) |
Set all the values in the array.
Sets all the elements of the array to value.
[in] | value | all the elements are set to this value. |
Definition at line 231 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, and SimpleArray< int16_t >::size.
Referenced by clear(), and correlate().
|
inlineinherited |
Set a single value in the array.
Definition at line 50 of file SimpleArray.h.
void ShortArray::setFloatValue | ( | uint32_t | n, |
float | value | ||
) |
Converts a float to int16 and stores it.
n | the array element to write to. @value the value to write |
Definition at line 547 of file ShortArray.cpp.
References SimpleArray< int16_t >::data.
Referenced by fromFloat().
void ShortArray::shift | ( | int | shiftValue | ) |
Bitshift the array values, saturating.
shiftValue | number of positions to shift. A positive value will shift left, a negative value will shift right. |
Definition at line 532 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, and SimpleArray< int16_t >::size.
Referenced by ComplexShortArray::getMagnitudeValues().
ShortArray ShortArray::subArray | ( | int | offset, |
size_t | length | ||
) |
A subset of the array.
Returns a array that points to subset of the memory used by the original array.
[in] | offset | the first element of the subset. |
[in] | length | the number of elments in the new ShortArray. |
Definition at line 226 of file ShortArray.cpp.
References ASSERT, SimpleArray< int16_t >::data, ShortArray(), and SimpleArray< int16_t >::size.
void ShortArray::subtract | ( | int16_t | scalar | ) |
Array-scalar subtraction.
Subtracts scalar from the values in the array.
scalar | to be subtracted from the array |
Definition at line 340 of file ShortArray.cpp.
References SimpleArray< int16_t >::data, saturateTo16(), and SimpleArray< int16_t >::size.
void ShortArray::subtract | ( | ShortArray | operand2 | ) |
Element-wise difference between arrays.
Subtracts from each element of the array the corresponding element in operand2.
[in] | operand2 | second operand for the subtraction |
Definition at line 335 of file ShortArray.cpp.
References subtract().
void ShortArray::subtract | ( | ShortArray | operand2, |
ShortArray | destination | ||
) |
Element-wise difference between arrays.
Sets each element in destination to the difference between the corresponding element of the array and operand2
[in] | operand2 | second operand for the subtraction |
[out] | destination | the destination array |
Definition at line 318 of file ShortArray.cpp.
References ASSERT, SimpleArray< T >::data, SimpleArray< int16_t >::data, saturateTo16(), SimpleArray< int16_t >::size, and SimpleArray< T >::size.
Referenced by subtract().
void ShortArray::toFloat | ( | FloatArray | destination | ) |
Copies the content of the array to a FloatArray, interpreting the content of the ShortArray as 1.15.
[out] | destination | the destination array |
Definition at line 567 of file ShortArray.cpp.
References ASSERT, SimpleArray< int16_t >::data, getFloatValue(), SimpleArray< T >::getSize(), and SimpleArray< int16_t >::size.
|
protectedinherited |
Definition at line 16 of file SimpleArray.h.
|
protectedinherited |
Definition at line 17 of file SimpleArray.h.