0

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++

samp17
  • 547
  • 1
  • 4
  • 16
  • Possibly helpful: https://stackoverflow.com/a/54639070. – Martin R Mar 21 '19 at 09:35
  • Thanks for the suggestion. I have tried the way suggested in the link, but its essentially the same as I have now, still results in the same errors. – samp17 Mar 21 '19 at 10:02
  • Did you manage to progress on this? I am using the same github repo but I am using a glue layer from Swift to C++ and it works fine. What I am struggling with right now is that I do not get the same results as librosa (python) – user1816142 Oct 04 '19 at 13:09

0 Answers0