Search code examples
swiftunsafe-pointersunsafemutablepointer

Writing to value at UnsafePointer<DSPSplitComplex>


From what I understood, an UnsafePointer presents the pointee as immutable and an UnsafeMutablePointer presents the pointee as mutable. But the signature for the vDSP function vDSP_zrvmul is as follows:

func vDSP_zrvmul(_ __A: UnsafePointer<DSPSplitComplex>, 
               _ __IA: vDSP_Stride, 
               _ __B: UnsafePointer<Float>, 
               _ __IB: vDSP_Stride, 
               _ __C: UnsafePointer<DSPSplitComplex>, 
               _ __IC: vDSP_Stride, 
               _ __N: vDSP_Length)

__C is supposed to be the output vector, but it's not mutable… what am I missing? Thanks for reading.


Solution

  • __A and__C are pointers to DSPSplitComplex:

    public struct DSPSplitComplex {
        public var realp: UnsafeMutablePointer<Float>
        public var imagp: UnsafeMutablePointer<Float>
    }
    

    which contain mutable pointers to arrays of floating point values.

    vDSP_zrvmul writes the output to the arrays pointed to by __C.realp and __C.imagp, but __C itself is not mutated.