Using AEBlockChannel in Swift: how do you access AudioBufferList's mBuffers?

I'm trying to use AEBlockChannel in Swift, but I can't figure out how to access the audio buffers it expostes.

Here is a Stackoverflow question with the same issue: http://stackoverflow.com/questions/24838106/using-audiobufferlist-with-swift There were tentative answers, but they don’t seem to unequivocally solve the issue.

Here's my code:

var blockChannel = AEBlockChannel(
    {(
        time:UnsafePointer<AudioTimeStamp>,
        frames:UInt32,
        audio: UnsafeMutablePointer<AudioBufferList>) in

        var i: Int
        for i = 0; i < Int(frames); i++ {

            //How do you access the mBuffers in audio?

        }
    })

In Objective-C, you can access the audio buffers like this:

((float*)audio->mBuffers[0].mData)[i] = newAudioSample

So how exactly do you access an AudioBufferList's mBuffers in Swift?

Cheers

Ariel

Comments

  • I could be wrong but

      operationsFiles = AEAudioFileLoaderOperation(fileURL: urlOfFiLes, targetAudioDescription: audioController.audioDescription)
                operationsFiles.start()
            
           operationsFiles.bufferList //bufferList

                memBuffPlayer = AEMemoryBufferPlayer(buffer: operationsFiles.bufferList, audioDescription: audioController.audioDescription, freeWhenDone: true)

  • Bad move, I'm afraid: Swift is not designed for use in a realtime context, and if you use it from within the render thread, your app will glitch. You'll need to use C or C++ only from the render thread (note that you can write C within Objective-C classes, of course).

  • @Michael what about swift pointers to C , will that work. I know this must be cumbersome for you to contantly remind Dev to use C .

  • Naw, just doing my civic duty ;-)

    Basically, as long as the actual rendering code itself, the stuff that is performed on the audio thread, is only C (C++ is okay, too), it's fine. So you can interact with TAAE's classes on the main thread via Swift without problems, as long as any channels/filters/receivers are written in plain C.

Sign In or Register to comment.