2

I have an AURenderCallbackStruct setted up with an Audio Unit. In the callbacks i am getting the audio data as ioData: UnsafeMutablePointer<AudioBufferList> . check the code below.

func renderCallback(inRefCon: UnsafeMutablePointer<Void>, ioActionFlag: UnsafeMutablePointer<AudioUnitRenderActionFlags>, inTimeStamp: UnsafePointer<AudioTimeStamp>, inBufferNumber: UInt32, inNumberFrames: UInt32, ioData: UnsafeMutablePointer<AudioBufferList>) -> OSStatus {

    // How can i get AudioBuffer from iodate here ?

    return noErr
}

How can i get AudioBuffer from ioDate here ? Please suggest...

N.B. I am using swift 2.2

1 Answers1

3

Simply use memory property of any UnsafeMutablePointer<> to access it's raw memory. SO your code should look something like this.

var audioBufferListPtr = UnsafeMutableAudioBufferListPointer(ioData).unsafeMutablePointer.memory
for i in 0 ..< Int(inBufferNumber) {
    var buffer: AudioBuffer = audioBufferListPtr.mBuffers
}

N.B. Swift is a quickly evolving language. So this code may change in future.

Partho Biswas
  • 2,290
  • 1
  • 24
  • 39