Multimedia programming guide & Audio

Source: Internet
Author: User

IOS offers a rich set of tools for working with sound in your application.
These tools are arranged into frameworks according to the features they provide, as follows:

■ Use themedia player framework to play songs, audio books, or audio podcasts froma user's iPod library.
For details, seemedia player framework reference, iPod libraryaccess programmingguide, And the addmusic sample code project.

■ Use the AV foundation framework to play and record audio using a simple objective-C interface.
For details, see AV foundation framework reference and the avtouch sample code project.

■ Use the audio toolbox framework to play audio with synchronization capabilities, access packets of incoming audio, parse audio streams,
Convert audio formats, and record audio with access to individual packets.
For details, see audio toolbox framework reference and the speakhere sample code project.

■ Use the audio Unit framework to connect to and use audio processing plug-ins. For details, see audio unit hosting guide for IOS.

■ Use the openal framework to provide positional audio playback in games and other applications.
IOS supports openal 1.1. For information on openal, see the openal website, openal FAQ for iPhone OS, and the oaltouch sample code project.

1 playing media items with iPod library access

2 playing UI sound effects or invoking vibration using system sound services (require audio toolbox Framework)

To play user-interface sound effects (such as button clicks), or to invoke vibration on devices that support it,
Use System sound services. This compact interface is described in system sound services reference.
You can find sample code in the audio UI sounds (syssound) sample in the IOS Dev center.
Note: Sounds played with system sound services are not subject to configuration using your audio session.
As a result, you cannot keep the behavior of system sound services audio in line with other audio Behavior
In your application. This is the most important reason to avoid using system sound services for any audio
Apart from its intended uses.
The audioservicesplaysystemsound function lets you very simply play short sound files. The simplicity
Carries with it a few restrictions. Your sound files must be:
■ No longer than 30 seconds in duration
■ In linear PCM or ima4 (IMA/ADPCM) Format
■ Packaged in a. CAF,. AIF, or. Wav file

In addition, when you use the audioservicesplaysystemsound function:
■ sounds play at the current system audio volume, with no programmatic volume control available
■ sounds play immediately
■ looping and stereo positioning are unavailable
■ simultaneous playback is unavailable: you can play only one sound at a time
the similar audioservicesplayalertsound function plays a short sound as an alert. if a user has configured
their device to vibrate in ring settings, calling this function invokes vibration in addition to playing the sound
file.

3 playing sounds easily with the avaudioplayer class
the avaudioplayer class provides a simple objective-C interface for playing sounds. if your application
does not require stereo positioning or precise synchronization, and if you are not playing audio captured
from a network stream, apple recommends that you use this class for playback.
using an audio player you can:
■ play sounds of any duration
■ play sounds from files or memory buffers
■ loop sounds
■ play multiple sounds simultaneously (although not with precise synchronization)
■ control relative playback level for each sound you are playing
■ seek to a participant point in a sound file, which supports application features such as fast forward and rewind
■ obtain audio power data that you can use for Audio level metering

4 playing sounds with control using audio queue services adds playback capabilities beyond those available with the avaudioplayer class.
Using audio queue services for playback lets you:
■ Precisely schedule when a sound plays, allowing Synchronization
■ Precisely control volume on a buffer-by-buffer basis
■ Play audio that you have captured from a stream using audio file stream services

 

5 playing sounds with positioning using openal

The open-sourced openal audio API, available in ios in the openal framework, provides an interface
Optimized for positioning sounds in a stereo field during playback. Playing, positioning, and moving sounds
Works just as it does on other platforms. openal also lets you mix sounds. openal uses the I/O unit
Playback, resulting in the lowest latency.

For all of these reasons, openal is your best choice for playing sounds in game applications on iOS-based
Devices. However, openal is also a good choice for general IOS application audio playback needs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.