150
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 What’s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media

What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

What’s New in Core Audio

Session 501 Torrey Holbrook Walker Master of Ceremonies

Media

Page 2: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

What’s New in Core AudioOverview

Core MIDI enhancements

Inter-App Audio UI views

Enhanced AV Foundation audio • Audio Unit Manager

• AVAudioSession

• Utility classes

• AVAudioEngine

Page 3: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

What’s New with Core MIDI

Torrey Holbrook Walker Vice Chair, Itty Bitty MIDI Committee

Page 4: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Your Current MIDI Studio

Mac

Network Session

Drum Machine

Analog Synthesizer

USB MIDI InterfaceUSB MIDI Controller

Page 5: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Your New MIDI Studio

Drum Machine

Analog Synthesizer

USB MIDI Interface

Mac

Mac Bluetooth iPad Bluetooth

Page 6: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

MIDI over Bluetooth

Send and receive MIDI over Bluetooth LE for OS X and iOS

Connection is secure

Appears as an ordinary MIDI device

Page 7: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Bluetooth Overview

Two key roles

Central Peripheral

Page 8: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Bluetooth Overview

Peripheral advertises MIDI capabilities

Central Peripheral

Page 9: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Bluetooth Overview

Peripheral advertises MIDI capabilities

Central Peripheral

Page 10: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Bluetooth Overview

Central scans and connects

Central Peripheral

Page 11: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Bluetooth Overview

Central scans and connects

Central Peripheral

Page 12: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Bluetooth Overview

Bluetooth MIDI I/O via characteristic

Central Peripheral

Page 13: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Bluetooth Overview

Bluetooth MIDI I/O via characteristic

Central Peripheral

Page 14: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

OS X—You’re Ready Already

Audio MIDI Setup • New Bluetooth panel

Page 15: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

OS X—You’re Ready Already

Advertise

Scan/connect

Creates standard MIDI devices

Page 16: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

iOS—CoreAudioKit View Controllers

New UI for Bluetooth MIDI

Required to manage Bluetooth connections for your app

“Scan” or “Advertise”

Unused connections are terminated after a few minutes

Page 17: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

DemoBluetooth MIDI UI on Mac OS X + iOS

Page 18: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Final Thoughts

Works with Mac, iPhone and iPad with native Bluetooth LE support

Low latency

Bluetooth LE bandwidth >> 3,125 B/s

Standardization in the works

Add Bluetooth UI views on iOS

Page 19: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CoreAudioKit Framework

Michael Hopkins Core Audio User Interface Wizard

Page 20: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

What Is CoreAudioKit?

New iOS framework

Provides standardized user interface elements • MIDI over Bluetooth LE

• Inter-App Audio views

Easy to adopt

Works on iPhone and iPad

Page 21: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

MIDI over Bluetooth LEUser interface elements

Michael Hopkins Core Audio User Interface Wizard

Page 22: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

MIDI over Bluetooth LECABTMIDILocalPeripheralViewController

Required to advertise iOS device as a Bluetooth peripheral

Page 23: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Using BLE UI Classes

#import <CoreAudioKit/CoreAudioKit.h>

!

Configuring a local peripheral

!

CABTMIDILocalPeripheralViewController *viewController = [[CABTMIDILocalPeripheralViewController alloc] init]; [self.navigationController pushViewController: viewController animated: YES];

Page 24: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Using BLE UI Classes

#import <CoreAudioKit/CoreAudioKit.h>

!

Configuring a local peripheral

!

CABTMIDILocalPeripheralViewController *viewController = [[CABTMIDILocalPeripheralViewController alloc] init]; [self.navigationController pushViewController: viewController animated: YES];

Page 25: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Using BLE UI Classes

#import <CoreAudioKit/CoreAudioKit.h>

!

Configuring a local peripheral

!

CABTMIDILocalPeripheralViewController *viewController = [[CABTMIDILocalPeripheralViewController alloc] init]; [self.navigationController pushViewController: viewController animated: YES];

Page 26: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

MIDI over Bluetooth LECABTMIDICentralViewController

Required for discovering and connecting to Bluetooth peripherals

Page 27: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Using BLE UI Classes

#import <CoreAudioKit/CoreAudioKit.h>

!

Searching for and connecting to external devices

!

CABTMIDICentralViewController *viewController = [[CABTMIDICentralViewController alloc] init]; [self.navigationController pushViewController: viewController animated: YES];

Page 28: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Using BLE UI Classes

