What s New in Core Audio

Similar documents
Going Social with ReplayKit and Game Center

ios Audio Programming Guide

Mobile Application Development

ios Application Development &

Soundcraft Signature MTK Recording Guide

Using the US-122 with GigaStudio and Cubasis

GETTING STARTED WITH STUDIO ONE ARTIST

Logic Pro 9. TDM Guide

Professional 24-bit USB Audio Interface. User s Guide

The diagram below illustrates the steps from stored music to audio device; key elements of the audio chain are discussed later in this guide.

October2013 VB-Audio Software V.Burel Configuring System Settings VB-CABLE revision 0 VB-AUDIO CABLE

Mbox Basics Guide. Version 6.7 for LE Systems on Windows XP or Mac OS X. Digidesign

Source Live 2.0 User Guide

Windows Audio Drivers Guide

Axia IP-Audio Driver Update v June, 2013

Message from the Development Team. Contents. Message from the Development Team..2. Panel Controls and Terminals...3. Using the UR22mkII...

Using Safari to Deliver and Debug a Responsive Web Design

USER GUIDE ENGLISH ( 3 6 )

USER GUIDE ENGLISH ( 3 6 )

Apogee ONE. QuickStart Guide. V3, March, 2013

Version 1.0. PNY DUO-LINK 4 User Manual

Source-Live 1.3 User Guide

Cubase LE 5. Installing Cubase LE 5. Trademarks. Quick Start Guide

2. Download, save and unzip the Cambridge Audio USB 2.0 driver from the Cambridge Audio website

Editor / Plug-In Editor Manual

XONE:23C QUICK START GUIDE

Supported Audio Interfaces for DAD version 8+

Game Center Programming Guide

8x8 Virtual Office Mobile User Guide for ios

MixMeister EZ Converter Setup & Troubleshooting Contents:

QUALITY AV PRODUCTS INMATE/INMATE USB PROFESSIONAL 19" MIXER. User Guide and Reference Manual

Contents. Latest versions and updates

Continuous Integration with Xcode 6

Video and Audio Codecs: How Morae Uses Them

Windows Audio Drivers Guide

Authoring for Dolby Atmos Cinema Sound Manual

Advanced Graphics and Animations for ios Apps

D i g i g r a m. sound card range. Professional stereo and multichannel sound cards. Installation and set-up

Video Encoding Best Practices

Mini Effect Gizmo. User s Manual. RJM Music Technology, Inc.

D A. TASCAM PCM Recorder. iphone/ipad/ipod touch Application USER'S GUIDE

Frequently Asked Questions about the Sound Blaster X7

MIDI Setup with TonePort UX2 and KB37

Basics. Mbox 2. Version 7.0

Audiomedia III Installation Guide

sndio OpenBSD audio & MIDI framework for music and desktop applications

OVERVIEW HARDWARE. Mode buttons. USB Micro socket. Kensington Security Slot. 8x8 playable grid. Mode buttons

Advanced Testing and Continuous Integration

Chord Limited. Mojo Dac Headphone Amplifier OPERATING INSTRUCTIONS

VirtualDJ 8 Numark IDJLIVE II 1

The Coast to Coast AM Podcast for itunes 11

Contents. About AirPlay 5. Preparing Your Media and Server for AirPlay 8. Opting Into or Out of AirPlay 11

PART 1. Using USB Mixer with a Computer

miditech Audiolink II

2.0 AUDIO RECORDING INTERFACE

User Manual. Ver 1.0. Solutions for the Digital Life

DSD Native DAC Setup Guide

User Guide FFFA

Editor / Plug-In Editor Manual

QUICK SETUP GUIDE SETUP FOR ICONNEX SOUNDCARD AND AUDACITY RECORDING SOFTWARE

For version p (September 4, 2012)

MEP-7000 FREQUENTLY ASKED QUESTIONS (FAQS)

The Rush 24/7 Podcast for itunes 11

Managing Apple Devices

MP-1010 Capture Device USB

What s New in Managing Apple Devices

PRODUCING DV VIDEO WITH PREMIERE & QUICKTIME

8x8 Virtual Office Mobile User Guide for ios

Project 4: Pseudo USB Simulation Introduction to UNIVERSAL SERIAL BUS (USB) STANDARD

Hi! Let s get started.

Aura. Wireless Speaker System Owner s Manual

이 기기는 업무용 급 으로 전자파적합등록을 한 기기이오니 판매자 또는 사용자는 이점을 주의하시기 바라며 가정 외의 지역에서 사용하는 것을 목적으로 합니다

Audio File Manager For MRS Series

Cisco Unity Connection WAV File Issues

