OpenWareLaboratory
ShortArray Class Reference

This class contains useful methods for manipulating arrays of int16_ts. More...

Public Member Functions

void add (ShortArray operand2, ShortArray destination)
 Element-wise sum between arrays. More...
 
void add (ShortArray operand2)
 Element-wise sum between arrays. More...
 
void add (int16_t scalar)
 Array-scalar sum. More...
 
void clear ()
 Clear the array. More...
 
void clip (int16_t range)
 Clips the elements in the array in the range [-**range**, range]. More...
 
void clip (int16_t min, int16_t max)
 Clips the elements in the array in the range [min, max]. 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 (ShortArray source)
 Copies the content of an array into another array. More...
 
void copyFrom (int16_t *source, size_t length)
 Copies an array of int16_t into the array. More...
 
void copyFrom (FloatArray source)
 Copies the content of a FloatArray into a ShortArray, converting the float elements to fixed-point 1.15. More...
 
void copyTo (ShortArray destination)
 Copies the content of the array to another array. More...
 
void copyTo (int16_t *destination, size_t length)
 Copies the content of the array to a location in memory. More...
 
void copyTo (FloatArray destination)
 Copies the content of the array to a FloatArray, interpreting the content of the ShortArray as 1.15. More...
 
void correlate (ShortArray operand2, ShortArray destination)
 Correlation between arrays. More...
 
void correlateInitialized (ShortArray operand2, ShortArray destination)
 Correlation between arrays. More...
 
bool equals (const ShortArray &other) const
 Compares two arrays. More...
 
int16_t * getData ()
 Get the data stored in the ShortArray. More...
 
int16_t getDb ()
 
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
 
size_t getSize ()
 
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 move (int fromIndex, int toIndex, size_t length)
 Copies values within an array. More...
 
void multiply (ShortArray operand2, ShortArray destination)
 Element-wise multiplication between arrays. More...
 
void multiply (ShortArray operand2)
 Element-wise multiplication between arrays. More...
 
void multiply (int16_t scalar)
 Array-scalar multiplication. More...
 
void negate (ShortArray &destination)
 Negate the array. More...
 
void negate ()
 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 int16_t*. More...
 
int16_t & operator[] (const int index)
 Allows to index the array using array-style brackets. More...
 
int16_t & operator[] (const int index) const
 Allows to index the array using array-style brackets. More...
 
void reciprocal (ShortArray &destination)
 Reciprocal of the array. More...
 
void reciprocal ()
 Reciprocal of the array. More...
 
void rectify (ShortArray &destination)
 Absolute value of the array. More...
 
void rectify ()
 Absolute value of the array. More...
 
void reverse (ShortArray &destination)
 Reverse the array Copies the elements of the array in reversed order into destination. More...
 
void reverse ()
 Reverse the array. More...
 
void setAll (int16_t value)
 Set all the values 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 (ShortArray operand2, ShortArray destination)
 Element-wise difference between arrays. More...
 
void subtract (ShortArray operand2)
 Element-wise difference between arrays. More...
 
void subtract (int16_t scalar)
 Array-scalar subtraction. More...
 

Static Public Member Functions

static ShortArray create (int size)
 Creates a new ShortArray. More...
 
static void destroy (ShortArray array)
 Destroys a ShortArray created with the create() method. More...
 

Detailed Description

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 13 of file ShortArray.h.

Constructor & Destructor Documentation

ShortArray::ShortArray ( )

Definition at line 17 of file ShortArray.cpp.

Referenced by subArray().

ShortArray::ShortArray ( int16_t *  data,
size_t  size 
)

Definition at line 20 of file ShortArray.cpp.

Member Function Documentation

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

Parameters
[in]operand2second operand for the sum
[out]destinationthe destination array
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 297 of file ShortArray.cpp.

References ASSERT, and saturateTo16().

Referenced by add().

void ShortArray::add ( ShortArray  operand2)

Element-wise sum between arrays.

Adds each element of operand2 to the corresponding element in the array.

Parameters
operand2second operand for the sum
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 314 of file ShortArray.cpp.

References add().

void ShortArray::add ( int16_t  scalar)

Array-scalar sum.

Adds scalar to the values in the array.

Parameters
scalarvalue to be added to the array

Definition at line 319 of file ShortArray.cpp.

References saturateTo16().

void ShortArray::clear ( )
inline

Clear the array.

Set all the values in the array to 0.

Definition at line 33 of file ShortArray.h.

References setAll().

Referenced by create().

void ShortArray::clip ( int16_t  range)

