OpenWareLaboratory
FloatArray Class Reference

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

Inheritance diagram for FloatArray:

Public Member Functions

void add (FloatArray operand2, FloatArray destination)
 Element-wise sum between arrays.
void add (FloatArray operand2)
 Element-wise sum between arrays.
void add (float scalar)
 Array-scalar sum.
void clear ()
 Clear the array.
void clip ()
 Clips the elements in the array in the range [-1, 1].
void clip (float range)
 Clips the elements in the array in the range [-**range**, range].
void clip (float min, float max)
 Clips the elements in the array in the range [min, max].
void convolve (FloatArray operand2, FloatArray destination)
 Convolution between arrays.
void convolve (FloatArray operand2, FloatArray destination, int offset, int samples)
 Partial convolution between arrays.
void copyFrom (FloatArray source)
 Copies the content of an array into another array.
void copyFrom (float *source, int length)
 Copies an array of float into the array.
void copyTo (FloatArray destination)
 Copies the content of the array to another array.
void copyTo (float *destination, int length)
 Copies the content of the array to a location in memory.
void correlate (FloatArray operand2, FloatArray destination)
 Correlation between arrays.
void correlateInitialized (FloatArray operand2, FloatArray destination)
 Correlation between arrays.
bool equals (const FloatArray &other) const
 Compares two arrays.
 FloatArray ()
 FloatArray (float *data, int size)
float * getData ()
 Get the data stored in the FloatArray.
float getDb ()
void getMax (float *value, int *index)
 Get the maximum value in the array and its index.
int getMaxIndex ()
 Get the index of the maximum value in the array.
float getMaxValue ()
 Get the maximum value in the array.
float getMean ()
 Mean of the array.
void getMin (float *value, int *index)
 Get the minimum value in the array and its index.
int getMinIndex ()
 Get the index of the minimum value in the array.
float getMinValue ()
 Get the minimum value in the array.
float getPower ()
 Power of the array.
float getRms ()
 Root mean square value of the array.
int getSize () const
int getSize ()
float getStandardDeviation ()
 Standard deviation of the array.
float getVariance ()
 Variance of the array.
void insert (FloatArray source, int destinationOffset, int samples)
 Copies the content of an array into a subset of the array.
void insert (FloatArray source, int sourceOffset, int destinationOffset, int samples)
 Copies the content of an array into a subset of the array.
void move (int fromIndex, int toIndex, int length)
 Copies values within an array.
void multiply (FloatArray operand2, FloatArray destination)
 Element-wise multiplication between arrays.
void multiply (FloatArray operand2)
 Element-wise multiplication between arrays.
void multiply (float scalar)
 Array-scalar multiplication.
void multiply (float scalar, FloatArray destination)
 Array-scalar multiplication.
void negate (FloatArray &destination)
 Negate the array.
void negate ()
 Negate the array.
void noise ()
 Random values Fills the array with random values in the range [-1, 1)
void noise (float min, float max)
 Random values in range.
 operator float * ()
 Casting operator to float*.
float & operator[] (const int index)
 Allows to index the array using array-style brackets.
float & operator[] (const int index) const
 Allows to index the array using array-style brackets.
void reciprocal (FloatArray &destination)
 Reciprocal of the array.
void reciprocal ()
 Reciprocal of the array.
void rectify (FloatArray &destination)
 Absolute value of the array.
void rectify ()
 Absolute value of the array.
void reverse (FloatArray &destination)
 Reverse the array Copies the elements of the array in reversed order into destination.
void reverse ()
 Reverse the array.
void setAll (float value)
 Set all the values in the array.
FloatArray subArray (int offset, int length)
 A subset of the array.
void subtract (FloatArray operand2, FloatArray destination)
 Element-wise difference between arrays.
void subtract (FloatArray operand2)
 Element-wise difference between arrays.
void subtract (float scalar)
 Array-scalar subtraction.

Static Public Member Functions

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

Detailed Description

This class contains useful methods for manipulating arrays of floats.

It also provides a convenient handle to the array pointer and the size of the array. FloatArray objects can be passed by value without copying the contents of the array.

Definition at line 11 of file FloatArray.h.

Constructor & Destructor Documentation

FloatArray::FloatArray ( )

Definition at line 6 of file FloatArray.cpp.

Referenced by subArray().

FloatArray::FloatArray ( float *  data,
int  size 
)

Definition at line 9 of file FloatArray.cpp.

Member Function Documentation

