I am trying to set the bands in my equalizer by using AudioUnitSetProperty but cant figure out the syntax in Swift. My code looks like this:
var eqFrequencies: NSArray = [ 32, 250, 500, 1000, 2000, 16000 ]
var noBands = UInt32(eqFrequencies.count)
AudioUnitSetProperty(self.MyAppUnit, AudioUnitParameterID(kAUNBandEQProperty_NumberOfBands), AudioUnitScope(kAudioUnitScope_Global), 0, 6, UInt32(sizeof(noBands)))
Anyone know the correct way of doing this?
Try this (compiles for me in Xcode 6.3):
var eqFrequencies: [UInt32] = [ 32, 250, 500, 1000, 2000, 16000 ]
AudioUnitSetProperty(
self.MyAppUnit,
AudioUnitPropertyID(kAUNBandEQProperty_NumberOfBands),
AudioUnitScope(kAudioUnitScope_Global),
0,
eqFrequencies,
UInt32(eqFrequencies.count*sizeof(UInt32))
)
Swift griped about the various int types, hence the extra casts, and the size calculation was wrong, but the band swift array of UInt32
s (not NSArray
) should convert automatically to UnsafePointer<Void>
.