Clips the elements in the array in the range [-**range**, range].

Parameters
rangeclipping value.

Definition at line 214 of file ShortArray.cpp.

References max.

void ShortArray::clip ( int16_t  min,
int16_t  max 
)

Clips the elements in the array in the range [min, max].

Parameters
minminimum value
maxmaximum value

Definition at line 222 of file ShortArray.cpp.

References max, and min.

void ShortArray::convolve ( ShortArray  operand2,
ShortArray  destination 
)

Convolution between arrays.

Sets destination to the result of the convolution between the array and operand2

Parameters
[in]operand2the second operand for the convolution
[out]destinationarray. It must have a minimum size of this+other-1.
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 520 of file ShortArray.cpp.

References ASSERT, and getSize().

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.

Parameters
[in]operand2the second operand for the convolution.
[out]destinationthe destination array.
[in]offsetfirst output sample to compute
[in]samplesnumber of samples to compute
Remarks
destination[n] is left unchanged for n<offset and the result is stored from destination[offset] onwards that is, in the same position where they would be if a full convolution was performed.
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 539 of file ShortArray.cpp.

References ASSERT, getData(), and getSize().

void ShortArray::copyFrom ( ShortArray  source)

Copies the content of an array into another array.

Parameters
[in]sourcethe source array
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 240 of file ShortArray.cpp.

References getSize(), and min.

void ShortArray::copyFrom ( int16_t *  source,
size_t  length 
)

Copies an array of int16_t into the array.

Parameters
[in]sourcea pointer to the beginning of the portion of memory to read from.
[in]lengthnumber of samples to copy.
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 255 of file ShortArray.cpp.

References ASSERT, and getData().

void ShortArray::copyFrom ( FloatArray  source)

Copies the content of a FloatArray into a ShortArray, converting the float elements to fixed-point 1.15.

Parameters
[in]sourcethe source array

Definition at line 627 of file ShortArray.cpp.

References ASSERT, FloatArray::getSize(), and setFloatValue().

void ShortArray::copyTo ( ShortArray  destination)

Copies the content of the array to another array.

Parameters
[out]destinationthe destination array
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 235 of file ShortArray.cpp.

References getSize(), and min.

void ShortArray::copyTo ( int16_t *  destination,
size_t  length 
)

Copies the content of the array to a location in memory.

Parameters
[out]destinationa pointer to the beginning of the memory location to copy to. The **length***sizeof(int16_t) bytes of memory starting at this location must have been allocated before calling this method.
[in]lengthnumber of samples to copy
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 245 of file ShortArray.cpp.

References ASSERT, and getData().

void ShortArray::copyTo ( FloatArray  destination)

Copies the content of the array to a FloatArray, interpreting the content of the ShortArray as 1.15.

Parameters
[out]destinationthe destination array

Definition at line 639 of file ShortArray.cpp.

References ASSERT, getFloatValue(), and FloatArray::getSize().

void ShortArray::correlate ( ShortArray  operand2,
ShortArray  destination 
)

Correlation between arrays.

Sets destination to the correlation of the array and operand2.

Parameters
[in]operand2the second operand for the correlation
[out]destinationthe destination array. It must have a minimum size of 2*max(srcALen, srcBLen)-1
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 567 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.

Parameters
[in]operand2the second operand for the correlation
[out]destinationarray. It must have a minimum size of 2*max(srcALen, srcBLen)-1
Remarks
It is the same as correlate(), but destination must have been initialized to 0 in advance.
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 572 of file ShortArray.cpp.

References ASSERT, convolve(), and reverse().

Referenced by correlate().

ShortArray ShortArray::create ( int  size)
static

Creates a new ShortArray.

Allocates size*sizeof(int16_t) bytes of memory and returns a ShortArray that points to it.

Parameters
sizethe size of the new ShortArray.
Returns
a ShortArray which data point to the newly allocated memory and size is initialized to the proper value.
Remarks
a ShortArray created with this method has to be destroyed invoking the ShortArray::destroy() method.

Definition at line 609 of file ShortArray.cpp.

References clear().

void ShortArray::destroy ( ShortArray  array)
static

Destroys a ShortArray created with the create() method.

Parameters
arraythe ShortArray to be destroyed.
Remarks
the ShortArray object passed as an argument should not be used again after invoking this method.
a ShortArray object that has not been created by the ShortArray::create() method might cause an exception if passed as an argument to this method.

Definition at line 615 of file ShortArray.cpp.

bool ShortArray::equals ( const ShortArray other) const
inline