CinePlay User Manual

Features, Benefits, and Operation

23425 USB DAC FAQ. My DAC is plugged into my PC but I get no audio or I get sound out of my laptop speakers. What gives? Windows Vista / 7:

USB 3.0 Universal Mini Docking Station Adapter

Co-designed by TASCAM and

Quick Start. Guide. The. Guide

UMI3 Parametric USB MIDI Foot Controller. User s Manual

bel canto The Computer as High Quality Audio Source A Primer

ScreenBeam Mini 2 Wireless Display Receiver

Document authored by: Native Instruments GmbH Software version: 2.7 (01/2015)

Installation and Operation Manual Blackmagic Converters. Mac OS X Windows

Using the Wireless Music Bridge

Getting Started Guide

Recording using Cubase LE 6

TEAC Professional Division OWNER S MANUAL

Upgrading to Pro Tools 7.4

US-122L/US-144 Release Notes

Focusrite Saffire 6 USB. User Guide

User Manual. For additional help please send a detailed to Support@phnxaudio.com. - 1 Phoenix Audio Technologies

Desktop Headphone amplifier with Advanced DAC

Berkeley Audio Design Alpha USB

1. Computer System Structure and Components

Transcription:

Media #WWDC15 What s New in Core Audio Session 507 Akshatha Nagesh AudioEngine er Torrey Holbrook Walker Senior New Feature Salesperson 2015 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Agenda AVAudioEngine Recap What s New Inter-device Audio AVAudioSession What s New Audio Unit Extensions Nob Hill Thursday 11:00 AM

AVAudioEngine Recap

Core Audio Stack ios and OS X AVAudioEngine Introduced in ios 8.0/OS X 10.10 Application AVFoundation Refer to WWDC14 session 502 AVAudioEngine in Practice OpenAL AVAudioSession AVAudioPlayer AVAudioRecorder AVAudioEngine MIDI AudioToolbox Audio Codecs CoreAudio and Drivers

AVAudioEngine Goals Provide powerful, feature-rich API set Achieve simple as well as complex tasks Simplify real-time audio

AVAudioEngine Features Objective-C / Swift API set Low latency, real-time audio Play and record audio Connect audio processing blocks Capture audio at any point in the processing chain Implement 3D audio for games

AVAudioEngine Building blocks Node-AVAudioNode Source nodes: Provide data for rendering Processing nodes: Process data Destination node: Terminating node connected to output hardware

Sample Engine Setup Karaoke InputNode EffectNode (Delay) PlayerNode (Backing Track) MixerNode OutputNode NodeTapBlock (Analyze) PlayerNode (Sound Effects)

Sample Engine Setup Karaoke Source nodes InputNode EffectNode (Delay) PlayerNode (Backing Track) MixerNode OutputNode NodeTapBlock (Analyze) PlayerNode (Sound Effects)

Sample Engine Setup Karaoke Processing nodes InputNode EffectNode (Delay) PlayerNode (Backing Track) MixerNode OutputNode NodeTapBlock (Analyze) PlayerNode (Sound Effects)

Sample Engine Setup Karaoke Destination node InputNode EffectNode (Delay) PlayerNode (Backing Track) MixerNode OutputNode NodeTapBlock (Analyze) PlayerNode (Sound Effects)

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

AVAudioMixing Protocol Defines properties for a mixer input bus Source nodes conform to this protocol Properties cached when not connected to a mixer Properties applied on connection to a mixer

AVAudioMixing Protocol Properties Common (all mixer nodes) volume - player.volume = 0.5 Stereo (AVAudioMixerNode) pan - player.pan = -1.0 3D (AVAudioEnvironmentNode) position - player.position = AVAudioMake3DPoint(-2.0, 0.0, 5.0) obstruction, occlusion, renderingalgorithm and more

AVAudioMixing Protocol Sample setup MixerNode PlayerNode MixerNode (Main Mixer) EnvironmentNode

AVAudioMixing Protocol Sample setup properties are cached MixerNode PlayerNode Mixing Settings volume = 0.5 pan = -1.0 position = (-1, 2, -5) MixerNode (Main Mixer) EnvironmentNode

AVAudioMixing Protocol Sample setup volume and pan take effect Mixing Settings MixerNode PlayerNode volume = 0.5 pan = -1.0 position = (-1, 2, -5) MixerNode (Main Mixer) EnvironmentNode

AVAudioMixing Protocol Sample setup MixerNode PlayerNode Mixing Settings volume = 0.5 pan = -1.0 position = (-1, 2, -5) MixerNode (Main Mixer) EnvironmentNode volume and position take effect

