ITP 342 Mobile App Dev. Audio

Similar documents
ITP 342 Mobile App Dev. Audio

AVAudioRecorder & System Sound Services

CS193P - Lecture 16. iphone Application Development. Audio APIs Video Playback Displaying Web Content Settings

Announcements. Today s Topics

For Mac and iphone. James McCartney Core Audio Engineer. Eric Allamanche Core Audio Engineer

Core Audio. MSDOSX : Lecture 20

UNDERSTANDING MUSIC & VIDEO FORMATS

Fundamental of Digital Media Design. Introduction to Audio

Computing in the Modern World

Contents. Introduction 7. What Is Core Audio? 10. Core Audio Essentials 19. Organization of This Document 8 See Also 8

ADDING MUSIC TO YOUR itunes LIBRARY

the gamedesigninitiative at cornell university Lecture 15 Game Audio

3 Sound / Audio. CS 5513 Multimedia Systems Spring 2009 LECTURE. Imran Ihsan Principal Design Consultant

ENHANCEMENT IMPLEMENTATION ON

CS 074 The Digital World. Digital Audio

Audio Queue Services. Dave

2.1 Transcoding audio files

Media player for windows 10 free download

iphone Programming Touch, Sound, and More! Norman McEntire Founder Servin Flashlight CodeTour TouchCount CodeTour

CS193p Spring 2010 Wednesday, May 26, 2010

Delivering an Exceptional Audio Experience

TEAC HR Audio Player. Music Playback Software for TEAC USB AUDIO DAC Devices OWNER S MANUAL

Skill Area 214: Use a Multimedia Software. Software Application (SWA)

Introduction to LAN/WAN. Application Layer 4

Export Audio Mixdown

TEAC HR Audio Player. Music Playback Software for TEAC USB AUDIO DAC Devices OWNER S MANUAL

Ultimate Video Capture v1.8 User Manual

OneClick Video Converter Free Version

Microcontroller Compatible Audio File Conversion

Optimizing Audio for Mobile Development. Ben Houge Berklee College of Music Music Technology Innovation Valencia, Spain

Digital Audio Basics

Lecture #3: Digital Music and Sound

Multi-Room Music Servers

Live Audio Reports and Remote Guest Recording Using Report-IT

Audio Coding and MP3

Parallels Toolbox for Windows User's Guide

Traditional Appearance, with Plentiful Functions Including DAB Tuner

ARM MPEG-4 AAC LC Decoder Technical Specification

Introducing working with sounds in Audacity

Computer Audio Setup Guide

ipod classic User Guide

Introducing Audio Signal Processing & Audio Coding. Dr Michael Mason Senior Manager, CE Technology Dolby Australia Pty Ltd

Audio Editing in Audacity. Josh Meltzer Western Kentucky University School of Journalism & Broadcasting

Application Control... 5 Zoom... 5 Exit... 5 Expand... 5 Minimize... 6 Administration... 7 Logging In... 7 Accessing Administration...

MEDIA RELEASE FOR IMMEDIATE RELEASE Singapore, 6 January 2010 Total: 8 pages (including Notes to the Editor)

User's Guide.

ITNP80: Multimedia! Sound-II!

STEP 1: DOWNLOAD THE PROGRAM

Digital Audio. Amplitude Analogue signal

CHAPTER 6 Audio compression in practice

Web 2.0 and iphone Application Development Workshop. Lab 5: Multimedia on iphone

Lesson 5: Multimedia on the Web

Lesson 5: Multimedia on the Web

What s New in Audio. Media #WWDC17. Akshatha Nagesh, AudioEngine-eer Béla Balázs, Audio Artisan Torrey Holbrook Walker, Audio/MIDI Black Ops

VISUAL QUICKSTART GUIDE QUICKTIME PRO 4. Judith Stern Robert Lettieri. Peachpit Press

What Do I Really Need to Know about itunes? COPYRIGHTED MATERIAL

Perceptual coding. A psychoacoustic model is used to identify those signals that are influenced by both these effects.

Creating Audio Apps for watchos

Setting your PC for operating from a smartphone, iphone, etc. as a controller (Windows 8.1)

Compressed Audio Demystified by Hendrik Gideonse and Connor Smith. All Rights Reserved.

ESOTERIC HR Audio Player

Apple Core Audio Format Specification 1.0

How Do I Get Ringtones For Iphone 5c Screen To Rotate

ipod nano Features Guide

VPAT for ipad Pro (12.9-inch) (2nd generation)

Completing the Multimedia Architecture

Both LPC and CELP are used primarily for telephony applications and hence the compression of a speech signal.

Networking Applications