Compares two arrays.

Performs an element-wise comparison of the values contained in the arrays.

Parameters
otherthe array to compare against.
Returns
true if the arrays have the same size and the value of each of the elements of the one match the value of the corresponding element of the other, or false otherwise.

Definition at line 430 of file ShortArray.h.

References getSize().

int16_t* ShortArray::getData ( )
inline

Get the data stored in the ShortArray.

Returns
a int16_t* pointer to the data stored in the ShortArray

Definition at line 454 of file ShortArray.h.

Referenced by convolve(), copyFrom(), copyTo(), insert(), negate(), reciprocal(), and rectify().

int16_t ShortArray::getDb ( )
float ShortArray::getFloatValue ( uint32_t  n)

Returns an element of the array converted to float.

Parameters
nthe array element to read.
Returns
the floating point representation of the element.

Definition at line 623 of file ShortArray.cpp.

Referenced by copyTo().

void ShortArray::getMax ( int16_t *  value,
int *  index 
)

Get the maximum value in the array and its index.

Parameters
[out]valuewill be set to the maximum value after the call
[out]indexwill be set to the index of the maximum value after the call
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 58 of file ShortArray.cpp.

References ASSERT.

Referenced by getMaxIndex(), and getMaxValue().

int ShortArray::getMaxIndex ( )

Get the index of the maximum value in the array.

Returns
the maximum value contained in the array
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 86 of file ShortArray.cpp.

References getMax().

int16_t ShortArray::getMaxValue ( )

Get the maximum value in the array.

Returns
the maximum value contained in the array
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 78 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.

Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 155 of file ShortArray.cpp.

References saturateTo16().

void ShortArray::getMin ( int16_t *  value,
int *  index 
)

Get the minimum value in the array and its index.

Parameters
[out]valuewill be set to the minimum value after the call
[out]indexwill be set to the index of the minimum value after the call
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 23 of file ShortArray.cpp.

Referenced by getMinIndex(), and getMinValue().

int ShortArray::getMinIndex ( )

Get the index of the minimum value in the array.

Returns
the mimimum value contained in the array
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 50 of file ShortArray.cpp.

References getMin().

int16_t ShortArray::getMinValue ( )

Get the minimum value in the array.

Returns
the minimum value contained in the array
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 42 of file ShortArray.cpp.

References getMin().

int64_t ShortArray::getPower ( )

Power of the array.

Gets the power of the values in the array.

Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 171 of file ShortArray.cpp.

References saturateTo16().

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 139 of file ShortArray.cpp.

References saturateTo16().

size_t ShortArray::getSize ( )
inline

Definition at line 25 of file ShortArray.h.

int16_t ShortArray::getStandardDeviation ( )

Standard deviation of the array.

Gets the standard deviation of the values in the array.

Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 187 of file ShortArray.cpp.

References getVariance().

int16_t ShortArray::getVariance ( )

Variance of the array.

Gets the variance of the values in the array.

Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 198 of file ShortArray.cpp.

References getPower().

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.

Parameters
[in]sourcethe source array
[in]destinationOffsetthe offset into the destination array
[in]samplesthe number of samples to copy
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 276 of file ShortArray.cpp.

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.

Parameters
[in]sourcethe source array
[in]sourceOffsetthe offset into the source array
[in]destinationOffsetthe offset into the destination array
[in]samplesthe number of samples to copy
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 265 of file ShortArray.cpp.

References ASSERT, and getData().

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

Parameters
[in]fromIndexthe first element to copy
[in]toIndexthe destination of the first element
[in]lengththe number of elements to copy
Remarks
this method uses memmove() so that the source memory and the destination memory can overlap. As a consequence it might have slow performances.

Definition at line 281 of file ShortArray.cpp.

References ASSERT.

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

Parameters
[in]operand2second operand for the product
[out]destinationthe destination array
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 454 of file ShortArray.cpp.

References ASSERT, and saturateTo16().

Referenced by multiply().

void ShortArray::multiply ( ShortArray  operand2)

Element-wise multiplication between arrays.

Multiplies each element in the array by the corresponding element in operand2.

Parameters
operand2second operand for the sum
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 472 of file ShortArray.cpp.

References multiply().

void ShortArray::multiply ( int16_t  scalar)

Array-scalar multiplication.

Multiplies the values in the array by scalar.

Parameters
scalarto be multiplied with the array elements

Definition at line 477 of file ShortArray.cpp.

References saturateTo16().

void ShortArray::negate ( ShortArray destination)

Negate the array.

