What's New in Core Audio
Transcript of What's New in Core Audio
![Page 1: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/1.jpg)
© 2015 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.
#WWDC15
What’s New in Core Audio
Akshatha Nagesh ‘AudioEngine’erTorrey Holbrook Walker Senior New Feature Salesperson
Media
Session 507
![Page 2: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/2.jpg)
Agenda
AVAudioEngine• Recap• What’s New
Inter-device AudioAVAudioSession• What’s New
Audio Unit Extensions Nob Hill Thursday 11:00 AM
![Page 3: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/3.jpg)
AVAudioEngineRecap
![Page 4: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/4.jpg)
Core Audio StackiOS and OS X
AudioToolbox
CoreAudio and Drivers
OpenAL
Audio Codecs
MIDI
Application
AVAudioSessionAVAudioPlayer
AVAudioRecorderAVAudioEngine
AVFoundation
AVAudioEngine• Introduced in iOS 8.0/OS X 10.10• Refer to WWDC14 session 502
AVAudioEngine in Practice
![Page 5: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/5.jpg)
AVAudioEngineGoals
Provide powerful, feature-rich API setAchieve simple as well as complex tasksSimplify real-time audio
![Page 6: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/6.jpg)
AVAudioEngineFeatures
Objective-C / Swift API setLow latency, real-time audioPlay and record audioConnect audio processing blocksCapture audio at any point in the processing chainImplement 3D audio for games
![Page 7: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/7.jpg)
AVAudioEngineBuilding blocks
Node-AVAudioNode• Source nodes: Provide data for rendering• Processing nodes: Process data• Destination node: Terminating node connected to output hardware
![Page 8: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/8.jpg)
Sample Engine SetupKaraoke
NodeTapBlock(Analyze)
InputNode EffectNode(Delay)
PlayerNode(Backing Track)
PlayerNode(Sound Effects)
MixerNode OutputNode
![Page 9: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/9.jpg)
Sample Engine SetupKaraoke
Source nodes
NodeTapBlock(Analyze)
InputNode EffectNode(Delay)
PlayerNode(Backing Track)
PlayerNode(Sound Effects)
MixerNode OutputNode
![Page 10: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/10.jpg)
Sample Engine SetupKaraoke
Processing nodes
NodeTapBlock(Analyze)
InputNode EffectNode(Delay)
PlayerNode(Backing Track)
PlayerNode(Sound Effects)
MixerNode OutputNode
![Page 11: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/11.jpg)
Sample Engine SetupKaraoke
Destination node
NodeTapBlock(Analyze)
InputNode EffectNode(Delay)
PlayerNode(Backing Track)
PlayerNode(Sound Effects)
MixerNode OutputNode
![Page 12: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/12.jpg)
Mixer Nodes
AVAudioMixerNode• Performs sample rate conversion, up/down mixing of channels• Supports mono, stereo and multichannel inputs
AVAudioEnvironmentNode• Simulates a 3D space (listener is implicit)• Supports mono and stereo inputs• Spatializes only mono inputs
![Page 13: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/13.jpg)
AVAudioMixing Protocol
Defines properties for a mixer input busSource nodes conform to this protocol• Properties cached when not connected to a mixer• Properties applied on connection to a mixer
![Page 14: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/14.jpg)
AVAudioMixing ProtocolProperties
Common (all mixer nodes)• volume - player.volume = 0.5 Stereo (AVAudioMixerNode)• pan - player.pan = -1.03D (AVAudioEnvironmentNode)• position - player.position = AVAudioMake3DPoint(-2.0, 0.0, 5.0)• obstruction, occlusion, renderingAlgorithm and more…
![Page 15: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/15.jpg)
AVAudioMixing ProtocolSample setup
PlayerNodeMixerNode
(Main Mixer)
EnvironmentNode
MixerNode
![Page 16: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/16.jpg)
AVAudioMixing ProtocolSample setup
properties are cached
PlayerNodeMixerNode
(Main Mixer)volume = 0.5
pan = -1.0position = (-1, 2, -5)
Mixing Settings
EnvironmentNode
MixerNode
![Page 17: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/17.jpg)
AVAudioMixing ProtocolSample setup
PlayerNodeMixerNode
(Main Mixer)volume = 0.5
pan = -1.0position = (-1, 2, -5)
Mixing Settings
EnvironmentNode
MixerNode
volume and pan take effect
![Page 18: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/18.jpg)
AVAudioMixing ProtocolSample setup
PlayerNode
volume and position take effect
MixerNode(Main Mixer)
volume = 0.5pan = -1.0
position = (-1, 2, -5)
Mixing Settings
EnvironmentNode
MixerNode
![Page 19: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/19.jpg)
Handling Multichannel Audio
Hardware setup• OS X• iOS
AVAudioEngine setup
![Page 20: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/20.jpg)
Handling Multichannel Audio
User can configure the hardware through Audio MIDI Setup
Hardware setup: OS X
![Page 21: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/21.jpg)
Handling Multichannel AudioHardware setup: iOS
Configure AVAudioSession• Playback use case:
- Activate audio session- Check maximumOutputNumberOfChannels- Set preferredOutputNumberOfChannels- Verify actual outputNumberOfChannels
![Page 22: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/22.jpg)
Handling Multichannel Audio
// example: audio playback use case do {
let desiredNumChannels = 6 // for 5.1 rendering
let audioSession = AVAudioSession.sharedInstance() let category = AVAudioSessionCategoryPlayback
try audioSession.setCategory(category) try audioSession.setActive(true)
// check maximum available output number of channels let maxChannels = audioSession.maximumOutputNumberOfChannels
Hardware setup: iOS-code example
![Page 23: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/23.jpg)
Handling Multichannel AudioHardware setup: iOS-code example
// example: audio playback use case do {
let desiredNumChannels = 6 // for 5.1 rendering
let audioSession = AVAudioSession.sharedInstance() let category = AVAudioSessionCategoryPlayback
try audioSession.setCategory(category) try audioSession.setActive(true)
// check maximum available output number of channels let maxChannels = audioSession.maximumOutputNumberOfChannels
![Page 24: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/24.jpg)
Handling Multichannel AudioHardware setup: iOS-code example
// example: audio playback use case do {
let desiredNumChannels = 6 // for 5.1 rendering
let audioSession = AVAudioSession.sharedInstance() let category = AVAudioSessionCategoryPlayback
try audioSession.setCategory(category) try audioSession.setActive(true)
// check maximum available output number of channels let maxChannels = audioSession.maximumOutputNumberOfChannels
![Page 25: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/25.jpg)
Handling Multichannel Audio
if maxChannels >= desiredNumChannels { // set preferred number of output channels try audioSession.setPreferredOutputNumberOfChannels(desiredNumChannels)
} let actualChannelCount = audioSession.outputNumberOfChannels
// adapt to the actual number of output channels ..
} catch { // handle errors
}
Hardware setup: iOS-code example
![Page 26: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/26.jpg)
Handling Multichannel Audio
if maxChannels >= desiredNumChannels { // set preferred number of output channels try audioSession.setPreferredOutputNumberOfChannels(desiredNumChannels)
} let actualChannelCount = audioSession.outputNumberOfChannels
// adapt to the actual number of output channels ..
} catch { // handle errors
}
Hardware setup: iOS-code example
![Page 27: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/27.jpg)
Handling Multichannel Audio
Multichannel content• AVAudioMixerNode
Spatialized content (games)• AVAudioEnvironmentNode
AVAudioEngine setup: iOS / OS X
![Page 28: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/28.jpg)
Handling Multichannel Audio
PlayerNode OutputNodeMixerNodeMultichannel
Hardware(5.1)
MultichannelContent
(5.1)
AVAudioEngine setup: multichannel content
![Page 29: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/29.jpg)
Handling Multichannel Audio
set connection format get hardware format
PlayerNode OutputNodeMixerNodeMultichannel
Hardware(5.1)
MultichannelContent
(5.1)
AVAudioEngine setup: multichannel content
![Page 30: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/30.jpg)
Handling Multichannel Audio
// get output hardware format let output = engine.outputNode let outputHWFormat = output.outputFormatForBus(0)
// connect mixer to output let mainMixer = engine.mainMixerNode engine.connect(mainMixer, to: output, format: outputHWFormat)
set connection format get hardware format
PlayerNode OutputNodeMixerNodeMultichannel
Hardware(5.1)
MultichannelContent
(5.1)
AVAudioEngine setup: multichannel content
![Page 31: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/31.jpg)
Handling Multichannel Audio
// get output hardware format let output = engine.outputNode let outputHWFormat = output.outputFormatForBus(0)
// connect mixer to output let mainMixer = engine.mainMixerNode engine.connect(mainMixer, to: output, format: outputHWFormat)
set connection format get hardware format
PlayerNode OutputNodeMixerNodeMultichannel
Hardware(5.1)
MultichannelContent
(5.1)
AVAudioEngine setup: multichannel content
![Page 32: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/32.jpg)
Handling Multichannel Audio
get content format set connection format
PlayerNode OutputNodeMixerNodeMultichannel
Hardware(5.1)
MultichannelContent
(5.1)
AVAudioEngine setup: multichannel content
![Page 33: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/33.jpg)
Handling Multichannel Audio
do { // open multichannel file for reading let mcFile = try AVAudioFile(forReading: fileURL)
// connect player to mixer engine.connect(player, to: mainMixer, format: mcFile.processingFormat)
} catch { .. }
get content format set connection format
PlayerNode OutputNodeMixerNodeMultichannel
Hardware(5.1)
MultichannelContent
(5.1)
AVAudioEngine setup: multichannel content
![Page 34: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/34.jpg)
Handling Multichannel Audio
// schedule file on player // start engine // start player
channel mapping
PlayerNode OutputNodeMixerNodeMultichannel
Hardware(5.1)
MultichannelContent
(5.1)
AVAudioEngine setup: multichannel content
![Page 35: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/35.jpg)
Handling Multichannel Audio
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 36: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/36.jpg)
Handling Multichannel Audio
set compatible format get hardware format
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 37: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/37.jpg)
Handling Multichannel Audio
// map output hardware channel layout to a compatible layout let layoutTag = kAudioChannelLayoutTag_AudioUnit_5_0 // for 5.1 HW layout let layout = AVAudioChannelLayout(layoutTag: layoutTag) let envOutputFormat = AVAudioFormat(
standardFormatWithSampleRate: outputHWFormat.sampleRate, channelLayout: layout);
engine.connect(envNode, to: output, format: envOutputFormat)
set compatible format get hardware format
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 38: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/38.jpg)
Handling Multichannel Audio
// map output hardware channel layout to a compatible layout let layoutTag = kAudioChannelLayoutTag_AudioUnit_5_0 // for 5.1 HW layout let layout = AVAudioChannelLayout(layoutTag: layoutTag) let envOutputFormat = AVAudioFormat(
standardFormatWithSampleRate: outputHWFormat.sampleRate, channelLayout: layout);
engine.connect(envNode, to: output, format: envOutputFormat)
set compatible format get hardware format
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 39: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/39.jpg)
Handling Multichannel Audio
// map output hardware channel layout to a compatible layout let layoutTag = kAudioChannelLayoutTag_AudioUnit_5_0 // for 5.1 HW layout let layout = AVAudioChannelLayout(layoutTag: layoutTag) let envOutputFormat = AVAudioFormat(
standardFormatWithSampleRate: outputHWFormat.sampleRate, channelLayout: layout);
engine.connect(envNode, to: output, format: envOutputFormat)
set compatible format get hardware format
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 40: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/40.jpg)
Handling Multichannel Audio
get content format set connection format
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 41: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/41.jpg)
Handling Multichannel Audio
let file = try AVAudioFile(forReading: fileURL) engine.connect(player, to: envNode, format: file.processingFormat)
// set multichannel rendering algorithm player.renderingAlgorithm = AVAudio3DMixingRenderingAlgorithm.SoundField
get content format set connection format
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 42: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/42.jpg)
Handling Multichannel Audio
let file = try AVAudioFile(forReading: fileURL) engine.connect(player, to: envNode, format: file.processingFormat)
// set multichannel rendering algorithm player.renderingAlgorithm = AVAudio3DMixingRenderingAlgorithm.SoundField
get content format set connection format
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 43: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/43.jpg)
Handling Multichannel Audio
// schedule file on player // start engine // start player
spatial mapping
PlayerNode OutputNodeEnvironmentNode
MultichannelHardware
(5.1)Mono
Content
AVAudioEngine setup: spatialized content
![Page 44: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/44.jpg)
AVAudioEngineWhat’s new
![Page 45: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/45.jpg)
AVAudioEngineWhat’s new
Splitting supportAudio format conversion support• AVAudioCompressedBuffer• AVAudioConverter
AVAudioSequencer
![Page 46: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/46.jpg)
AVAudioEngineWhat’s new
Splitting supportAudio format conversion support• AVAudioCompressedBuffer• AVAudioConverter
AVAudioSequencer
![Page 47: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/47.jpg)
Splitting SupportSample setup
PlayerNode EffectNode MixerNode
![Page 48: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/48.jpg)
Splitting SupportSample setup
PlayerNode EffectNode MixerNode
Only one-to-one connections were supported
![Page 49: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/49.jpg)
Splitting SupportSample setup
PlayerNode MixerNode
![Page 50: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/50.jpg)
Splitting SupportSample setup
PlayerNode
EffectNode 1
EffectNode 2
MixerNode
![Page 51: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/51.jpg)
Splitting SupportCode example
PlayerNode
EffectNode 1
EffectNode 2
MixerNode
![Page 52: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/52.jpg)
Splitting SupportCode example
Connection points—AVAudioConnectionPoint [node, bus]
PlayerNode
EffectNode 1
EffectNode 2
MixerNode
![Page 53: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/53.jpg)
Splitting SupportCode example
// Create an array of player connection points let connPoints = [ AVAudioConnectionPoint(node: effect1, bus: 0), AVAudioConnectionPoint(node: mixer, bus: 1), AVAudioConnectionPoint(node: effect2, bus: 0)]
![Page 54: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/54.jpg)
Splitting SupportCode example
// Create an array of player connection points let connPoints = [ AVAudioConnectionPoint(node: effect1, bus: 0), AVAudioConnectionPoint(node: mixer, bus: 1), AVAudioConnectionPoint(node: effect2, bus: 0)]
// Make player connections engine.connect(player, toConnectionPoints: connPoints, fromBus: 0, format: playerFormat)
// Make effect nodes to mixer connections ..
![Page 55: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/55.jpg)
AVAudioMixing ProtocolWith splitting
PlayerNode
EffectNode(Distortion)
MixerNode
EffectNode(Reverb)
![Page 56: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/56.jpg)
AVAudioMixing ProtocolWith splitting
// set player’s global mixing setting player.volume = 0.5
PlayerNode
EffectNode(Distortion)
MixerNode
EffectNode(Reverb)
Mixing Settingsvolume = 0.5
volume = 0.5
volume = 0.5
![Page 57: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/57.jpg)
AVAudioMixing ProtocolWith splitting
// override mixing settings of mixer bus0 if let mxDest0 = player.destinationForMixer(mixer, bus: 0) {
mxDest0.volume = 0.8 }
PlayerNode
EffectNode(Distortion)
MixerNode
EffectNode(Reverb)
Mixing Settingsvolume = 0.5
Mixing Settingsvolume = 0.8
volume = 0.5
volume = 0.8 (override)
![Page 58: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/58.jpg)
AVAudioMixing ProtocolWith splitting
// override mixing settings of mixer bus1 if let mxDest1 = player.destinationForMixer(mixer, bus: 1) {
mxDest1.volume = 0.2 }
PlayerNode
EffectNode(Distortion)
MixerNode
EffectNode(Reverb)
Mixing Settingsvolume = 0.5
Mixing Settingsvolume = 0.8
volume = 0.2 (override)
Mixing Settingsvolume = 0.2
![Page 59: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/59.jpg)
AVAudioMixing ProtocolWith splitting
// disconnect mixer bus1 input, corresponding mixing settings are lost engine.disconnectNodeInput(mixer, bus: 1)
PlayerNode
EffectNode(Distortion)
MixerNode
EffectNode(Reverb)
Mixing Settingsvolume = 0.5
Mixing Settingsvolume = 0.8
settings lost
Mixing Settingsvolume = 0.2
![Page 60: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/60.jpg)
AVAudioMixing ProtocolWith splitting
PlayerNode
EffectNode(Distortion)
MixerNode
EffectNode(Reverb)
Mixing Settingsvolume = 0.5
Mixing Settingsvolume = 0.8
![Page 61: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/61.jpg)
AVAudioMixing ProtocolWith splitting
// make a new connection, player’s global mixing settings take effect engine.connect(effect2, to:mixer, fromBus: 0, toBus: 1, format: format)
PlayerNode
EffectNode(Distortion)
MixerNode
EffectNode(Reverb)
Mixing Settingsvolume = 0.5
Mixing Settingsvolume = 0.8
volume = 0.5(global settings)
![Page 62: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/62.jpg)
AVAudioMixing ProtocolWith splitting
Source node with multiple mixer connections• Properties changed on source node
- Applied to all existing/new mixer connections• Properties on individual mixer connections
- Can be overridden- Not preserved on disconnections
![Page 63: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/63.jpg)
Splitting supportRestrictions
From the split node to the mixer where all split paths terminate:• Cannot have AVAudioUnitTimeEffect• Cannot have any rate conversion
![Page 64: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/64.jpg)
AVAudioEngineWhat’s new
Splitting supportAudio format conversion support• AVAudioCompressedBuffer• AVAudioConverter
AVAudioSequencer
![Page 65: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/65.jpg)
AVAudioBuffer
AVAudioPCMBuffer• Uncompressed (PCM) audio data
AVAudioCompressedBuffer (new in iOS 9.0 / OS X El Capitan)• Compressed audio data• Used with AVAudioConverter
![Page 66: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/66.jpg)
AVAudioConverter
Utility class, higher-level equivalent for AudioConverterAudio format conversion• PCM to PCM
- Integer/float, bit depth, interleave/deinterleave, sample rate conversion• PCM to/from compressed
- Encoding- Decoding
Can be used in conjunction with AVAudioEngine
![Page 67: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/67.jpg)
AVAudioConverter
OutputNode
AVAudioEngine
EffectNodePlayerNode
With AVAudioEngine: sample use case
![Page 68: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/68.jpg)
AVAudioConverter
OutputNode
AVAudioEngine
EffectNodePlayerNode
CompressedAudio Stream
With AVAudioEngine: sample use case
![Page 69: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/69.jpg)
AVAudioConverter
OutputNode
PCMBuffer 2
PCMBuffer 3
PCMBuffer 1
AVAudioEngine
EffectNodePlayerNode
CompressedAudio Stream
With AVAudioEngine: sample use case
![Page 70: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/70.jpg)
AVAudioConverter
OutputNode
PCMBuffer 2
PCMBuffer 3
PCMBuffer 1
AVAudioEngine
EffectNodePlayerNode
AVAudioConverter
CompressedAudio Stream
With AVAudioEngine: sample use case
![Page 71: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/71.jpg)
AVAudioConverter
// Input format: 44.1 kHz, 2 channel, non-interleaved, 16-bit signed integer let inFormat = AVAudioFormat(
commonFormat: AVAudioCommonFormat.PCMFormatInt16, sampleRate: 44100, channels: 2, interleaved: false)
// Output format: 44.1 kHz, 2 channel, AAC var outDesc = AudioStreamBasicDescription(
mSampleRate: 44100, mFormatID: kAudioFormatMPEG4AAC, mFormatFlags: 0, mBytesPerPacket: 0, mFramesPerPacket: 0, mBytesPerFrame: 0, mChannelsPerFrame: 2, mBitsPerChannel: 0, mReserved: 0)
let outFormat = AVAudioFormat(streamDescription: &outDesc)
Code example: encoding
![Page 72: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/72.jpg)
AVAudioConverter
// Input format: 44.1 kHz, 2 channel, non-interleaved, 16-bit signed integer let inFormat = AVAudioFormat(
commonFormat: AVAudioCommonFormat.PCMFormatInt16, sampleRate: 44100, channels: 2, interleaved: false)
// Output format: 44.1 kHz, 2 channel, AAC var outDesc = AudioStreamBasicDescription(
mSampleRate: 44100, mFormatID: kAudioFormatMPEG4AAC, mFormatFlags: 0, mBytesPerPacket: 0, mFramesPerPacket: 0, mBytesPerFrame: 0, mChannelsPerFrame: 2, mBitsPerChannel: 0, mReserved: 0)
let outFormat = AVAudioFormat(streamDescription: &outDesc)
Code example: encoding
![Page 73: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/73.jpg)
AVAudioConverter
// Create a converter let converter = AVAudioConverter(fromFormat: inFormat, toFormat: outFormat)
// Allocate an input PCM buffer let inBuffer = AVAudioPCMBuffer(PCMFormat: inFormat, frameCapacity: 1024)
// Allocate an output compressed buffer let outBuffer = AVAudioCompressedBuffer(
format: outFormat, packetCapacity: 8, maximumPacketSize: converter.maximumOutputPacketSize)
Code example: encoding
![Page 74: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/74.jpg)
AVAudioConverter
// Create a converter let converter = AVAudioConverter(fromFormat: inFormat, toFormat: outFormat)
// Allocate an input PCM buffer let inBuffer = AVAudioPCMBuffer(PCMFormat: inFormat, frameCapacity: 1024)
// Allocate an output compressed buffer let outBuffer = AVAudioCompressedBuffer(
format: outFormat, packetCapacity: 8, maximumPacketSize: converter.maximumOutputPacketSize)
Code example: encoding
![Page 75: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/75.jpg)
AVAudioConverter
// Create a converter let converter = AVAudioConverter(fromFormat: inFormat, toFormat: outFormat)
// Allocate an input PCM buffer let inBuffer = AVAudioPCMBuffer(PCMFormat: inFormat, frameCapacity: 1024)
// Allocate an output compressed buffer let outBuffer = AVAudioCompressedBuffer(
format: outFormat, packetCapacity: 8, maximumPacketSize: converter.maximumOutputPacketSize)
Code example: encoding
![Page 76: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/76.jpg)
AVAudioConverter
// Create an input block that’s called when converter needs input let inputBlock : AVAudioConverterInputBlock = {
inNumPackets, outStatus in if (<no_data_available>) {
outStatus.memory = AVAudioConverterInputStatus.NoDataNow; return nil; } else if (<end_of_stream>) { outStatus.memory = AVAudioConverterInputStatus.EndOfStream; return nil; } else {
.. outStatus.memory = AVAudioConverterInputStatus.HaveData; return inBuffer; // fill and return input buffer } }
Code example: encoding
![Page 77: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/77.jpg)
AVAudioConverter
// Create an input block that’s called when converter needs input let inputBlock : AVAudioConverterInputBlock = {
inNumPackets, outStatus in if (<no_data_available>) { outStatus.memory = AVAudioConverterInputStatus.NoDataNow; return nil; } else if (<end_of_stream>) { outStatus.memory = AVAudioConverterInputStatus.EndOfStream; return nil; } else {
.. outStatus.memory = AVAudioConverterInputStatus.HaveData; return inBuffer; // fill and return input buffer } }
Code example: encoding
![Page 78: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/78.jpg)
AVAudioConverter
// Create an input block that’s called when converter needs input let inputBlock : AVAudioConverterInputBlock = {
inNumPackets, outStatus in if (<no_data_available>) { outStatus.memory = AVAudioConverterInputStatus.NoDataNow; return nil; } else if (<end_of_stream>) { outStatus.memory = AVAudioConverterInputStatus.EndOfStream; return nil; } else {
.. outStatus.memory = AVAudioConverterInputStatus.HaveData; return inBuffer; // fill and return input buffer } }
Code example: encoding
![Page 79: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/79.jpg)
AVAudioConverter
// Create an input block that’s called when converter needs input let inputBlock : AVAudioConverterInputBlock = {
inNumPackets, outStatus in if (<no_data_available>) { outStatus.memory = AVAudioConverterInputStatus.NoDataNow; return nil; } else if (<end_of_stream>) { outStatus.memory = AVAudioConverterInputStatus.EndOfStream; return nil; } else {
.. outStatus.memory = AVAudioConverterInputStatus.HaveData; return inBuffer; // fill and return input buffer } }
Code example: encoding
![Page 80: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/80.jpg)
AVAudioConverter
// Conversion loop outError = nil while (true) {
let status = converter.convertToBuffer(outBuffer, error: outError, withInputFromBlock: inputBlock) if status == AVAudioConverterOutputStatus.EndOfStream || status == AVAudioConverterOutputStatus.Error {
break } // outBuffer contains output data
.. }
Code example: encoding
![Page 81: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/81.jpg)
AVAudioConverter
// Conversion loop outError = nil while (true) {
let status = converter.convertToBuffer(outBuffer, error: outError, withInputFromBlock: inputBlock) if status == AVAudioConverterOutputStatus.EndOfStream || status == AVAudioConverterOutputStatus.Error {
break } // outBuffer contains output data
.. }
Code example: encoding
![Page 82: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/82.jpg)
AVAudioConverter
// Conversion loop outError = nil while (true) {
let status = converter.convertToBuffer(outBuffer, error: outError, withInputFromBlock: inputBlock) if status == AVAudioConverterOutputStatus.EndOfStream || status == AVAudioConverterOutputStatus.Error {
break } // outBuffer contains output data
.. }
Code example: encoding
![Page 83: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/83.jpg)
AVAudioEngineWhat’s new
Splitting supportAudio format conversion support• AVAudioCompressedBuffer• AVAudioConverter
AVAudioSequencer
![Page 84: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/84.jpg)
AVAudioSequencer
Plays MIDI filesAssociated with an AVAudioEngine during instantiationSends MIDI events to AVAudioUnitMIDIInstrument nodes in the engine
![Page 85: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/85.jpg)
AVAudioSequencerSample setup
AVAudioEngine
OutputNodeMixerNode
InstrumentNode
![Page 86: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/86.jpg)
AVAudioSequencerSample setup
AVAudioEngine
OutputNodeMixerNodeAVAudioSequencer
InstrumentNode
![Page 87: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/87.jpg)
AVAudioSequencerSample setup
AVAudioEngine
OutputNodeMixerNodeAVAudioSequencer
InstrumentNode
![Page 88: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/88.jpg)
AVAudioSequencer
do { // setup instrument node (e.g. sampler) let sampler = AVAudioUnitSampler() engine.attachNode(sampler) engine.connect(sampler, to: engine.mainMixerNode, format: format) try sampler.loadInstrumentAtURL(instURL)
// start the engine try engine.start()
} catch { // handle errors }
Code example: AVAudioEngine setup
![Page 89: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/89.jpg)
AVAudioSequencer
do { // setup instrument node (e.g. sampler) let sampler = AVAudioUnitSampler() engine.attachNode(sampler) engine.connect(sampler, to: engine.mainMixerNode, format: format) try sampler.loadInstrumentAtURL(instURL)
// start the engine try engine.start()
} catch { // handle errors }
Code example: AVAudioEngine setup
![Page 90: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/90.jpg)
AVAudioSequencer
do { // create sequencer and associate with engine let sequencer = AVAudioSequencer(audioEngine: engine)
// load MIDI file try sequencer.loadFromURL(fileURL,
options: AVMusicSequenceLoadOptions.SMF_PreserveTracks)
// start sequencer sequencer.prepareToPlay() try sequencer.start() // audio will start playing
} catch { // handle error }
Code example: AVAudioSequencer setup
![Page 91: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/91.jpg)
AVAudioSequencer
do { // create sequencer and associate with engine let sequencer = AVAudioSequencer(audioEngine: engine)
// load MIDI file try sequencer.loadFromURL(fileURL,
options: AVMusicSequenceLoadOptions.SMF_PreserveTracks)
// start sequencer sequencer.prepareToPlay() try sequencer.start() // audio will start playing
} catch { // handle error }
Code example: AVAudioSequencer setup
![Page 92: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/92.jpg)
AVAudioSequencer
do { // create sequencer and associate with engine let sequencer = AVAudioSequencer(audioEngine: engine)
// load MIDI file try sequencer.loadFromURL(fileURL,
options: AVMusicSequenceLoadOptions.SMF_PreserveTracks)
// start sequencer sequencer.prepareToPlay() try sequencer.start() // audio will start playing
} catch { // handle error }
Code example: AVAudioSequencer setup
![Page 93: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/93.jpg)
AVAudioSequencerHandling multiple tracks
AVAudioEngine
OutputNodeMixerNode
InstrumentNode 1
InstrumentNode 2
AVAudioSequencer
t1t2
![Page 94: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/94.jpg)
AVAudioSequencerHandling multiple tracks
AVAudioEngine
OutputNodeMixerNode
InstrumentNode 1
InstrumentNode 2
AVAudioSequencer
t1
t2
![Page 95: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/95.jpg)
AVAudioSequencer
// create and setup engine // create sequencer // load MIDI file .. // send individual tracks to different instrument nodes in the engine let tracks = sequencer.tracks tracks[0].destinationAudioUnit = sampler tracks[1].destinationAudioUnit = midiSynth
// start sequencer ..
Code example: handling multiple tracks
![Page 96: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/96.jpg)
AVAudioSequencerTransport controls
Prepare to play, start, stopSet playback position• Seconds or beats
Set playback rate
![Page 97: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/97.jpg)
DemoAVAudioEngine
Akshatha Nagesh ‘AudioEngine’erTorrey Holbrook Walker Senior New Feature Salesperson
![Page 98: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/98.jpg)
SummaryAVAudioEngine
Recap• Handling multichannel audio
What’s new• Splitting support• Audio format conversion support
- AVAudioCompressedBuffer- AVAudioConverter
• AVAudioSequencer
![Page 99: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/99.jpg)
Inter-device Audio Mode for iOS
Torrey Holbrook WalkerSenior New Feature Salesperson
![Page 100: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/100.jpg)
Recording From iOS Devices
![Page 101: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/101.jpg)
Recording From iOS Devices
![Page 102: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/102.jpg)
Recording From iOS Devices
Digital USB AudioDigital USB Audio
![Page 103: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/103.jpg)
Recording Audio From iOS
Digital recording is possible with USB host mode and USB hardware3rd party software/frameworksCouldn’t this be simpler?
![Page 104: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/104.jpg)
Inter-device Audio Mode
Record audio digitally over the Lighting to USB cableStereo 24-bit @ 48 kHz stream formatUSB 2.0 audio class-compliant implementation
![Page 105: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/105.jpg)
Inter-device Audio Mode
No additional hardwareNo additional softwareNo need to modify OS X or iOS applicationsNo system sounds routed to USB
![Page 106: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/106.jpg)
Inter-device Audio Mode
Device can charge and syncTemporarily disabled functionality• Photo import• Tethering• QuickTime screen capture
![Page 107: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/107.jpg)
Inter-device Audio ModeAccessible via Audio MIDI Setup
![Page 108: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/108.jpg)
Inter-device Audio Mode
![Page 109: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/109.jpg)
DemoInter-device audio mode
Torrey Holbrook WalkerSenior New Feature Salesperson
![Page 110: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/110.jpg)
Inter-device Audio Mode
Requires OS X El Capitan and iOS 9Works on all iPhones with a lightning connectorWorks on all iPads with a lightning connector except first-gen iPad miniSupports multiple devices simultaneously (if you’ve got the hubs)
![Page 111: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/111.jpg)
CoreAudioKit View Controller
@IBOutlet weak var viewContainer: NSView! weak var iOSDeviceView: NSView? var controller : CAInterDeviceAudioViewController?
@IBAction func toggleIOSDeviceView(sender: NSButton) { if iOSDeviceView == nil {
controller = CAInterDeviceAudioViewController() iOSDeviceView = controller!.view viewContainer.addSubview(iOSDeviceView!) } else { iOSDeviceView!.removeFromSuperview() iOSDeviceView = nil controller = nil } }
![Page 112: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/112.jpg)
More CoreAudioKit View Controllers
CABTLEMIDIWindowControllerDisplays UI for configuring Bluetooth LE MIDI devicesNSWindowController subclass
![Page 113: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/113.jpg)
CABTLEMIDIWindowController
![Page 114: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/114.jpg)
More CoreAudioKit View Controllers
CANetworkBrowserWindowControllerDisplays UI for managing AVB audio devicesNSWindowController subclass
![Page 115: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/115.jpg)
CoreAudioKit View Controller (cont.)
![Page 116: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/116.jpg)
What’s New in AVAudioSession
Torrey Holbrook WalkerSenior New Feature Salesperson
![Page 117: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/117.jpg)
Navigation Prompts and PodcastsProblem
Listening to podcast while drivingNavigation prompts duck podcast audio—> Bad user experience!
![Page 118: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/118.jpg)
Navigation Prompts and PodcastsSolution
Podcast and audio book apps:• Use AVAudioSessionModeSpokenAudio
Navigation and fitness apps: • Use AVAudioSessionCategoryOptions.InterruptSpokenAudioAndMixWithOthers
1st party apps have opted in:• Maps, Podcasts, iBooks
![Page 119: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/119.jpg)
Navigation ApplicationSession setup
do { let audioSession = AVAudioSession.sharedInstance() let category = AVAudioSessionCategoryPlayback var categoryOptions = AVAudioSessionCategoryOptions.DuckOthers if #available(iOS 9.0, *) { categoryOptions.unionInPlace(.InterruptSpokenAudioAndMixWithOthers) } try audioSession.setCategory(category, withOptions: categoryOptions) } catch { // handle errors ... }
![Page 120: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/120.jpg)
Starting navigation promptsNavigation Application
func startNavPrompt(promptPath : NSURL) { do { let audioSession = AVAudioSession.sharedInstance() let player = try AVAudioPlayer(contentsOfURL: promptPath) player.delegate = self try audioSession.setActive(true) player.play() } catch { // handle errors ... } }
![Page 121: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/121.jpg)
Navigation ApplicationCompleting navigation prompts
// AVAudioPlayerDelegate method func audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully flag: Bool) { do { let audioSession = AVAudioSession.sharedInstance() try audioSession.setActive(false, withOptions: .OptionNotifyOthersOnDeactivation) } catch { // handle errors ... } }
![Page 122: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/122.jpg)
Podcast ApplicationSession setup
do { let audioSession = AVAudioSession.sharedInstance() let category = AVAudioSessionCategoryPlayback var mode = AVAudioSessionModeDefault if #available(iOS 9.0, *) { mode = AVAudioSessionModeSpokenAudio } try audioSession.setCategory(category) try audioSession.setMode(mode)
...
![Page 123: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/123.jpg)
Podcast ApplicationSession setup
...
// add interruption handler NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleInterruption:", name:AVAudioSessionInterruptionNotification, object: audioSession)
// register for other important notifications
} catch { // handle errors ... }
![Page 124: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/124.jpg)
Podcast ApplicationInterruption handling
func handleInterruption(notification: NSNotification) { let userInfo = notification.userInfo as! [String: AnyObject] let type = userInfo[AVAudioSessionInterruptionTypeKey] as! AVAudioSessionInterruptionType
switch type { case .Began: // update UI to indicate that playback has stopped
if (state == isPlaying) { wasPlaying = true state = stopped }
...
![Page 125: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/125.jpg)
Podcast ApplicationInterruption handling (cont.)
... case .Ended: if let flag = userInfo[AVAudioSessionInterruptionOptionKey] as? AVAudioSessionInterruptionOptions { if flag == .OptionShouldResume && wasPlaying {
// rewind the audio a little player.play()
state = isPlaying // and update the UI to reflect that playback has resumed
} } } // end switch } // end func
![Page 126: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/126.jpg)
Recap
Enhanced AVAudioEngineInter-device audio modeCoreAudioKit View Controllers for IDAM, BLE MIDI, and AVBAVAudioSessionModeSpokenAudioAVAudioSessionCategoryOptions.InterruptSpokenAudioAndMixWithOthers
![Page 127: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/127.jpg)
Related Sessions
Audio Unit Extensions Nob Hill Thursday 11:00 AM
What's New in SpriteKit Mission Wednesday 10:00 AM
Enhancements to SceneKit Mission Wednesday 2:30 PM
![Page 128: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/128.jpg)
Related Labs
Audio Lab Graphics, Games, and Media Lab A Thursday 9:00 AM
Audio Lab Graphics, Games, and Media Lab A Thursday 1:30 PM
![Page 129: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/129.jpg)
More Information
Technical SupportDeveloper Technical Supporthttp://developer.apple.com/contact
Apple Developer Forumshttp://developer.apple.com/forums
Bugshttp://bugreport.apple.com
General InquiriesCraig Keithley, Technologies [email protected]
![Page 130: What's New in Core Audio](https://reader031.fdocuments.in/reader031/viewer/2022012305/58a2e5f61a28ab366e8b8eb3/html5/thumbnails/130.jpg)