I'm trying to convert an interleaved DSPComplex
vector to a DSPSplitComplex
vector, using vDSP_ctoz
from the Swift Accelerate library. The last line of the code below produces the error Segmentation fault: 11
I don't understand why vDSP_ctoz
would try to access out-of-bound memory when I've allocated large vectors and am only trying to process a small number of elements. The vectors are size 2048 and the argument for N
(number of elements to process) in vDSP_ctoz
is 1.
I've also tried using different stride and N
values when calling vDSP_ctoz
, to no avail.
// set stride values
let dspComplexStride = MemoryLayout<DSPComplex>.stride
let dspSplitComplexStride = MemoryLayout<DSPSplitComplex>.stride
// make interleaved vector
var interleaved = UnsafeMutablePointer<DSPComplex>.allocate(capacity: 2048)
for index in 0..<16 {
interleaved[index] = DSPComplex(real: Float(2*index), imag: Float(2*index+1))
}
// make split vector
var splitComplex = UnsafeMutablePointer<DSPSplitComplex>.allocate(capacity: 2048)
vDSP_ctoz(
interleaved, dspComplexStride, splitComplex, dspSplitComplexStride, 1
)