Stores the opposite of the elements in the array into destination.

Parameters
[out]destinationthe destination array.
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 491 of file ShortArray.cpp.

References getData().

void ShortArray::negate ( )

Negate the array.

Sets each element in the array to its opposite.

Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 501 of file ShortArray.cpp.

void ShortArray::noise ( )

Random values Fills the array with random values in the range [-1, 1)

Definition at line 506 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)

Parameters
minminimum value in the range
maxmaximum value in the range

Definition at line 510 of file ShortArray.cpp.

References abs, and min.

ShortArray::operator int16_t * ( )
inline

Casting operator to int16_t*.

Returns
a int16_t* pointer to the data stored in the ShortArray

Definition at line 446 of file ShortArray.h.

int16_t& ShortArray::operator[] ( const int  index)
inline

Allows to index the array using array-style brackets.

Parameters
indexthe index of the element
Returns
the value of the index element of the array Example usage:
int size=1000;
int16_t content[size];
ShortArray int16_tArray(content, size);
for(int n=0; n<size; n++)
content[n]==int16_tArray[n]; //now the ShortArray can be indexed as if it was an array

Definition at line 411 of file ShortArray.h.

int16_t& ShortArray::operator[] ( const int  index) const
inline

Allows to index the array using array-style brackets.

const version of operator[]

Definition at line 419 of file ShortArray.h.

void ShortArray::reciprocal ( ShortArray destination)

Reciprocal of the array.

Stores the reciprocal of the elements in the array into destination.

Parameters
[out]destinationthe destination array.

Definition at line 129 of file ShortArray.cpp.

References getData(), and getSize().

void ShortArray::reciprocal ( )

Reciprocal of the array.

Sets each element in the array to its reciprocal.

Definition at line 135 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.

Parameters
[out]destinationthe destination array.
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 94 of file ShortArray.cpp.

References getData(), getSize(), and min.

void ShortArray::rectify ( )

Absolute value of the array.

Sets each element in the array to its absolute value.

Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 106 of file ShortArray.cpp.

void ShortArray::reverse ( ShortArray destination)

Reverse the array Copies the elements of the array in reversed order into destination.

Parameters
[out]destinationthe destination array.

Definition at line 111 of file ShortArray.cpp.

References reverse().

Referenced by correlateInitialized().

void ShortArray::reverse ( )

Reverse the array.

Reverses the order of the elements in the array.

Definition at line 121 of file ShortArray.cpp.

Referenced by reverse().

void ShortArray::setAll ( int16_t  value)

Set all the values in the array.

Sets all the elements of the array to value.

Parameters
[in]valueall the elements are set to this value.
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 286 of file ShortArray.cpp.

Referenced by clear(), and correlate().

void ShortArray::setFloatValue ( uint32_t  n,
float  value 
)

Converts a float to int16 and stores it.

Parameters
nthe array element to write to. the value to write

Definition at line 619 of file ShortArray.cpp.

Referenced by copyFrom().

void ShortArray::shift ( int  shiftValue)

Bitshift the array values, saturating.

Parameters
shiftValuenumber of positions to shift. A positive value will shift left, a negative value will shift right.

Definition at line 588 of file ShortArray.cpp.

References getSize().

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.

Parameters
[in]offsetthe first element of the subset.
[in]lengththe number of elments in the new ShortArray.
Returns
the newly created ShortArray.
Remarks
no memory is allocated by this method. The memory is still shared with the original array. The memory should not be de-allocated elsewhere (e.g.: by calling ShortArray::destroy() on the original ShortArray) as long as the ShortArray returned by this method is still in use.
Calling ShortArray::destroy() on a ShortArray instance created with this method might cause an exception.

Definition at line 230 of file ShortArray.cpp.

References ASSERT, and ShortArray().

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

Parameters
[in]operand2second operand for the subtraction
[out]destinationthe destination array

Definition at line 373 of file ShortArray.cpp.

References ASSERT, and saturateTo16().

Referenced by subtract().

void ShortArray::subtract ( ShortArray  operand2)

Element-wise difference between arrays.

Subtracts from each element of the array the corresponding element in operand2.

Parameters
[in]operand2second operand for the subtraction
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 390 of file ShortArray.cpp.

References subtract().

void ShortArray::subtract ( int16_t  scalar)

Array-scalar subtraction.

Subtracts scalar from the values in the array.

Parameters
scalarto be subtracted from the array

Definition at line 395 of file ShortArray.cpp.

References saturateTo16().


The documentation for this class was generated from the following files: