I am writing an application that uses constant Q transform using swift. Whilst searching the internet I stumbled upon a GitHub rep that implements constant q transform using Apple's accelerate framework but for C++
I have read through and translated most of the code however am stuck on one crucial part regarding pointers.
The original shows:
DSPSplitComplex kernel;
kernel.realp = new float[K * m_fftLength];
kernel.imagp = new float[K * m_fftLength];
bzero(kernel.realp, sizeof(float) * K * m_fftLength);
bzero(kernel.imagp, sizeof(float) * K * m_fftLength);
and in a function later on, has this:
DSPSplitComplex complexPointer;
complexPointer.realp = &kernel.realp[(k-1) * m_fftLength];
complexPointer.imagp = &kernel.imagp[(k-1) * m_fftLength];
The function performs an FFT and returns the result to complexPointer.
I believe the idea is the 'kernel' is a matrix, with each entry in realp or imagp being a full array of floats returned from the complex pointer function. No errors in Xcode.
However I am confused as to how to convert this part to Swift. I have done the following:
var real1:[Float] = Array(repeating: 0.0, count: Int(K * m_fftLength))
var imag1:[Float] = Array(repeating: 0.0, count: Int(K * m_fftLength))
var kernel = DSPSplitComplex(realp: UnsafeMutablePointer(mutating:real1), imagp: UnsafeMutablePointer(mutating:imag1))
and
var complexPointer:DSPSplitComplex
complexPointer.realp = &kernel.realp[Int((k-1) * m_fftLength)]
complexPointer.imagp = &kernel.imagp[Int((k-1) * m_fftLength)]
and I get the error 'extraneous &'. So it doesn't like the pointer to kernel. without it, the error 'Cannot assign value of type 'Float' to type 'UnsafeMutablePointer''
So I am confused as to where to go from here as I do not know much C++