     weak var delegate: AudioInputInterfaceDelegate? = nil
     
     var inputFormat: AudioStreamBasicDescription = AudioStreamBasicDescription()
-    var buffer = UnsafeMutablePointer<Float>()
-    var buffer2 = UnsafeMutablePointer<Float>() // used for de-interleaving data
-    var bufferLen: Int = 0
+    var outputFormat: AudioStreamBasicDescription = AudioStreamBasicDescription()
+    
+    var bufferList: UnsafeMutableAudioBufferListPointer = UnsafeMutableAudioBufferListPointer(nil)
     
     init(deviceID: AudioDeviceID, frameSize: Int = 64) {
         self.deviceID = deviceID

    // get audio in interface
    let aii = unsafeBitCast(inRefCon, AudioInputInterface.self)
    
    // build buffer
    var buffer = AudioBuffer()
    buffer.mDataByteSize = aii.inputFormat.mBytesPerFrame * frameCount
    buffer.mNumberChannels = aii.inputFormat.mChannelsPerFrame
    buffer.mData = UnsafeMutablePointer<Void>(aii.buffer)
    
    var bufferList = AudioBufferList()
    bufferList.mNumberBuffers = 1
    bufferList.mBuffers = buffer
    
    // render input
    let status = AudioUnitRender(aii.audioUnit, actionFlags, timeStamp, busNumber, frameCount, &bufferList)
    
    if noErr != status {
        return status
    }
    
    // data
    let data = UnsafeMutablePointer<Float>(buffer.mData)
    
    // number of channels
    let maxi = Int(aii.inputFormat.mChannelsPerFrame)
    
    // number of floats per channel
    let frameLength = Int(frameCount)
    
    // single channel? no interleaving
    if maxi == 1 {
        aii.delegate?.receiveAudioFrom(aii, fromChannel: 0, withData: data, ofLength: frameLength)
        return 0
    }
    
    // multiple channels? de-interleave
    var zero: Float = 0.0
    for var i = 0; i < maxi; ++i {
        // use vDSP to deinterleave
        vDSP_vsadd(data + i, vDSP_Stride(maxi), &zero, aii.buffer2, 1, vDSP_Length(frameLength))
        
        
        // call delegate
        aii.delegate?.receiveAudioFrom(aii, fromChannel: i, withData: aii.buffer2, ofLength: frameLength)
    }
    
    return 0

        try checkError(AudioUnitGetProperty(audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &maxFrameSize, &size))
        
        // create buffers
        bufferList = AudioBufferList.allocate(maximumBuffers: Int(outputFormat.mChannelsPerFrame))
        bufferList.count = Int(outputFormat.mChannelsPerFrame)
        for var channel = 0; channel < Int(outputFormat.mChannelsPerFrame); ++channel {
            // build buffer
            var buffer = AudioBuffer()
            buffer.mDataByteSize = outputFormat.mBytesPerFrame * maxFrameSize
            buffer.mNumberChannels = 1 // since non-interleaved
            buffer.mData = malloc(Int(outputFormat.mBytesPerFrame * maxFrameSize))
            bufferList[channel] = buffer
        }
        
        // set frame size
        var frameSize: UInt32 = UInt32(self.frameSize)