#import <CoreAudioKit/CoreAudioKit.h>

!

Searching for and connecting to external devices

!

CABTMIDICentralViewController *viewController = [[CABTMIDICentralViewController alloc] init]; [self.navigationController pushViewController: viewController animated: YES];

Page 29: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Using BLE UI Classes

#import <CoreAudioKit/CoreAudioKit.h>

!

Searching for and connecting to external devices

!

CABTMIDICentralViewController *viewController = [[CABTMIDICentralViewController alloc] init]; [self.navigationController pushViewController: viewController animated: YES];

Page 30: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Inter-App AudioUser interface elements

Page 31: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Inter-App AudioReview

Streams audio between apps in realtime on iOS

Node apps can be discovered by host apps

See WWDC 2013 Session 206—What’s New in Core Audio for iOS

Page 32: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Inter-App Audio

Host App

Audio

Audio I/O

Node App

Page 33: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Inter-App Audio

Host App

Audio I/O

Node App (Instrument)

Audio

MIDI

Page 34: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Inter-App Audio User Interface ElementsOverview

Inter-App Audio Switcher • Provides a simple way to switch between connected apps

Page 35: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Inter-App Audio User Interface ElementsOverview

Inter-App Audio Host Transport • Displays host transport (play/pause, rewind, and record) controls

0:24

Page 36: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

DemoInter-App Audio user interface elements

Michael Hopkins Core Audio UI Maestro

Page 37: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Inter-App Audio User Interface Elements

Provides a consistent user experience

Flexible sizing

Minimal code required to adopt

Subclass of UIView

Page 38: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioSwitcherViewCreating from a nib file

#import <CoreAudioKit/CoreAudioKit.h> !

IBOutlet CAInterAppAudioSwitcherView *switcherView; !

-(void) viewDidLoad { [super viewDidLoad]; … switcherView.backgroundColor = [UIColor darkGrayColor]; [switcherView setOutputAudioUnit: audioUnit]; }

Page 39: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioSwitcherViewCreating from a nib file

#import <CoreAudioKit/CoreAudioKit.h> !

IBOutlet CAInterAppAudioSwitcherView *switcherView; !

-(void) viewDidLoad { [super viewDidLoad]; … switcherView.backgroundColor = [UIColor darkGrayColor]; [switcherView setOutputAudioUnit: audioUnit]; }

Page 40: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioSwitcherViewCreating from a nib file

#import <CoreAudioKit/CoreAudioKit.h> !

IBOutlet CAInterAppAudioSwitcherView *switcherView; !

-(void) viewDidLoad { [super viewDidLoad]; … switcherView.backgroundColor = [UIColor darkGrayColor]; [switcherView setOutputAudioUnit: audioUnit]; }

Page 41: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioSwitcherViewCreating from a nib file

#import <CoreAudioKit/CoreAudioKit.h> !

IBOutlet CAInterAppAudioSwitcherView *switcherView; !

-(void) viewDidLoad { [super viewDidLoad]; … switcherView.backgroundColor = [UIColor darkGrayColor]; [switcherView setOutputAudioUnit: outputAU]; }

Page 42: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioTransportViewCreating programmatically

CAInterAppAudioTransportView *transportView = [[CAInterAppAudioTransportView alloc] initWithFrame: CGRectMake(0, 0, kTransportViewHeight, kTransportViewWidth)]; !

transportView.rewindButtonColor = transportView.playButtonColor = transportView.pauseButtonColor = [UIColor whiteColor]; transportView.labelColor = [UIColor lightGrayColor]; transportView.backgroundColor = [UIColor darkGrayColor]; [transportView setOutputAudioUnit: outputAU]; !

[self addSubview: transportView];

Page 43: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioTransportViewCreating programmatically

CAInterAppAudioTransportView *transportView = [[CAInterAppAudioTransportView alloc] initWithFrame: CGRectMake(0, 0, kTransportViewHeight, kTransportViewWidth)]; !

transportView.rewindButtonColor = transportView.playButtonColor = transportView.pauseButtonColor = [UIColor whiteColor]; transportView.labelColor = [UIColor lightGrayColor]; transportView.backgroundColor = [UIColor darkGrayColor]; [transportView setOutputAudioUnit: outputAU]; !

[self addSubview: transportView];

Page 44: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioTransportViewCreating programmatically

CAInterAppAudioTransportView *transportView = [[CAInterAppAudioTransportView alloc] initWithFrame: CGRectMake(0, 0, kTransportViewHeight, kTransportViewWidth)]; !