void FloatArray::add ( FloatArray  operand2,
FloatArray  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 288 of file FloatArray.cpp.

Referenced by add().

void FloatArray::add ( FloatArray  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 304 of file FloatArray.cpp.

References add().

void FloatArray::add ( float  scalar)

Array-scalar sum.

Adds scalar to the values in the array.

Parameters
scalarvalue to be added to the array

Definition at line 309 of file FloatArray.cpp.

void FloatArray::clear ( )
inline

Clear the array.

Set all the values in the array to 0.

Definition at line 31 of file FloatArray.h.

References setAll().

Referenced by create(), and FirFilter::init().

void FloatArray::clip ( )

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

Definition at line 201 of file FloatArray.cpp.

void FloatArray::clip ( float  range)

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

Parameters
rangeclipping value.

Definition at line 205 of file FloatArray.cpp.

References max.

void FloatArray::clip ( float  min,
float  max 
)

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

Parameters
minminimum value
maxmaximum value

Definition at line 213 of file FloatArray.cpp.

References max, and min.

void FloatArray::convolve ( FloatArray  operand2,
FloatArray  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 412 of file FloatArray.cpp.

References getSize().

Referenced by correlateInitialized().

void FloatArray::convolve ( FloatArray  operand2,
FloatArray  destination,
int  offset,
int  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 431 of file FloatArray.cpp.

References getData(), and getSize().

void FloatArray::copyFrom ( FloatArray  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 231 of file FloatArray.cpp.

References getSize(), and min.

Referenced by FilterStage::setCoefficients(), and FirFilter::setCoefficients().

void FloatArray::copyFrom ( float *  source,
int  length 
)

Copies an array of float 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 246 of file FloatArray.cpp.

References getData().

void FloatArray::copyTo ( FloatArray  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 226 of file FloatArray.cpp.

References getSize(), and min.

void FloatArray::copyTo ( float *  destination,
int  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(float) 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 236 of file FloatArray.cpp.

References getData().

void FloatArray::correlate ( FloatArray  operand2,
FloatArray  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 459 of file FloatArray.cpp.

References correlateInitialized(), and setAll().

void FloatArray::correlateInitialized ( FloatArray  operand2,
FloatArray  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 464 of file FloatArray.cpp.

References convolve(), and reverse().

Referenced by correlate().

FloatArray FloatArray::create ( int  size)
static

Creates a new FloatArray.

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

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

Reimplemented in Window.

Definition at line 480 of file FloatArray.cpp.

References clear().

Referenced by GaussianNoiseOscillator::create(), FourierPitchDetector::init(), and ZeroCrossingPitchDetector::ZeroCrossingPitchDetector().

void FloatArray::destroy ( FloatArray  array)
static

Destroys a FloatArray created with the create() method.

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

Definition at line 486 of file FloatArray.cpp.

Referenced by FourierPitchDetector::~FourierPitchDetector(), and ZeroCrossingPitchDetector::~ZeroCrossingPitchDetector().

bool FloatArray::equals ( const FloatArray 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 411 of file FloatArray.h.

References getSize().

float* FloatArray::getData ( )
inline

Get the data stored in the FloatArray.

Returns
a float* pointer to the data stored in the FloatArray

Definition at line 435 of file FloatArray.h.

Referenced by Window::apply(), convolve(), copyFrom(), copyTo(), FirFilter::init(), insert(), negate(), FirFilter::processBlock(), reciprocal(), and rectify().

float FloatArray::getDb ( )
void FloatArray::getMax ( float *  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 47 of file FloatArray.cpp.

Referenced by getMaxIndex(), and getMaxValue().

int FloatArray::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 75 of file FloatArray.cpp.

References getMax().

Referenced by FourierPitchDetector::computeFrequency().

float FloatArray::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 67 of file FloatArray.cpp.

References getMax().

float FloatArray::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 144 of file FloatArray.cpp.

Referenced by ZeroCrossingPitchDetector::getFrequency().

void FloatArray::getMin ( float *  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 12 of file FloatArray.cpp.

Referenced by getMinIndex(), and getMinValue().

int FloatArray::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 39 of file FloatArray.cpp.

References getMin().

float FloatArray::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 31 of file FloatArray.cpp.

References getMin().

float FloatArray::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 159 of file FloatArray.cpp.

Referenced by getVariance().

float FloatArray::getRms ( )

Root mean square value of the array.

Gets the root mean square 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 128 of file FloatArray.cpp.

int FloatArray::getSize ( )
inline

Definition at line 23 of file FloatArray.h.

float FloatArray::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 174 of file FloatArray.cpp.

References getVariance().

float FloatArray::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 185 of file FloatArray.cpp.

References getPower().

Referenced by getStandardDeviation().

void FloatArray::insert ( FloatArray  source,
int  destinationOffset,
int  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 267 of file FloatArray.cpp.

Referenced by FourierPitchDetector::process().

void FloatArray::insert ( FloatArray  source,
int  sourceOffset,
int  destinationOffset,
int  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 256 of file FloatArray.cpp.

References getData().

void FloatArray::move ( int  fromIndex,
int  toIndex,
int  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 272 of file FloatArray.cpp.

void FloatArray::multiply ( FloatArray  operand2,
FloatArray  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 342 of file FloatArray.cpp.

Referenced by PolyBlepOscillator::getSamples(), multiply(), and FourierPitchDetector::process().

void FloatArray::multiply ( FloatArray  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 359 of file FloatArray.cpp.

References multiply().

void FloatArray::multiply ( float  scalar)

Array-scalar multiplication.

Multiplies the values in the array by scalar.

Parameters
scalarto be multiplied with the array elements

Definition at line 364 of file FloatArray.cpp.

void FloatArray::multiply ( float  scalar,
FloatArray  destination 
)

Array-scalar multiplication.

Multiplies the values in the array by scalar.

Parameters
scalarto be subtracted from the array
destinationthe destination array

Definition at line 373 of file FloatArray.cpp.

void FloatArray::negate ( FloatArray 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 382 of file FloatArray.cpp.

References getData().

void FloatArray::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 392 of file FloatArray.cpp.

void FloatArray::noise ( )

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

Definition at line 397 of file FloatArray.cpp.

void FloatArray::noise ( float  min,
float  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 401 of file FloatArray.cpp.

References getSize(), and min.

FloatArray::operator float * ( )
inline

Casting operator to float*.

Returns
a float* pointer to the data stored in the FloatArray

Definition at line 427 of file FloatArray.h.

float& FloatArray::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;
float content[size];
FloatArray floatArray(content, size);
for(int n=0; n<size; n++)
content[n]==floatArray[n]; //now the FloatArray can be indexed as if it was an array

Definition at line 392 of file FloatArray.h.

float& FloatArray::operator[] ( const int  index) const
inline

Allows to index the array using array-style brackets.

const version of operator[]

Definition at line 400 of file FloatArray.h.

void FloatArray::reciprocal ( FloatArray destination)

Reciprocal of the array.

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

Parameters
[out]destinationthe destination array.

Definition at line 118 of file FloatArray.cpp.

References getData(), and getSize().

void FloatArray::reciprocal ( )

Reciprocal of the array.

Sets each element in the array to its reciprocal.

Definition at line 124 of file FloatArray.cpp.

void FloatArray::rectify ( FloatArray 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 83 of file FloatArray.cpp.

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

void FloatArray::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 95 of file FloatArray.cpp.

void FloatArray::reverse ( FloatArray destination)

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

Parameters
[out]destinationthe destination array.

Definition at line 100 of file FloatArray.cpp.

References reverse().

Referenced by correlateInitialized().

void FloatArray::reverse ( )

Reverse the array.

Reverses the order of the elements in the array.

Definition at line 110 of file FloatArray.cpp.

Referenced by reverse().

void FloatArray::setAll ( float  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 277 of file FloatArray.cpp.

Referenced by clear(), and correlate().

FloatArray FloatArray::subArray ( int  offset,
int  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 FloatArray.
Returns
the newly created FloatArray.
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 FloatArray::destroy() on the original FloatArray) as long as the FloatArray returned by this method is still in use.
Calling FloatArray::destroy() on a FloatArray instance created with this method might cause an exception.

Definition at line 221 of file FloatArray.cpp.

References FloatArray().

Referenced by FourierPitchDetector::computeFrequency().

void FloatArray::subtract ( FloatArray  operand2,
FloatArray  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
Note
When built for ARM Cortex-M processor series, this method uses the optimized CMSIS library

Definition at line 315 of file FloatArray.cpp.

Referenced by subtract().

void FloatArray::subtract ( FloatArray  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 331 of file FloatArray.cpp.

References subtract().

void FloatArray::subtract ( float  scalar)

Array-scalar subtraction.

Subtracts scalar from the values in the array.

Parameters
scalarto be subtracted from the array

Definition at line 336 of file FloatArray.cpp.


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