Audio for Everybody. OCPUG/PATACS 21 January Tom Gutnick. Copyright by Tom Gutnick. All rights reserved.

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

oit Digital Audio Basics with Audacity UMass Office of Information Technologies Get Started with Digital Audio...

Introducing Audio Signal Processing & Audio Coding. Dr Michael Mason Snr Staff Eng., Team Lead (Applied Research) Dolby Australia Pty Ltd

Portable media PORTABLE MEDIA CONNECTIONS

Squeeze Play: The State of Ady0 Cmprshn. Scott Selfon Senior Development Lead Xbox Advanced Technology Group Microsoft

ipod nano User Guide

Display Audio System AUDIO AND CONNECTIVITY. Use simple gestures-including touching, swiping and scrolling-to operate certain audio functions.

OLIVE 4 & 4HD HI-FI MUSIC SERVER P R O D U C T O V E R V I E W

Welcome to MainConcept AAC Encoder - Plug-In for Adobe Flash Media Live Encoder -

Pro Tools Addendum. Version for LE Systems on Windows or Macintosh. Digidesign

ipod shuffle User Guide

CHAPTER 10: SOUND AND VIDEO EDITING

How Do I Manually Lock My Iphone 4s On Silent Mode

Announcements. Today s Topics

Models with Display Audio Display Audio Operation

Multimedia on the Web

DAB/DAB+ Radio User Manual

MENU button until a padlock icon appears in the top-left corner of the screen. This will not affect the volume control. To unlock the buttons, hold do

Amazing Audacity: Session 1

Audacity Tutorial Recording With Your PC

Frequently Asked Questions: Cisco Jabber Voice 9.1(6) for iphone

Streaming Media. Advanced Audio. Erik Noreke Standardization Consultant Chair, OpenSL ES. Copyright Khronos Group, Page 1

ITP 342 Mobile App Dev. Web View

Models with Display Audio Touchscreen Operation*

VS1063 ENCODER DEMONSTRATION

AUDIO AND CONNECTIVITY

How to Make a Podcast

AUDIO AND CONNECTIVITY

ipad Basics Class Handouts Presented by: Ashlee Tominey Adult Services Librarian

Software Development & Education Center. Java Platform, Micro Edition. (Mobile Java)

NEO 4.5. User Manual

Transcription:

ITP 342 Mobile App Dev Audio

File Formats and Data Formats 2 pieces to every audio file: file format (or audio container) data format (or audio encoding) File formats describe the format of the file itself Actual audio data inside can be encoded many different ways Example: a CAF file is a file format that can contain audio that is encode in MP3, linear PCM, and many other data formats

Data Formats (or Audio Encoding) Data formats supported by ios AAC = Advanced Audio Coding Designed to be the successor of MP3 Compresses the original sound, resulting disk savings but lower quality In practice, AAC usually does better compression than MP3, especially at bit rates below 128kbit/s HE-AAC = High Efficiency AAC Superset of AAC Optimized for low bit rate audio such as streaming audio 3

Data Formats (or Audio Encoding) Data formats supported by ios AMR = Adaptive Multi-Rate Optimized for speech, featuring very low bit rates ALAC = Apple Lossless Audio Coding Compresses the audio data without losing any quality In practice, the compression is about 40-60% of the original data. The algorithm was designed so that data could be decompressed at high speeds, which is good for devices such as the ipod or iphone. ilbc = Internet Low Bitrate Codec Optimized for speech, good for voice over IP, and streaming audio 4

Data Formats (or Audio Encoding) Data formats supported by ios ima4 = Interactive Multimedia Association 4:1 Compression format that gives you 4:1 compression on 16- bit audio files linear PCM = Linear Pulse Code Modulation Describes the technique used to convert analog sound data into a digital format No compression Fastest to play μ-law and a-law Alternate encodings to convert analog data into digital format, but are more optimized for speech than linear PCM 5

Data Formats (or Audio Encoding) Data formats supported by ios MP3 = MPEG-1 or MPEG-2 Audio Layer III Audio-specific format that was designed by the Moving Picture Experts Group (MPEG) Uses a form of lossy data compression Common audio format for consumer audio streaming or storage De facto standard of digital audio compression for the transfer and playback of music on most digital audio players Released in 1995 6

Audio Playback Formats and Codecs Audio decoder / playback format Hardware-assisted decoding Software-based decoding AAC (MPEG-4 Advanced Audio Coding) Yes Yes ALAC (Apple Lossless) Yes Yes HE-AAC (MPEG-4 High Efficiency AAC) Yes - ilbc (internet Low Bitrate Codec, another format for speech) - Yes IMA4 (IMA/ADPCM) - Yes Linear PCM (uncompressed, linear pulse-code modulation) - Yes MP3 (MPEG-1 audio layer 3) Yes Yes µ-law and a-law - Yes 7