transportView.rewindButtonColor = transportView.playButtonColor = transportView.pauseButtonColor = [UIColor whiteColor]; transportView.labelColor = [UIColor lightGrayColor]; transportView.backgroundColor = [UIColor darkGrayColor]; [transportView setOutputAudioUnit: outputAU]; !

[self addSubview: transportView];

Page 45: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioTransportViewCreating programmatically

CAInterAppAudioTransportView *transportView = [[CAInterAppAudioTransportView alloc] initWithFrame: CGRectMake(0, 0, kTransportViewHeight, kTransportViewWidth)]; !

transportView.rewindButtonColor = transportView.playButtonColor = transportView.pauseButtonColor = [UIColor whiteColor]; transportView.labelColor = [UIColor lightGrayColor]; transportView.backgroundColor = [UIColor darkGrayColor]; [transportView setOutputAudioUnit: outputAU]; !

[self addSubview: transportView];

Page 46: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

CAInterAppAudioTransportViewCreating programmatically

CAInterAppAudioTransportView *transportView = [[CAInterAppAudioTransportView alloc] initWithFrame: CGRectMake(0, 0, kTransportViewHeight, kTransportViewWidth)]; !

transportView.rewindButtonColor = transportView.playButtonColor = transportView.pauseButtonColor = [UIColor whiteColor]; transportView.labelColor = [UIColor lightGrayColor]; transportView.backgroundColor = [UIColor darkGrayColor]; [transportView setOutputAudioUnit: outputAU]; !

[self addSubview: transportView];

Page 47: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Managing Audio UnitsUsing AVAudioUnitComponentManager

Michael Hopkins Audio Unit Wrangler

Page 48: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioUnitComponentManagerIntroduction

Objective-C based API for Audio Unit host applications

Querying methods for Audio Units

Simple API for getting information about Audio Units

Audio Unit tagging facilities

Centralized Audio Unit cache

Page 49: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioUnitComponentManager API

New classes in AV Foundation

AVAudioUnitComponentManager • Provides multiple search mechanisms

- NSPredicates

- Block-based

- Backwards-compatibility mode using AudioComponentDescriptions

AVAudioUnitComponent • Provides information about individual Audio Units

Page 50: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Getting Information About an Audio UnitFinding all stereo effects using AudioComponent API

#include <AudioUnit/AUComponent.h> #include <AudioUnit/AudioUnit.h> #include <AudioUnit/AudioUnitProperties.h> !

