Setting up Audiobus Receiver

I want my app to use Audiobus and receive audio from other apps. However, I can't seem to figure out how to go about it. I have my audio controller setup (I can play songs from music library). I added the Audiobus framework, initialised a audiobus controller with my temp api key. Right now the Audiobus slider thingy on the left side of the screen works.

The code that I am using:

    audiobusController = ABAudiobusController(apiKey: "ommitted")
    audiobusReceiver = ABReceiverPort(name: "Main", title: "Main Input")

    audiobusController?.addReceiverPort(audiobusReceiver)

    audiobusReceiver?.clientFormat = audioController!.audioDescription

    audioController?.audiobusReceiverPort = audiobusReceiver

    audiobusController?.connectionPanelPosition = ABConnectionPanelPositionLeft

Comments

  • Hi @Nosebird - what seems to be the trouble? That looks pretty much correct to me (although, of course, you need to do something with the audio input, via an audio receiver)

  • Hi Michael, I am still a little confused what to do. How do I set this up?

  • I'm doing this right now, no idea if it makes sense (it doesn't work). Btw should I set inputEnabled: true when initializing the audioController:

        let receiver = AEBlockAudioReceiver { (source, time, frames, audioBufferList) -> Void in
    
            ABReceiverPortReceive(self.audioController!.audiobusReceiverPort, nil, audioBufferList, frames, UnsafeMutablePointer<AudioTimeStamp>(time))
        }
    
        audioController?.addInputReceiver(receiver)
    
  • edited August 2015

    Oops, sorry I missed you @Nosebird.

    To receive audio that way, yes, you'd need to set inputEnabled to YES (otherwise your input receiver will never be called).

    Alternatively - and I'd probably recommend this approach instead if you're not planning on recording from the device microphone when you're not receiving over Audiobus - you could create a channel block and call ABReceiverPortReceive the same way.

    So, instead of:

        let receiver = AEBlockAudioReceiver { (source, time, frames, audioBufferList) -> Void in
            ABReceiverPortReceive(self.audioController!.audiobusReceiverPort, nil, audioBufferList, frames, UnsafeMutablePointer(time))
        }
        audioController?.addInputReceiver(receiver)
    

    you'd have:

        let channel = AEBlockChannel { (time, frames, audioBufferList) -> Void in
            ABReceiverPortReceive(audiobusReceiverPort, nil, audioBufferList, frames, UnsafeMutablePointer(time))
        }
        audioController?.addChannels([channel])
    

    I've not tested that, but it should work =)

Sign In or Register to comment.