Which to use? You can play linear PCM, IMA4, and a few other formats that are uncompressed or simply compressed quite quickly and simultaneously with no issues. For more advanced compression methods such as AAC, MP3, and ALAC, the iphone does have hardware support to decompress the data quickly but the problem is it can only handle one file at a time. Therefore, if you play more than one of these encodings at a time, they will be decompressed in software, which is slow. 8

Which to use? If space is not an issue, just encode everything with linear PCM. Not only is this the fastest way for your audio to play, but you can play multiple sounds simultaneously without running into any CPU resource issues. If space is an issue, most likely you ll want to use AAC encoding for your background music and IMA4 encoding for your sound effects. 9

Variants of Linear PCM There are several variants of linear PCM depending on how the data is stored. The data can be stored in big or little endian formats, as floats or integers, and in varying bit-widths. The preferred variant of linear PCM on the iphone is little-endian integer 16-bit, or LEI16 for short. Note that this differs from the preferred variant on the Mac OSX, which is native-endian floating point 32-bit. Because audio files are often created on the Mac, it s a good idea to examine the files and convert them to the preferred format for the iphone. 10

File Formats (or Audio Containers) ios supports many file formats including MPEG-1 (.mp3), MPEG-2 ADTS (.aac), AIFF, CAF, and WAVE. But the most important thing to know here is that usually you ll just want to use CAF. It can contain any encoding supported on the iphone, and it is the preferred file format on the iphone. 11

Audio Files Any audio files that you want to use need to be added into your project. Many people create a group called Resources and put them in there. You may also reference audio files that exist on a server via a URL. 12

Bit Rates The bit rate is the number of bytes per second that an audio file takes up. Some encodings such as AAC or MP3 let you specify the number of bytes to compress the audio file to. When you lower the bytes per second, you lose quality as well. You should choose a bit rate based on your particular sound file try it out at different bit rates and see where the best match between file size and quality is. If your file is mostly speech, you can probably get away with a lower bit rate. 13

Common Bit Rates Bit Rates Usage 32 kbit/s AM Radio quality 48 kbit/s Common rate for long speech podcasts 64 kbit/s Common rate for normal-length speech podcasts 96 kbit/s FM Radio quality 128 kbit/s Most common bit rate for MP3 music 160 kbit/s Musicians or sensitive listeners prefer this from 128 kbit/s 192 kbit/s Digital radio broadcasting quality 320 kbit/s Virtually indistinguishable from CDs 500 kbit/s 1,411 kbit/s Lossless audio encoding such as linear PCM 14

Sample Rates There s one final piece of terminology to cover sample rates. When converting an analog signal to digital format, the sample rate is how often the sound wave is sampled to make a digital signal. Almost always, 44,100Hz is used because that is the same rate for CD audio. 15

Audio Most Core Audio services use and manipulate audio in linear pulse-code-modulated (linear PCM) format The most common uncompressed digital audio data format Digital audio recording creates PCM data by measuring an analog (real world) audio signal s magnitude at regular intervals (the sampling rate) and converting each sample to a numerical value Audio units are software plug-ins that process audio data ios provides a set of audio units optimized for efficiency and performance on a mobile platform You can develop audio units for use in your ios application 16

ios Core Audio Core Audio in ios is optimized for the computing resources available in a battery-powered mobile platform 17

Core Audio Frameworks Frameworks available for ios AudioToolbox System Sound Services lets you play short sounds and alerts Audio Hardware Services provides a lightweight interface for interacting with audio hardware Audio Session Services lets ios applications manage audio sessions AudioUnit CoreAudio OpenAL AVFoundation 18

Audio Session An audio session is the intermediary between your application and ios for configuring audio behavior. Upon launch, your application automatically gets a singleton audio session. You configure it to express your application s audio intentions.

Audio Session Configuration Audio session configuration influences all audio activity while your application is running, except for user-interface sound effects that you play. You can query the audio session to discover hardware characteristics of the device your application is on characteristics such as channel count, sample rate, and availability of audio input. These can vary by device and can change due to user actions while your application runs. You can explicitly activate and deactivate your audio session. For application sound to play, or for recording to work, your audio session must be active. 20

Interruption The system can also deactivate your audio session which it does, for example, when a phone call arrives or an alarm sounds. Such a deactivation is called an interruption. The audio session APIs provide ways to respond to and recover from interruptions. 21

