Can't set AudioBufferList data from within Swift

edited August 2015

There seems to be no known way to set the data within an AudioBufferList in swift.
Any ideas anyone?

Let's take some objective-c code from AERecorder.m for example:

UInt32 bufferLength = kProcessChunkSize;
for ( int i=0; i<THIS->_buffer->mNumberBuffers; i++ ) {
    THIS->_buffer->mBuffers[i].mData = NULL;
    THIS->_buffer->mBuffers[i].mDataByteSize = 0;


You can't recreate the above code in swift.

It is possible to GET the mData and mDataByteSize though. Just not SET it.


var _buffer: UnsafeMutablePointer<AudioBufferList> = AEAllocateAndInitAudioBufferList(kAudioDescription, 0)

let buffers = UnsafeBufferPointer<AudioBuffer>(start: &_buffer.memory.mBuffers,
    count: Int(_buffer.memory.mNumberBuffers))
for buf in buffers {
    var a = buf.mData
    var b = buf.mDataByteSize


  • edited August 2015

    This is the unabridged (auto-generated?) code in ObjC->Swift Bridging File in XCode

    struct AudioBufferList {
    var mNumberBuffers: UInt32
    var mBuffers: (AudioBuffer) // this is a variable length array of mNumberBuffers elements
    init(mNumberBuffers: UInt32, mBuffers: (AudioBuffer))
Sign In or Register to comment.