iosarraysswiftcocoavdsp

Converting an array of Floats to an array of UnsafePointer<DSPComplex>


I have this array of floats created like this

var myArray : [Float] = []

This array has 256 elements, the real part. All imaginary parts are zero.

I need to do a

vDSP_ctoz(anArray, 2, &output, 1, vDSP_Length(n/2))

but this API requires anArray to be UnsafePointer<DSPComplex>

How I convert myArray to this format?


Solution

  • normal arrays can pass as UnsafePointer

    So this snippet should work,

    var myArr = [Float]()
    var arr = [DSPComplex]()
    for number in myArr {
         var dsp = DSPComplex(real: number, imag: 0)
         arr.append(dsp) 
    } 
    

    Just pass this the arr.