Audio Session Category An audio session category is a key that identifies a set of audio behaviors for your application. By setting a category, you indicate your audio intentions to the system such as whether your audio should continue when the screen locks. The six audio session categories in ios, along with a set of override and modifier switches, let you customize your app s audio behavior. 22

Audio Session Categories Category identifiers Silenced by the Ring/Silent switch and by screen locking Allows audio from other applications Allows audio input (recording) and output (playback) AVAudioSessionCategoryAmbient kaudiosessioncategory_ambientsound AVAudioSessionCategorySoloAmbient kaudiosessioncategory_soloambientsound Yes Yes Output only Yes No Output only AVAudioSessionCategoryPlayback kaudiosessioncategory_mediaplayback No No by default; yes by using override switch Output only AVAudioSessionCategoryRecord kaudiosessioncategory_recordaudio No (recording continues with the screen locked) No Input only AVAudioSessionCategoryPlayAndRecord kaudiosessioncategory_playandrecord No No by default; yes by using override switch Input and output AVAudioSessionCategoryAudioProcessing kaudiosessioncategory_audioprocessing - No No input and no output 23

Audio Session Default Behavior An audio session comes with some default behavior. Specifically: Playback is enabled and recording is disabled. When the user moves the Silent switch (or Ring/Silent switch on iphone) to the silent position, your audio is silenced. When the user presses the Sleep/Wake button to lock the screen, or when the Auto-Lock period expires, your audio is silenced. When your audio starts, other audio on the device such as ipod audio that was already playing is silenced. 24

Ignore Audio Session The only times you can safely ignore the audio session for a shipping application are these: Your application uses System Sound Services or the UIKit playinputclick method for audio and uses no other audio APIs. Your application uses no audio at all. In all other cases, do not ship your application with the default audio session. 25

2 Audio Session APIs ios offers two APIs for working with the audio session object, each with its own advantages: The AVAudioSession class, described in AVAudioSession Class Reference, provides a convenient, Objective-C interface that works well with the other Objective-C code in your application. This API provides access to a core set of audio session features. Audio Session Services, described in Audio Session Services Reference, is a full-featured C API that provides access to all basic and advanced features of the audio session. 26

Simulator The Simulator does not simulate audio session behavior and does not have access to the hardware features of a device. When running in the simulator, you cannot: Invoke an interruption Change the setting of the Silent switch Simulate screen lock Simulate the plugging in or unplugging of a headset Query audio route information or test audio session category behavior Test audio mixing behavior that is, playing your audio along with audio from another application (such as the Music app) 27

System Sound Services System Sound Services is the ios technology for playing user-interface sound effects and for invoking vibration. It is unsuitable for other purposes. https://developer.apple.com/library/ios/docum entation/audiotoolbox/reference/systemso undservicesreference/reference/reference. html https://developer.apple.com/library/ios/sampl ecode/syssound/introduction/intro.html 28

System Sound Services Audio feedback-like clicks & beeps can enhance your programs and make your interaction richer System Sound Services is intended for user-interface sound effects and user alerts It is not intended for sound effects in games Alert sounds work best when kept short According to Apple, preferably 2 seconds or less 29

Drawbacks: System Sound Services It only supports audio data formats linear PCM or IMA4. It only supports audio file formats CAF, AIF, or WAV. The sounds must be 30 seconds or less in length. 30

Add Audio Framework In Xcode, control-click on your project's target (top left corner) Click on the General tab Scroll down to the Linked Frameworks and Libraries section Click the + button Type audio into the search field Select AudioToolbox.framework Click the Add button You can look under Frameworks AudioToolbox.framework and see the header files 31

AudioToolbox In the main View Controller implementation file, import the AudioToolbox and create a property for the sound SWIFT // QuoteViewController.m #import <AudioToolbox/AudioToolbox.h> #import "QuoteViewController.h" // QuotesViewController.swift import UIKit import AudioToolbox @interface QuoteViewController () class QuotesViewController: UIViewController{ @property (readonly) SystemSoundID soundfileid; var soundfileid: SystemSoundID! 32

Audio Toolbox In the viewdidload method, set up the soundfileid property // QuoteViewController.m NSString *soundfilepath = [[NSBundle mainbundle] pathforresource:@"tada" oftype:@"wav"]; NSURL *soundurl = [NSURL fileurlwithpath:soundfilepath]; AudioServicesCreateSystemSoundID(( bridge CFURLRef _Nonnull)(soundURL), &_soundfileid); SWIFT // QuotesViewController.swift let soundfilepath = Bundle.main.path(forResource: "Tada", oftype: "wav") let soundurl = NSURL(fileURLWithPath: soundfilepath!) AudioServicesCreateSystemSoundID(soundURL as CFURL, &soundfileid) 33

