Get On The Audiobus (CocoaConf Boston, October 2013)

  • 819 views
Uploaded on

Audiobus is an iOS app that allows other apps to work together as an audio-processing toolchain: play your MIDI keyboard into one app, run it through filters in other apps, and mix it in a third. All …

Audiobus is an iOS app that allows other apps to work together as an audio-processing toolchain: play your MIDI keyboard into one app, run it through filters in other apps, and mix it in a third. All in real-time, foreground or background. That such a thing is possible on the locked down iOS platform is remarkable enough, but what's even more remarkable is that hundreds of audio apps have added Audiobus support in the few months since its debut, including Apple's own GarageBand. In this session, we'll take a look at the Audiobus SDK and see how to create inputs, outputs, and filters that can be managed by the Audiobus app to process audio in collaboration with other apps on the device.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
819
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
1
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Get on the Audiobus Chris Adamson • @invalidname CocoaConf Boston • October, 2013 Slides & code will be posted to the CocoaConf Glassboard, and announced on my Twitter & app.net (@invalidname)
  • 2. Roadmap • How audio works on iOS • What Audiobus is and how it connects apps • Adopting Audiobus in your audio app
  • 3. Audio on iOS • Each app is responsible for its own audio • No access to audio to/from other apps • Apps use the Audio Session API to interact with the system • See also AVAudioSession in AV Foundation
  • 4. Audio Session • Allows inspection of hardware properties (sampling rate, hardware latencies) and negotiation of access to system audio resources • Audio “category” declares what your app does with audio • This affects things like whether you mix with other apps’ audio, honor ring/silent, can play in background, etc.
  • 5. Audio Categories • Ambient • Solo Ambient • Playback • Record • Play and Record • Audio Processing • Multi-Route
  • 6. Audio Engines • How your app interacts with audio hardware, i.e., captures or produces sound • OpenAL (play-out only) • Audio Queue • Audio Units
  • 7. AURemoteIO Bus 1: audio in AURemoteIO Bus 0: audio out
  • 8. Mixing between apps AURemoteIO AURemoteIO
  • 9. Mixing between apps AURemoteIO ! AURemoteIO
  • 10. Every App is an Island • Only awareness of other apps’ audio is value of kAudioSessionProperty_OtherAudioIsPlaying property • No access to what other apps are playing audio, how loud it is, etc.
  • 11. Which means… • You can’t record audio from one app in another app • Production apps can’t specialize; have to provide everything (instruments, filters/ effects, recording) that you’d ever need
  • 12. Enter Audiobus
  • 13. Audiobus • Standalone app that coordinates inter-app audio • Currently on 50% off sale ($4.99) • Only works with apps that adopt the Audiobus API • 300 and counting!
  • 14. Demo
  • 15. What Audiobus Is • Audiobus is an app for users to coordinate audio across supported apps • User decides which apps are the inputs, effects, and outputs
  • 16. What Audiobus Isn’t • Audiobus is not a general-purpose systemlevel audio capture (like Audio Hijack on Mac) • Audiobus cannot get audio from or send audio to an arbitrary app • Apps must adopt the Audiobus SDK and register with the Audiobus website
  • 17. How the heck does it even work? Considering that inter-app communication is nearly impossible on iOS…
  • 18. Secret Sauce! • Audiobus began with MIDI “System Exclusive” (SysEx) messages, defined as being arbitrary blobs of data unique to a given MIDI device • Originally meant for synths to exchange waveforms, patches or other software/firmware upgrades, etc. • MIDI messages available to all interested apps via Core MIDI • Later switched to Mach Ports, which Core MIDI is implemented atop
  • 19. Audiobus Concepts • Apps take on roles based on their relationship to Audiobus • Inputs produce audio • Outputs receive audio • Filters receive from inputs and send to outputs • Points of connection are called ports
  • 20. http://developer.audiob.us/doc/index.html
  • 21. Basic Audiobus Integration • Decide if you’re an input, output, or filter • Decide if you can work with the Remote IO unit or Audiobus’ port API • Adopt the Audiobus SDK to connect to Audiobus at runtime • Register at audiob.us
  • 22. An Audiobus Integration Case Study
  • 23. Audiobus Web Radio • Web Radio app developed as in-class exercise for Thursday's all-day Core Audio class • Will also be at CocoaConf Atlanta • Uses Audio File Stream to receive packets of MP3 and play them with Audio Queue Packets Packets 2 Packets Packets Packets 1 0 Packets
  • 24. LPCM or GTFO • Audiobus ports and AURemoteIO only work with uncompressed LPCM audio • Web radio app is dealing in MP3 or AAC • Conversion to LPCM happens inside the Audio Queue
  • 25. Offline Queues Packets Packets 2 Packets 1 Packets Packets 0 Packets AURemoteIO AudioQueueOfflineRender()
  • 26. Libraries • Download the Audiobus SDK from developer.audiob.us • Add libAudiobus.a and the Audiobus headers to your project • Add Accelerate, AudioToolbox, QuartzCore, CoreGraphics, and Security frameworks to your project
  • 27. Enable background audio • Add “audio” to the app’s “Required Background Modes” if it’s not already present • All Audiobus-enabled apps must participate in backgrounding, since they must be able to keep running when Audiobus is in foreground
  • 28. Create a launch URL scheme • You must have a URL scheme for your app that ends in “.audiobus” for Audiobus to be able to launch you • Add this to the target’s “URL Types”
  • 29. Get Audiobus API key • For apps registered with iTunes Connect, submit your App Store URL or ID • For unpublished apps or tinkering, register for a temporary ID, good for 14 days • This requires dropping the Info.plist from your app bundle (not from project!)
  • 30. Audiobus API Keys • Audiobus app gets a master list of known keys from a server every 30 minutes • For temporary IDs, click the link from the developer page on the device that you’re using Audiobus on to register your App ID • e.g., audiobus-registry:// developer.audiob.us/tempreg?t=0ff37 • The dev page can mail you the link
  • 31. Set Audiobus-compatible behaviors • Audio Session category must be playback or play-and-record • Must also set the mix-with-others property on the audio session • Often do both these things in the AppDelegate
  • 32. UInt32 audioCategory = kAudioSessionCategory_MediaPlayback; AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(audioCategory), &audioCategory); UInt32 allowMixing = YES; AudioSessionSetProperty(kAudioSessionProperty_OverrideCategory MixWithOthers, sizeof (allowMixing), &allowMixing); Note: Audio Session is deprecated in iOS 7 Modern apps can use the AV Foundation equivalents
  • 33. Setup Your App’s Audio System • Your app’s audio infrastructure needs to be up and running before you connect to Audiobus • If you’re going to send audio via the ABAudioBusAudioUnitWrapper, you’ll need to initialize your AURemoteIO • For the web radio app, I send an NSNotification once the player class starts playing
  • 34. Instantiate ABAudiobusController • ABAudiobusController is your app’s connection to Audiobus; probably gets held as a strong property somewhere • init method takes the launch URL and your API key • Obviously, these must match what you registered on audiob.us
  • 35. self.audiobusController = [[ABAudiobusController alloc] initWithAppLaunchURL: [NSURL URLWithString:@"audiobuswebradio.audiobus://"] apiKey:AUDIOBUS_API_KEY];
  • 36. Create ABOutputPort (and Audio Unit wrapper) • ABOutputPort sends audio to Audiobus (via ABOutputPortSendAudio() function) • If you use a RemoteIO unit for your output, the ABAudiobusAudioUnitWrapper will make these calls for you
  • 37. CCFViewController *vc = (CCFViewController*) self.window.rootViewController; ABOutputPort *output = [self.audiobusController addOutputPortNamed:@"Audio Output" title:NSLocalizedString(@"Main App Output", @"")]; self.audiobusAudioUnitWrapper = [[ABAudiobusAudioUnitWrapper alloc] initWithAudiobusController:self.audiobusController audioUnit:vc.player.remoteIOUnit output:output input:nil];
  • 38. Demo
  • 39. Demo
  • 40. Ports • Apps that don’t use the Audio Unit Wrapper use ports directly instead • ABOutputPortSendAudio() for senders (inputs and filters) • Block-based callback or poll with ABInputPortReceive() for receivers (filters and outputs)
  • 41. Filters & Outputs • If you produce audio output based on input, you need to tell the ABInputPort, so that the signal isn’t doubled in Audiobus.
  • 42. As for iOS 7…
  • 43. iOS 7 Inter-App Audio
  • 44. Sherlocked? Embrace & Extend! From: michael@audiob.us Date: June 19, 2013 Subject: Important Information Regarding Audiobus, iOS 7 and Inter-App Audio iOS 7 introduces many new features, including Apple’s own Inter-App Audio framework which we’re planning to incorporate into Audiobus so you don’t have to. For details and further discussion, we highly recommend checking out our thread on the Apple developer forums: https://devforums.apple.com/thread/191197
  • 45. Closing Thoughts • Audiobus is approachable for developers already working at the Audio Unit level • Adding Audiobus will get it seen by users who’ve proven willing to pay for good apps (we love music app users!) • Future-proofed for iOS 7
  • 46. Q&A Slides & code will be posted to the CocoaConf Glassboard, and announced on my Twitter & app.net (@invalidname)