AudioComponentDescription desc = {kAudioUnitType_Effect, 0, 0, 0, 0}; AudioComponent comp = NULL; while (comp = AudioComponentFindNext(comp, &desc)) { AudioUnit au; if (AudioComponentInstanceNew(comp, &au) != noErr) { AudioStreamBasicDescription inputDesc, outputDesc; UInt32 dataSize = sizeof(AudioStreamBasicDescription); OSStatus result1 = AudioUnitGetProperty(au, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &inputDesc, &dataSize);

Page 51: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Getting Information About an Audio UnitFinding all stereo effects continued

OSStatus result2 = AudioUnitGetProperty(au, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &outputDesc, &dataSize); if (result1 != noErr || result2 != noErr) continue; if (inputDesc.mChannelsPerFrame == 2 && outputDesc.mChannelsPerFrame == 2) { // do something with the component to store it into a list // then close the Audio Unit } } }

Page 52: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Getting Information About an Audio UnitFinding all stereo effects using AVAudioUnitComponentManager API

#import <AVFoundation/AVAudioUnitComponent.h> !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsPassingTest: ^(AVAudioUnitComponent *comp, BOOL *stop) { return [[comp typeName] isEqualToString: AVAudioUnitTypeEffect] && [comp supportsNumberInputChannels: 2 outputChannels: 2]; }];

Page 53: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Getting Information About an Audio UnitFinding all stereo effects using AVAudioUnitComponentManager API

#import <AVFoundation/AVAudioUnitComponent.h> !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsPassingTest: ^(AVAudioUnitComponent *comp, BOOL *stop) { return [[comp typeName] isEqualToString: AVAudioUnitTypeEffect] && [comp supportsNumberInputChannels: 2 outputChannels: 2]; }];

Page 54: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Getting Information About an Audio UnitFinding all stereo effects using AVAudioUnitComponentManager API

#import <AVFoundation/AVAudioUnitComponent.h> !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsPassingTest: ^(AVAudioUnitComponent *comp, BOOL *stop) { return [[comp typeName] isEqualToString: AVAudioUnitTypeEffect] && [comp supportsNumberInputChannels: 2 outputChannels: 2]; }];

Page 55: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Getting Information About an Audio UnitFinding all stereo effects using AVAudioUnitComponentManager API

#import <AVFoundation/AVAudioUnitComponent.h> !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsPassingTest: ^(AVAudioUnitComponent *comp, BOOL *stop) { return [[comp typeName] isEqualToString: AVAudioUnitTypeEffect] && [comp supportsNumberInputChannels: 2 outputChannels: 2]; }];

Page 56: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Getting Information About an Audio UnitFinding all stereo effects using AVAudioUnitComponentManager API

#import <AVFoundation/AVAudioUnitComponent.h> !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsPassingTest: ^(AVAudioUnitComponent *comp, BOOL *stop) { return [[comp typeName] isEqualToString: AVAudioUnitTypeEffect] && [comp supportsNumberInputChannels: 2 outputChannels: 2];}];

Page 57: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Tagging Audio UnitsIntroduction

Many users have lots of Audio Units…

Finding the right one can be difficult

Page 58: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioUnitComponentManagerTags

Audio Units can have one or more tags

System tags • Defined by creator of Audio Unit (read-only)

User tags • Specified by current user (read/write)

• Each user can have a unique set of tags

Page 59: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioUnitComponentManagerTags continued

A tag is a localized string • Arbitrary

• Predefined (AudioComponent.h)

- Type (equalizer, dynamics, distortion, etc.)

- Usage (drums, guitar, vocal, etc.)

Page 60: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

DemoAudio Unit tags in AU Lab

Michael Hopkins Audio Unit Scientist

Page 61: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Finding Audio Units with a Specific Tag

#import <AVFoundation/AVAudioUnitComponent.h> !

NSString *aString = @“My Favorite Tag”; NSPredicate *aPredicate = [NSPredicate predicateWithFormat: @"allTagNames CONTAINS[cd] %@", aString]; !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsMatchingPredicate: aPredicate];

Page 62: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Finding Audio Units with a Specific Tag

#import <AVFoundation/AVAudioUnitComponent.h> !

NSString *aString = @“My Favorite Tag”; NSPredicate *aPredicate = [NSPredicate predicateWithFormat: @"allTagNames CONTAINS[cd] %@", aString]; !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsMatchingPredicate: aPredicate];

Page 63: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Finding Audio Units with a Specific Tag

#import <AVFoundation/AVAudioUnitComponent.h> !

NSString *aString = @“My Favorite Tag”; NSPredicate *aPredicate = [NSPredicate predicateWithFormat: @"allTagNames CONTAINS[cd] %@", aString]; !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsMatchingPredicate: aPredicate];

Page 64: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Finding Audio Units with a Specific Tag

#import <AVFoundation/AVAudioUnitComponent.h> !

NSString *aString = @“My Favorite Tag”; NSPredicate *aPredicate = [NSPredicate predicateWithFormat: @"allTagNames CONTAINS[cd] %@", aString]; !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsMatchingPredicate: aPredicate];

Page 65: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Finding Audio Units with a Specific Tag

#import <AVFoundation/AVAudioUnitComponent.h> !

NSString *aString = @“My Favorite Tag”; NSPredicate *aPredicate = [NSPredicate predicateWithFormat: @"allTagNames CONTAINS[cd] %@", aString]; !

NSArray *components = [[AVAudioUnitComponentManager sharedAudioUnitManager] componentsMatchingPredicate: aPredicate];

Page 66: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Tagging Facilities

Getting user tags of an AVAudioUnitComponent NSArray *userTags = aComp.userTagNames;

!

Page 67: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Tagging Facilities

Getting user tags of an AVAudioUnitComponent NSArray *userTags = aComp.userTagNames;

!

Page 68: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Tagging Facilities

Getting user tags of an AVAudioUnitComponent NSArray *userTags = aComp.userTagNames;

!

Setting user tags of an AVAudioUnitComponent aComp.userTagNames = @[@“Trippy”, @“Favorites”];

Page 69: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Tagging Facilities

Getting user tags of an AVAudioUnitComponent NSArray *userTags = aComp.userTagNames;

!

Setting user tags of an AVAudioUnitComponent aComp.userTagNames = @[@“Trippy”, @“Favorites”];