Audio Toolbox In the method to handle a single tap (or swipe or shake), play the sound // QuoteViewController.m - (void)singletaprecognized: (UITapGestureRecognizer *)recognizer{ // Play sound file AudioServicesPlaySystemSound(self.soundFileID); } [self displayquote:[self.model randomquote]]; SWIFT // QuotesViewController.swift func singletaprecognized(recognizer: UITapGestureRecognizer){ // Play sound file AudioServicesPlaySystemSound(self.soundFileID) } self.displayquote(str: self.model.randomquote()) 34

Vibration As with audio alerts, vibration immediately grabs a user s attention Works for nearly all users, including those who are hearing or visually impaired We use the same System Audio services we just used AudioServicesPlaySystemSound Each call produces a short 1-to-2 second buzz 35

Vibration Code In method to handle a double tap, make the device vibrate // QuoteViewController.m - (void)doubletaprecognized: (UITapGestureRecognizer *)recognizer{ // Vibrate AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); } [self displayquote:[self.model randomquote]]; SWIFT // QuotesViewController.swift } func doubletaprecognized(recognizer: UITapGestureRecognizer){ // Vibrate AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) self.displayquote(str: self.model.randomquote()) 36

AVAudioPlay So what if you have an audio file encoded with AAC or MP3 that you want to play as background music? Another easy way to play music is via the AVAudioPlayer class. However, the drawback of AVAudioPlayer is it is extremely slow. If you tap a button and try to trigger a sound with AVAudioPlayer, there will be a noticeable small delay. 37

AVAudioPlayer Couple other things to keep in mind: If you re playing background music, you should check to see if other audio (like the ipod) is playing first, so you don t have two layers of music going on at once! If a phone call arrives and the user chooses Decline, by default your AVAudioPlayer will stop. You can start it back up again by registering for the AVAudioPlayerDelegate and starting the music back up again in the audioplayerendinterruption method. 38

AVAudioPlayer In the main View Controller implementation file, import the AVFoundation framework and create a property for the sound // QuoteViewController.m #import <AVFoundation/AVFoundation.h> // Other imports @interface QuoteViewController () @property (strong, nonatomic) AVAudioPlayer *audioplayer; 39

AVAudioPlayer In the main View Controller implementation file, import the AVFoundation framework and create a property for the sound SWIFT // QuotesViewController.swift import AVFoundation // Other imports class QuotesViewController: UIViewController { var audioplayer: AVAudioPlayer! 40

AVAudioPlayer In the viewdidload method, set up the audioplayer property // QuoteViewController.m NSString *path = [NSString stringwithformat:@"%@/tone.mp3", [[NSBundle mainbundle] resourcepath]]; NSURL *soundurl = [NSURL fileurlwithpath:path]; NSError *error; self.audioplayer = [[AVAudioPlayer alloc] initwithcontentsofurl:soundurl error:&error]; [self.audioplayer preparetoplay]; SWIFT let path = "\(Bundle.main.resourcePath!)/tone.mp3" let soundurl = NSURL(fileURLWithPath: path) self.audioplayer = try! AVAudioPlayer(contentsOf: soundurl as URL) self.audioplayer.preparetoplay() 41

AVAudioPlayer In the method to handle a single tap (or swipe or shake), play the sound // QuoteViewController.m - (void)singletaprecognized: (UITapGestureRecognizer *)recognizer{ // Play audio [self.audioplayer play]; [self displayquote:[self.model randomquote]]; } SWIFT func singletaprecognized(recognizer: UITapGestureRecognizer){ // Play audio self.audioplayer.play() self.displayquote(str: self.model.randomquote()) } 42

OpenAL If you re writing a game or another app where you want fine grained control of audio with low latency, you might want to use OpenAL, a cross-platform audio library supported by ios. OpenAL can be a beast with a steep learning curve. OpenAL.framework 43

Cocos2D Another option is the Cocos2D game library includes an extremely easy to use sound engine that makes playing audio a snap. Tutorial: http://www.raywenderlich.com/25736/how-tomake-a-simple-iphone-game-with-cocos2d-2-xtutorial 44

Apple Developer Library https://developer.apple.com/library/ios/documen tation/audio/conceptual/audiosessionprogram mingguide/basics/basics.html https://developer.apple.com/library/ios/documen tation/audiovideo/conceptual/multimediapg/usi ngaudio/usingaudio.html http://www.raywenderlich.com/259/audiotutorial-for-ios-playing-audio-programatically http://www.raywenderlich.com/69369/audio- tutorial-ios-playing-audio-programatically-2014- edition 45