Handling Multichannel Audio Hardware setup OS X ios AVAudioEngine setup

Handling Multichannel Audio Hardware setup: OS X User can configure the hardware through Audio MIDI Setup

Handling Multichannel Audio Hardware setup: ios Configure AVAudioSession Playback use case: - Activate audio session - Check maximumoutputnumberofchannels - Set preferredoutputnumberofchannels - Verify actual outputnumberofchannels

Handling Multichannel Audio Hardware 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

Handling Multichannel Audio Hardware 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

Handling Multichannel Audio Hardware 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

Handling Multichannel Audio Hardware setup: ios-code example 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 }

Handling Multichannel Audio Hardware setup: ios-code example 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 }

Handling Multichannel Audio AVAudioEngine setup: ios / OS X Multichannel content AVAudioMixerNode Spatialized content (games) AVAudioEnvironmentNode

Handling Multichannel Audio AVAudioEngine setup: multichannel content Multichannel Content (5.1) PlayerNode MixerNode OutputNode Multichannel Hardware (5.1)

Handling Multichannel Audio AVAudioEngine setup: multichannel content set connection format get hardware format Multichannel Content (5.1) PlayerNode MixerNode OutputNode Multichannel Hardware (5.1)

Handling Multichannel Audio AVAudioEngine setup: multichannel content set connection format get hardware format Multichannel Content (5.1) PlayerNode MixerNode OutputNode Multichannel Hardware (5.1) // 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)

Handling Multichannel Audio AVAudioEngine setup: multichannel content set connection format get hardware format Multichannel Content (5.1) PlayerNode MixerNode OutputNode Multichannel Hardware (5.1) // 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)

Handling Multichannel Audio AVAudioEngine setup: multichannel content get content format set connection format Multichannel Content (5.1) PlayerNode MixerNode OutputNode Multichannel Hardware (5.1)

Handling Multichannel Audio AVAudioEngine setup: multichannel content get content format set connection format Multichannel Content (5.1) PlayerNode MixerNode OutputNode Multichannel Hardware (5.1) 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 {.. }

Handling Multichannel Audio AVAudioEngine setup: multichannel content Multichannel Content (5.1) PlayerNode MixerNode OutputNode Multichannel Hardware (5.1) channel mapping // schedule file on player // start engine // start player

Handling Multichannel Audio AVAudioEngine setup: spatialized content Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1)

Handling Multichannel Audio AVAudioEngine setup: spatialized content set compatible format get hardware format Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1)

Handling Multichannel Audio AVAudioEngine setup: spatialized content set compatible format get hardware format Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1) // 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)

Handling Multichannel Audio AVAudioEngine setup: spatialized content set compatible format get hardware format Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1) // 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)

Handling Multichannel Audio AVAudioEngine setup: spatialized content set compatible format get hardware format Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1) // 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)

Handling Multichannel Audio AVAudioEngine setup: spatialized content get content format set connection format Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1)

Handling Multichannel Audio AVAudioEngine setup: spatialized content get content format set connection format Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1) let file = try AVAudioFile(forReading: fileurl) engine.connect(player, to: envnode, format: file.processingformat) // set multichannel rendering algorithm player.renderingalgorithm = AVAudio3DMixingRenderingAlgorithm.SoundField

Handling Multichannel Audio AVAudioEngine setup: spatialized content get content format set connection format Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1) let file = try AVAudioFile(forReading: fileurl) engine.connect(player, to: envnode, format: file.processingformat) // set multichannel rendering algorithm player.renderingalgorithm = AVAudio3DMixingRenderingAlgorithm.SoundField

Handling Multichannel Audio AVAudioEngine setup: spatialized content Mono Content PlayerNode Environment Node OutputNode Multichannel Hardware (5.1) spatial mapping // schedule file on player // start engine // start player

AVAudioEngine What s new

AVAudioEngine What s new Splitting support Audio format conversion support AVAudioCompressedBuffer AVAudioConverter AVAudioSequencer

AVAudioEngine What s new Splitting support Audio format conversion support AVAudioCompressedBuffer AVAudioConverter AVAudioSequencer

Splitting Support Sample setup PlayerNode EffectNode MixerNode

Splitting Support Sample setup PlayerNode EffectNode MixerNode Only one-to-one connections were supported

Splitting Support Sample setup PlayerNode MixerNode

Splitting Support Sample setup EffectNode 1 PlayerNode MixerNode EffectNode 2

Splitting Support Code example EffectNode 1 PlayerNode MixerNode EffectNode 2

Splitting Support Code example EffectNode 1 PlayerNode MixerNode EffectNode 2 Connection points AVAudioConnectionPoint [node, bus]