Page 70: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Tagging Facilities

Getting user tags of an AVAudioUnitComponent NSArray *userTags = aComp.userTagNames;

!

Setting user tags of an AVAudioUnitComponent aComp.userTagNames = @[@“Trippy”, @“Favorites”];

!

Getting all tags of an AVAudioUnitComponent NSArray *allTags = aComp.allTagNames;

!

Page 71: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Tagging Facilities

Getting user tags of an AVAudioUnitComponent NSArray *userTags = aComp.userTagNames;

!

Setting user tags of an AVAudioUnitComponent aComp.userTagNames = @[@“Trippy”, @“Favorites”];

!

Getting all tags of an AVAudioUnitComponent NSArray *allTags = aComp.allTagNames;

!

Page 72: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

More Tagging Facilities

Getting a localized list of standard system tags AVAudioUnitComponentManager *manager = [AVAudioUnitComponentManager sharedAudioUnitComponentManager]; !

NSArray *standardTags = manager.standardLocalizedTagNames;

Page 73: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

More Tagging Facilities

Getting a localized list of standard system tags AVAudioUnitComponentManager *manager = [AVAudioUnitComponentManager sharedAudioUnitComponentManager]; !

NSArray *standardTags = manager.standardLocalizedTagNames;

Page 74: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

More Tagging Facilities

Getting a localized list of standard system tags AVAudioUnitComponentManager *manager = [AVAudioUnitComponentManager sharedAudioUnitComponentManager]; !

NSArray *standardTags = manager.standardLocalizedTagNames;

Page 75: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

More Tagging Facilities

Getting a localized list of standard system tags AVAudioUnitComponentManager *manager = [AVAudioUnitComponentManager sharedAudioUnitComponentManager]; !

NSArray *standardTags = manager.standardLocalizedTagNames; !

Getting a complete list of all available localized tags NSArray *allTags = manager.tagNames;

Page 76: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

More Tagging Facilities

Getting a localized list of standard system tags AVAudioUnitComponentManager *manager = [AVAudioUnitComponentManager sharedAudioUnitComponentManager]; !

NSArray *standardTags = manager.standardLocalizedTagNames; !

Getting a complete list of all available localized tags NSArray *allTags = manager.tagNames;

Page 77: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Adding Built-in Tags to an AudioUnit

Add a tags section to Info.plist of AudioComponent bundle <key>tags</key> <array> <string>Effect</string> <string>Equalizer</string> <string>Custom Tag</string> </array>

Page 78: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Adding Built-in Tags to an AudioUnit

Add a tags section to Info.plist of AudioComponent bundle <key>tags</key> <array> <string>Effect</string> <string>Equalizer</string> <string>Custom Tag</string> </array>

Page 79: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Adding Built-in Tags to an AudioUnit

Add a tags section to Info.plist of AudioComponent bundle <key>tags</key> <array> <string>Effect</string> <string>Equalizer</string> <string>Custom Tag</string> </array>

Page 80: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Adding Built-in Tags to an AudioUnit

Add a tags section to Info.plist of AudioComponent bundle <key>tags</key> <array> <string>Effect</string> <string>Equalizer</string> <string>Custom Tag</string> </array>

!

Localize Custom Tag by adding AudioUnitTags.strings file in bundle “Custom Tag” = “Localized Tag”;

Page 81: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Adding Built-in Tags to an AudioUnit

Add a tags section to Info.plist of AudioComponent bundle <key>tags</key> <array> <string>Effect</string> <string>Equalizer</string> <string>Custom Tag</string> </array>

!

Localize Custom Tag by adding AudioUnitTags.strings file in bundle “Custom Tag” = “Localized Tag”;

Page 82: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Adding Built-in Tags to an AudioUnit

Add a tags section to Info.plist of AudioComponent bundle <key>tags</key> <array> <string>Effect</string> <string>Equalizer</string> <string>Custom Tag</string> </array>

!

Localize Custom Tag by adding AudioUnitTags.strings file in bundle “Custom Tag” = “Localized Tag”;

!

Do not localize Standard System Tags!

Page 83: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Action Items

Users • Tag your Audio Units

Host developers • Adopt AVAudioUnitComponentManager API

• Surprise and delight your users

Audio Unit developers • Add system tags to your Audio Units

Page 84: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioSession Tips

Eric Johnson Audio Traffic Controller

Page 85: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

References

Updated audio session programming guide

https://developer.apple.com/library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide

!

