void FloatArray::convolve(FloatArray operand2, FloatArray destination, int offset, int samples){ ASSERT(destination.size >= size + operand2.size -1, "Destination array too small"); //TODO: change this condition to the actual size being written(will be samples+ tail) /// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a> #ifdef ARM_CORTEX //TODO: I suspect a bug in arm_conv_partial_f32 //it seems that destination[n] is left unchanged for n<offset //and the result is actually stored from destination[offset] onwards //that is, in the same position where they would be if a full convolution was performed. //This requires (destination.size >= size + operand2.size -1). Ideally you would want destination to be smaller arm_conv_partial_f32(data, size, operand2.data, operand2.size, destination.getData(), offset, samples); #else //this implementations reproduces the (buggy?) behaviour of arm_conv_partial (see comment above and inline comments below) /* This implementation is just a copy/paste/edit from the overloaded method */ int size2=operand2.getSize(); for (int n=offset; n<offset+samples; n++){ int n1=n; destination[n] =0; //this should be [n-offset] for(int k=0; k<size2; k++){ if(n1>=0 && n1<size) destination[n]+=data[n1]*operand2[k];//this should be destination[n-offset] n1--; } } #endif /* ARM_CORTEX */ }
void FloatArray::negate(FloatArray& destination){//allows in-place /// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a> #ifdef ARM_CORTEX arm_negate_f32(data, destination.getData(), size); #else for(int n=0; n<size; n++){ destination[n]=-data[n]; } #endif /* ARM_CORTEX */ }
void FloatArray::insert(FloatArray source, int sourceOffset, int destinationOffset, int samples){ ASSERT(size >= destinationOffset+samples, "Array too small"); ASSERT(source.size >= sourceOffset+samples, "Array too small"); /// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a> #ifdef ARM_CORTEX arm_copy_f32(source.data+sourceOffset, data+destinationOffset, samples); #else memcpy((void*)(getData()+destinationOffset), (void*)(source.getData()+sourceOffset), samples*sizeof(float)); #endif /* ARM_CORTEX */ }
void FloatArray::rectify(FloatArray& destination){ //this is actually "copy data with rectifify" /// @note When built for ARM Cortex-M processor series, this method uses the optimized <a href="http://www.keil.com/pack/doc/CMSIS/General/html/index.html">CMSIS library</a> #ifdef ARM_CORTEX arm_abs_f32(data, destination.getData(), size); #else int minSize= min(size,destination.getSize()); //TODO: shall we take this out and allow it to segfault? for(int n=0; n<minSize; n++){ destination[n] = fabs(data[n]); } #endif }