Splitting Support Code 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)]

Splitting Support Code 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..

AVAudioMixing Protocol With splitting EffectNode (Reverb) PlayerNode MixerNode EffectNode (Distortion)

AVAudioMixing Protocol With splitting EffectNode (Reverb) volume = 0.5 PlayerNode Mixing Settings volume = 0.5 MixerNode EffectNode (Distortion) volume = 0.5 // set player s global mixing setting player.volume = 0.5

AVAudioMixing Protocol With splitting volume = 0.8 (override) EffectNode (Reverb) Mixing Settings volume = 0.8 PlayerNode Mixing Settings volume = 0.5 MixerNode EffectNode (Distortion) volume = 0.5 // override mixing settings of mixer bus0 if let mxdest0 = player.destinationformixer(mixer, bus: 0) { mxdest0.volume = 0.8 }

AVAudioMixing Protocol With splitting EffectNode (Reverb) Mixing Settings volume = 0.8 PlayerNode Mixing Settings volume = 0.5 MixerNode EffectNode (Distortion) Mixing Settings volume = 0.2 volume = 0.2 (override) // override mixing settings of mixer bus1 if let mxdest1 = player.destinationformixer(mixer, bus: 1) { mxdest1.volume = 0.2 }

AVAudioMixing Protocol With splitting EffectNode (Reverb) Mixing Settings volume = 0.8 PlayerNode Mixing Settings volume = 0.5 MixerNode EffectNode (Distortion) Mixing Settings volume = 0.2 settings lost // disconnect mixer bus1 input, corresponding mixing settings are lost engine.disconnectnodeinput(mixer, bus: 1)

AVAudioMixing Protocol With splitting EffectNode (Reverb) Mixing Settings volume = 0.8 PlayerNode Mixing Settings volume = 0.5 MixerNode EffectNode (Distortion)

AVAudioMixing Protocol With splitting EffectNode (Reverb) Mixing Settings volume = 0.8 PlayerNode Mixing Settings volume = 0.5 MixerNode EffectNode (Distortion) volume = 0.5 (global settings) // make a new connection, player s global mixing settings take effect engine.connect(effect2, to:mixer, frombus: 0, tobus: 1, format: format)

AVAudioMixing Protocol With 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

Splitting support Restrictions From the split node to the mixer where all split paths terminate: Cannot have AVAudioUnitTimeEffect Cannot have any rate conversion

AVAudioEngine What s new Splitting support Audio format conversion support AVAudioCompressedBuffer AVAudioConverter AVAudioSequencer

AVAudioBuffer AVAudioPCMBuffer Uncompressed (PCM) audio data AVAudioCompressedBuffer (new in ios 9.0 / OS X El Capitan) Compressed audio data Used with AVAudioConverter

AVAudioConverter Utility class, higher-level equivalent for AudioConverter Audio 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

AVAudioConverter With AVAudioEngine: sample use case AVAudioEngine PlayerNode EffectNode OutputNode

AVAudioConverter With AVAudioEngine: sample use case AVAudioEngine PlayerNode EffectNode OutputNode Compressed Audio Stream

AVAudioConverter With AVAudioEngine: sample use case AVAudioEngine PlayerNode EffectNode OutputNode PCMBuffer 1 Compressed Audio Stream PCMBuffer 2 PCMBuffer 3

AVAudioConverter With AVAudioEngine: sample use case AVAudioEngine PlayerNode EffectNode OutputNode PCMBuffer 1 Compressed Audio Stream AVAudio Converter PCMBuffer 2 PCMBuffer 3

AVAudioConverter Code example: encoding // 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)

AVAudioConverter Code example: encoding // 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)

AVAudioConverter Code example: encoding // 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)

AVAudioConverter Code example: encoding // 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)

AVAudioConverter Code example: encoding // 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)

AVAudioConverter Code example: encoding // 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 } }

AVAudioConverter Code example: encoding // 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 } }

AVAudioConverter Code example: encoding // 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 } }

AVAudioConverter Code example: encoding // 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 } }

AVAudioConverter Code example: encoding // 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.. }

AVAudioConverter Code example: encoding // 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.. }

AVAudioConverter Code example: encoding // 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.. }

AVAudioEngine What s new Splitting support Audio format conversion support AVAudioCompressedBuffer AVAudioConverter AVAudioSequencer

AVAudioSequencer Plays MIDI files Associated with an AVAudioEngine during instantiation Sends MIDI events to AVAudioUnitMIDIInstrument nodes in the engine

AVAudioSequencer Sample setup AVAudioEngine InstrumentNode MixerNode OutputNode