WWDC 2012 Session 505—Audio Session and Multiroute Audio in iOS

Page 86: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Managing Session Activation StateApp state vs. audio session activation state

App state • Not running

• Foreground inactive/foreground active

• Background

• Suspended

Audio session activation state • Active or inactive

• Interruptions

Page 87: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

Phone audio session

Page 88: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

User launches App

Phone audio session

Page 89: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

Activate session and begin playback

Phone audio session

Page 90: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

Phone audio session

Page 91: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

Interrupted by phone call

Phone audio session

Page 92: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

Phone audio session

ring

Page 93: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

Phone audio session

ring

Page 94: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

Phone audio session

Page 95: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

User ends call, interruption ends

Phone audio session

Page 96: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Session State Changes

Your audio session

Phone audio session

Reactivate session, resume playback

Page 97: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Managing Session Activation StateNeeds vary by application type

Games

Media playback

VoIP and chat apps

Metering and monitoring apps

Browser-like apps

Navigation and fitness apps

Music-making apps

Page 98: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Managing Session Activation StateActivation

Game apps • Go active upon app delegate’s applicationDidBecomeActive: method

• Handle interruptions

- Begin—Update internal state

- End—Go active and resume audio playback

Page 99: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Managing Session Activation StateActivation

Media playback apps • Music, podcasts, streaming radio

• Go active when the user presses “play” button

• Stay active, unless interrupted

• Handle interruptions

- Begin—Update UI and internal state

- End—Honor AVAudioSessionInterruptionOptionShouldResume

Page 100: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Managing Session Activation StateDeactivation

End ducking of other audio • Navigation/Fitness

Allow other audio to resume • VoIP/Chat

• Short videos in browser views

• AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation

Page 101: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary AudioPrimary vs. secondary audio

Game App

Primary Audio Secondary Audio

Page 102: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

secondaryAudioShouldBeSilencedHint • Hint to foreground app for silencing secondary audio

• Check in app delegate’s applicationDidBecomeActive: method

!

Page 103: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

secondaryAudioShouldBeSilencedHint • Hint to foreground app for silencing secondary audio

• Check in app delegate’s applicationDidBecomeActive: method

!

AVAudioSessionSilenceSecondaryAudioHintNotification • Delivered to foreground, active audio sessions

• Begin—Mute secondary audio

• End—Resume secondary audio

Page 104: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

(Background)Music AppGame App

(Foreground)

Page 105: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

Begin Playing

Game App(Foreground) (Background)

Music App

Page 106: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

Notification Begin Playing

Game App(Foreground) (Background)

Music App

Page 107: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

(Background)Music App

Notification Begin Playing

Game App(Foreground)

Page 108: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

Game App(Foreground) (Background)

Music App

Page 109: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

(Background)Music App

Pauses

Game App(Foreground)

Page 110: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

(Background)Music App

PausesNotification

Game App(Foreground)

Page 111: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary Audio

(Background)Music App

PausesNotification

Game App(Foreground)

Page 112: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Muting Secondary AudioUpdated best practices

Do not change category based on isOtherAudioPlaying

Use AVAudioSessionCategoryAmbient

Use secondaryAudioShouldBeSilencedHint

Use AVAudioSessionSilenceSecondaryAudioHintNotification

Page 113: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

New AV Foundation Audio Classes

Doug Wyatt Core Audio Syntactic Confectioner

Page 114: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

New AV Foundation Audio Classes

Introduction

Tour of the classes

Example

Page 115: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Introduction

Core Audio/AudioToolbox—Powerful but not always simple

Historically—C++ classes in Core Audio SDK

New—Objective-C classes in AVFoundation.framework

Available—OS X 10.10 and iOS 8.0

Page 116: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Goals

Wrap C structs in Objective-C • Simpler to build

• Can be passed to low-level APIs

AVAudioEngine

Stay realtime-safe

Page 117: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Classes

AVAudioFile AVAudioPCMBuffer

AVAudioChannelLayout

has

uses

has

has

AVAudioFormat

Page 118: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFormat

AVAudioFile AVAudioPCMBuffer

AVAudioChannelLayout

AVAudioFormat

Page 119: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Describes data in audio file or stream

Wraps struct AudioStreamBasicDescription { Float64 mSampleRate; UInt32 mFormatID; UInt32 mFormatFlags; UInt32 mBytesPerPacket; UInt32 mFramesPerPacket; UInt32 mBytesPerFrame; UInt32 mChannelsPerFrame; UInt32 mBitsPerChannel; UInt32 mReserved; };

