0

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?

Paul Lehn
  • 3,202
  • 1
  • 24
  • 29

1 Answers1

1

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 UInt32s (not NSArray) should convert automatically to UnsafePointer<Void>.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
  • Doesn't seem to compile for me. complains that: "Cannot invoke 'AudioUnitSetProperty' with an argument list of type '(AudioUnit, Uint32, Uint32, Int, NSArray, Uint32)". – Paul Lehn Apr 30 '15 at 13:09
  • My mistake, I forgot to mention that I changed the type – Rhythmic Fistman Apr 30 '15 at 13:17
  • This does compile but when i adjust the equalizer only the first slider adjusts the sound and it seems to adjust ALL levels. Do you have any Idea why this may be? – Paul Lehn Apr 30 '15 at 13:47
  • 1
    I need to see more code to know why that's happening. Is that part of this question or a new question? – Rhythmic Fistman Apr 30 '15 at 13:52
  • Your right that should be a new question, I will start a new one with more code. Thanks for your help! – Paul Lehn Apr 30 '15 at 13:53
  • If you have time here is the new question: http://stackoverflow.com/questions/29970220/core-audio-swift-equalizer-adjusts-all-bands-at-once – Paul Lehn Apr 30 '15 at 14:27