AVAudioSequencer Sample setup AVAudioEngine InstrumentNode AVAudioSequencer MixerNode OutputNode

AVAudioSequencer Sample setup AVAudioEngine InstrumentNode AVAudioSequencer MixerNode OutputNode

AVAudioSequencer Code example: AVAudioEngine setup 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 }

AVAudioSequencer Code example: AVAudioEngine setup 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 }

AVAudioSequencer Code example: AVAudioSequencer setup 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 }

AVAudioSequencer Code example: AVAudioSequencer setup 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 }

AVAudioSequencer Code example: AVAudioSequencer setup 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 }

AVAudioSequencer Handling multiple tracks AVAudioEngine t1 t2 InstrumentNode 1 AVAudioSequencer MixerNode OutputNode InstrumentNode 2

AVAudioSequencer Handling multiple tracks AVAudioEngine t1 InstrumentNode 1 AVAudioSequencer MixerNode OutputNode t2 InstrumentNode 2

AVAudioSequencer Code example: handling multiple tracks // 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..

AVAudioSequencer Transport controls Prepare to play, start, stop Set playback position Seconds or beats Set playback rate

Demo AVAudioEngine Akshatha Nagesh AudioEngine er Torrey Holbrook Walker Senior New Feature Salesperson

Summary AVAudioEngine Recap Handling multichannel audio What s new Splitting support Audio format conversion support - AVAudioCompressedBuffer - AVAudioConverter AVAudioSequencer

Inter-device Audio Mode for ios Torrey Holbrook Walker Senior New Feature Salesperson

Recording From ios Devices

Recording From ios Devices

Recording From ios Devices Digital USB Audio Digital USB Audio

Recording Audio From ios Digital recording is possible with USB host mode and USB hardware 3rd party software/frameworks Couldn t this be simpler?

Inter-device Audio Mode Record audio digitally over the Lighting to USB cable Stereo 24-bit @ 48 khz stream format USB 2.0 audio class-compliant implementation

Inter-device Audio Mode No additional hardware No additional software No need to modify OS X or ios applications No system sounds routed to USB

Inter-device Audio Mode Device can charge and sync Temporarily disabled functionality Photo import Tethering QuickTime screen capture

Inter-device Audio Mode Accessible via Audio MIDI Setup

Inter-device Audio Mode

Demo Inter-device audio mode Torrey Holbrook Walker Senior New Feature Salesperson

Inter-device Audio Mode Requires OS X El Capitan and ios 9 Works on all iphones with a lightning connector Works on all ipads with a lightning connector except first-gen ipad mini Supports multiple devices simultaneously (if you ve got the hubs)

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 } }

More CoreAudioKit View Controllers CABTLEMIDIWindowController Displays UI for configuring Bluetooth LE MIDI devices NSWindowController subclass

CABTLEMIDIWindowController

More CoreAudioKit View Controllers CANetworkBrowserWindowController Displays UI for managing AVB audio devices NSWindowController subclass

CoreAudioKit View Controller (cont.)

What s New in AVAudioSession Torrey Holbrook Walker Senior New Feature Salesperson

Navigation Prompts and Podcasts Problem Listening to podcast while driving Navigation prompts duck podcast audio > Bad user experience!

Navigation Prompts and Podcasts Solution Podcast and audio book apps: Use AVAudioSessionModeSpokenAudio Navigation and fitness apps: Use AVAudioSessionCategoryOptions.InterruptSpokenAudioAndMixWithOthers 1st party apps have opted in: Maps, Podcasts, ibooks

Navigation Application Session 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... }

Navigation Application Starting navigation prompts 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... } }

Navigation Application Completing 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... } }

Podcast Application Session 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)...

Podcast Application Session setup... // add interruption handler NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleinterruption:", name:avaudiosessioninterruptionnotification, object: audiosession) // register for other important notifications } catch { } // handle errors...

Podcast Application Interruption 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 }...

Podcast Application Interruption 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

Recap Enhanced AVAudioEngine Inter-device audio mode CoreAudioKit View Controllers for IDAM, BLE MIDI, and AVB AVAudioSessionModeSpokenAudio AVAudioSessionCategoryOptions.InterruptSpokenAudioAndMixWithOthers

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

Related Labs Audio Lab Audio Lab Graphics, Games, and Media Lab A Graphics, Games, and Media Lab A Thursday 9:00 AM Thursday 1:30 PM

More Information Technical Support Developer Technical Support http://developer.apple.com/contact Apple Developer Forums http://developer.apple.com/forums Bugs http://bugreport.apple.com General Inquiries Craig Keithley, Technologies Evangelist keithley@apple.com