tempi-fft icon indicating copy to clipboard operation
tempi-fft copied to clipboard

TempiFFT fix

Open slmille4 opened this issue 8 years ago • 5 comments

On line 166 in TempiFFT.swift, the call should be

analysisBuffer.withUnsafeBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPComplex.self, capacity: analysisBuffer.count) { vDSP_ctoz($0, 2, &complexBuffer, 1, UInt(halfSize)) } }

that should help get vDSP_ctoz working again

slmille4 avatar Jul 01 '17 21:07 slmille4

Thanks! But I still get an error with that code:

Cannot convert value of type 'UnsafePointer<_>' to expected argument type 'UnsafePointer<DSPComplex>'

jscalo avatar Jul 06 '17 00:07 jscalo

It looks like the complexBuffer parameter needs to be DSPSplitComplex instead of DSPSplitComplex!

slmille4 avatar Jul 06 '17 14:07 slmille4

complexBuffer is a class property that can't be initialized (sensibly) at init time, so it must be either DSPSplitComplex? or DSPSplitComplex!.

jscalo avatar Jul 06 '17 20:07 jscalo

Cannot convert value of type 'UnsafePointer<_>' to expected argument type 'UnsafePointer'

The error goes away if you put the reference to 'complexBuffer' in parenthesis.

analysisBuffer.withUnsafeBufferPointer { $0.baseAddress!.withMemoryRebound(to: DSPComplex.self, capacity: analysisBuffer.count) { vDSP_ctoz($0, 2, &(complexBuffer!), 1, UInt(halfSize)) } }

Unfortunately, after trying that, I was getting runtime crashes after a few cycles through audio rendering.

Through a bit of trial and error, I found out the runtime errors were occurring from instantiating DSPSplitComplex with locally instantiated Float arrays at the init call. I was able to make it work by declaring the empty real and imaginary Float arrays as private variables in the class instance. Since that all happens at the init call, I also changed to the 'complexBuffer' from 'DSPSplitComplex!' to 'DSPSplitComplex'.

Tested on Swift 4.0, XCode 9.0 beta 4

Crittar avatar Aug 03 '17 00:08 Crittar

I do not see a historical PR for this - can you create one for the benefit of other users of this project? Thx!

javadba avatar May 01 '20 14:05 javadba