!- (instancetype)initWithStreamDescription: (const AudioStreamBasicDescription *)asbd; !@property (nonatomic, readonly) const AudioStreamBasicDescription *streamDescription;

AVAudioFormat

Page 120: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

“Standard” Formats

“Canonical” • Was float on OS X, 8.24 fixed-point on iOS

• Now deprecated

“Standard” • Non-interleaved 32-bit float

• On both platforms !

(instancetype)initStandardFormatWithSampleRate: (double)sampleRate channels:(AVAudioChannelCount)channels; !

@property (nonatomic, readonly, getter=isStandard) BOOL standard;

Page 121: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

“Common” Formats

Formats often used in signal processing

Always native-endian typedef NS_ENUM(NSUInteger, AVAudioCommonFormat) { AVAudioOtherFormat = 0, AVAudioPCMFormatFloat32 = 1, AVAudioPCMFormatFloat64 = 2, AVAudioPCMFormatInt16 = 3, AVAudioPCMFormatInt32 = 4 }; !- (instancetype)initWithCommonFormat:(AVAudioCommonFormat)format sampleRate:(double)sampleRate channels:(AVAudioChannelCount)channels interleaved:(BOOL)interleaved; !@property (nonatomic, readonly) AVAudioCommonFormat commonFormat;

Page 122: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile AVAudioPCMBuffer

AVAudioFormat

AVAudioChannelLayout

AVAudioChannelLayout

Page 123: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioChannelLayout

Describes ordering/roles of multiple channels

AVAudioFormat has an AVAudioChannelLayout

AVAudioFormat initializers require a layout when describing > 2 channels

Wraps AudioChannelLayout (CoreAudioTypes.h)

Page 124: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFormat

AVAudioFile

AVAudioChannelLayout

AVAudioPCMBuffer

AVAudioPCMBuffer

Page 125: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioPCMBuffer

Memory for storing audio data in any PCM format

