Question

I'd like to use apple's accelerate for efficient clipping of an audio signal. If the signal is greater than 1 or less than -1, I'd like to make it equal to 1 or -1. vDSP_vmaxmg looks like it's almost what i'm looking for, but not quite. The documentation says it does this:

Each element of output vector C is the larger of the magnitudes of corresponding values from input vectors A and B.

So it looks like the output of vDSP_vmaxmg will always be absolute values of the input, will always be positive. Can the accelerate framework help me if I want to preserve the absolute value of the output of a signal, but constrain the magnitude?

Was it helpful?

Solution

You want vDSP_vclip( ):

#include <Accelerate/Accelerate.h>

...

float min = -1.0f;
float max =  1.0f;
vDSP_vclip(inputBuffer, inputStride, &min, &max,
           outputBuffer, outputStride, length);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top