Wraps struct AudioBuffer { UInt32 mNumberChannels; UInt32 mDataByteSize; void * mData; }; struct AudioBufferList { UInt32 mNumberBuffers; AudioBuffer mBuffers[1]; // variable length }; !

@property (nonatomic, readonly) const AudioBufferList *audioBufferList; @property (nonatomic, readonly) AudioBufferList *mutableAudioBufferList;

Page 126: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioPCMBuffer

- (instancetype)initWithPCMFormat:(AVAudioFormat *)format frameCapacity:(AVAudioFrameCount)frameCapacity; !

Has an AVAudioFormat @property (nonatomic, readonly) AVAudioFormat *format;

!

Has separate frame capacity and length @property (nonatomic, readonly) AVAudioFrameCount frameCapacity; !@property (nonatomic) AVAudioFrameCount frameLength;

Page 127: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioPCMBuffer

Sample access @property (nonatomic, readonly) float * const *floatChannelData; @property (nonatomic, readonly) int16_t * const *int16ChannelData; @property (nonatomic, readonly) int32_t * const *int32ChannelData;

!

Realtime-safety • Don’t access buffer’s properties on audio I/O thread

• Cache AudioBufferList pointer or one of the above pointer arrays

Page 128: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile

AVAudioPCMBuffer

AVAudioFormat

AVAudioChannelLayout

AVAudioFile

Page 129: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile

Read and write files of any supported format

Transparently decodes while reading, encodes while writing

“Processing format” • Specified at initialization

• Either standard or common

Similar to ExtAudioFile

Page 130: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile Initializers and Formats

Page 131: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile Initializers and Formats

- (instancetype)initForReading:(NSURL *)fileURL error:(NSError **)outError;

Page 132: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile Initializers and Formats

- (instancetype)initForReading:(NSURL *)fileURL error:(NSError **)outError;

- (instancetype)initForWriting:(NSURL *)fileURL settings:(NSDictionary *)settings error:(NSError **)outError;

Page 133: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile Initializers and Formats

- (instancetype)initForReading:(NSURL *)fileURL error:(NSError **)outError;

- (instancetype)initForWriting:(NSURL *)fileURL settings:(NSDictionary *)settings error:(NSError **)outError;

@property (nonatomic, readonly) AVAudioFormat *fileFormat;

Page 134: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile Initializers and Formats

- (instancetype)initForReading:(NSURL *)fileURL error:(NSError **)outError;

- (instancetype)initForWriting:(NSURL *)fileURL settings:(NSDictionary *)settings error:(NSError **)outError;

@property (nonatomic, readonly) AVAudioFormat *fileFormat;@property (nonatomic, readonly) AVAudioFormat *processingFormat;

Page 135: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile I/O

Page 136: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile I/O

- (BOOL)readIntoBuffer:(AVAudioPCMBuffer *)buffer error:(NSError **)outError;

Page 137: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile I/O

- (BOOL)readIntoBuffer:(AVAudioPCMBuffer *)buffer error:(NSError **)outError;

- (BOOL)writeFromBuffer:(const AVAudioPCMBuffer *)buffer error:(NSError **)outError;

Page 138: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AVAudioFile I/O

- (BOOL)readIntoBuffer:(AVAudioPCMBuffer *)buffer error:(NSError **)outError;

- (BOOL)writeFromBuffer:(const AVAudioPCMBuffer *)buffer error:(NSError **)outError;

@property (nonatomic) AVAudioFramePosition framePosition;

Page 139: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Example—Reading an Audio FileOpen the file

static BOOL AudioFileInfo(NSURL *fileURL) { NSError *error = nil; AVAudioFile *audioFile = [[AVAudioFile alloc] initForReading: fileURL commonFormat: AVAudioPCMFormatFloat32 interleaved: NO error: &error]; !

Page 140: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Fetch and print basic info

NSLog(@“File URL: %@\n”, fileURL.absoluteString); NSLog(@“File format: %@\n”, audioFile.fileFormat.description); NSLog(@“Processing format: %@\n”, audioFile.processingFormat.description); AVAudioFramePosition fileLength = audioFile.length; NSLog(@“Length: %lld frames, %.3f seconds\n", (long long)fileLength, fileLength / audioFile.fileFormat.sampleRate);

Page 141: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Create a buffer to read into

const AVAudioFrameCount kBufferFrameCapacity = 128 * 1024L; AVAudioPCMBuffer *readBuffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat: audioFile.processingFormat frameCapacity: kBufferFrameCapacity];

Page 142: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Read the file a buffer at a time to find the loudest sample float loudestSample = 0.0f; AVAudioFramePosition loudestSamplePosition = 0; !! while (audioFile.framePosition < fileLength) { AVAudioFramePosition readPosition = audioFile.framePosition; if (![audioFile readIntoBuffer: readBuffer error: &error]) { NSLog(@"failed to read audio file: %@", error); return NO; } if (readBuffer.frameLength == 0) break; // finished

Page 143: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

For each channel, check each audio sample

for (AVAudioChannelCount channelIndex = 0; channelIndex < readBuffer.format.channelCount; ++channelIndex) { float *channelData = readBuffer.floatChannelData[channelIndex]; for (AVAudioFrameCount frameIndex = 0; frameIndex < readBuffer.frameLength; ++frameIndex) { float sampleAbsLevel = fabs(channelData[frameIndex]); if (sampleAbsLevel > loudestSample) { loudestSample = sampleAbsLevel; loudestSamplePosition = readPosition + frameIndex; }

Page 144: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

With AVAudioEngine Classes

AVAudioFile AVAudioPCMBuffer AVAudioFormat

AVAudioPlayerNode

AVAudioNode has

uses

is a

uses

Page 145: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

AV Foundation Audio—Summary

Classes • AVAudioFormat

• AVAudioChannelLayout

• AVAudioPCMBuffer

• AVAudioFile

Use with Core Audio, Audio Toolbox and Audio Unit C APIs • Via accessors

AVAudioEngine

Page 146: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Summary

MIDI over Bluetooth

Inter-App Audio UI Views

Enhanced AV Foundation audio • Audio Unit Manager

• AVAudioSession

• Utility classes

• AVAudioEngine

Page 147: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

More Information

Filip Iliescu Graphics and Game Technologies Evangelist [email protected]

!

Apple Developer Forums http://devforums.apple.com

Page 148: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Related Sessions

• AVAudioEngine in Practice Marina Tuesday 10:15AM

Page 149: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X

Labs

• Audio Lab Media Lab A Tuesday 11:30AM

• Audio Lab Media Lab B Wednesday 12:45PM

Page 150: What’s New in Core Audio - Apple Inc.€™s New in Core Audio Session 501 Torrey Holbrook Walker Master of Ceremonies Media. ... Send and receive MIDI over Bluetooth LE for OS X