IOS audio development function

Source: Internet
Author: User

Usage of sound • Sound Effect
■ Click the button ■ warning ■ short voice accompanied by user actions
• Sounds of any length (music, podcasts, and speeches) • audio streams from network services • recorded sounds
How hard is this?
• Playing sound on a versatile mobile device can be surprisingly complicated
■ There may be multiple sources at the same time
■ Countless possible outputs
■ Changing events may exceed user control ■ different priorities for seemingly similar actions
• OS management sound system ■ once again, you just need to build a car

Coreaudio
• High Level, easy to use 
 ■ SYSTEM sound API-short sound
■ Avaudioplayer class-objc, Simple API
• Low level, more effort, but more control
Audiotoolbox-recording and playing, stream processing, full control
Audio units-processing sound
Openal-3D positioning sounds • which to use depends on what you want to do ■ in many cases satisfied with the system sound and avaudioplayer

Playing Short audio • "short" means less than 30 seconds
• Very Simple API, but limited ■ it cannot be repeated
■ No volume control ■ play immediately ■ limited format
■ Linear PCM or ima4 ■ .caf,.aifor .wav files

Playing Short audio
• Two-step process 
 ■ register this sound and return a "sound ID" 
 ■ playback sound ■ you can choose whether to run the callback function when the sound playback ends.
Nsurl * fileurl =... // the address of a file systemsoundid myid;
// Register the voice register audioservicescreatesystemsoundid (cfurlref) fileurl, & myid );
// Now you can play this sound audioservicesplaysystemsound (myid );

Playing Short audio • Clear
■ Clear the sound ID when you finish the call. ■ otherwise, you will receive a memory warning.
Systemsoundid myid;
// Clear the previously registered sound audioservicesdisposesystemsoundid (myid );
Experience your voice • The sound API of the system allows the mobile phone to vibrate
• Use this specific system sound ID ksystemsoundid_vibrate ■ do nothing on the iPod Touch
-(Void) vibrate {// boost the mobile phone Vibration
Audioservicesplaysystemsound (ksystemsoundid_vibrate );
}

Conversion of sounds • command line tool for conversion of sounds
/Usr/bin/afconvert
• Various input and output formats are supported. • For details, see man's page.
• Easy conversion of sound into the system sound format: Audio/usr/bin/afconvert-f aiff-D bei16 inputaudio output. AIF

Play long phoneme • In versions earlier than iPhone OS 2.1, you must use low-level
Coreaudio APIs
■ It may be very complicated. It is very difficult to introduce the objc class into iPhone OS 2.2 to handle simple audio playback.
■ Avaudioplayer audio • if you want to use the sound in the final project, update it to Version 2.2.

Avaudioplayer
• Play a long voice (over 30 seconds)
• Files stored locally or in Memory (or from network streams)
• Ability to loop, beat, play, and pause
• Provide volume information
• Play multiple sounds simultaneously
• Cocoa-style API catalog ■ initialize from the file address or data
■ Allow proxy

Avaudioplayer
• Generate avaudioplayer * player from the file address or data;
Nsstring * Path = [[nsbundle mainbundle] pathforresource...];
Nsurl * url = [nsurl fileurlwithpath: path];
Player = [[avaudioplayer alloc] initwithcontentsofurl: url]; • simple start/stop Methods
If (! Player. Playing ){
[Player play];
} Else {
[PLAYER pause];
}
Avaudioplayerdelegate
• Tell when to stop playing
• Audio Decoding Error Notification
• Interfaces for handling interruptions ■ Oh, these annoying interruptions
Audio sessions
• The operating system needs to know what you are doing to the sound. ■ start playing a game or listen to a podcast, and then lock the settings... what will happen?
■ If you play a shooting game and use the voice/mute switch to mute... what will happen?
• Provides a way for you to express your audio purpose ■ categories is defined to clarify
■ Ambient sound ■ media playback ■ recording ■ playback and recording

Default sessions
• When the app gets the default session, it will listen ■ when playing your sound (such as iPod Audio), other sounds will be muted ■ use the voice/mute switch ■ mute when the user locks the device
• This is good for many applications, but not necessarily suitable for your applications ■ if so, you need to use audio session APIs

Advanced Audio

Audio file stream service and audio Queue Service

Supported formats

More control over return visit

Stream playing audio to Network

Advanced Audio

• Audio Recording

■ Audio Queue Service (brief description)

1. Generate a queue

2. Define a callback function to receive the recorded audio data.

3. Start the queue

4. To receive the recording data of the callback function, you must save it.

5. Stop the queue

■ For more details, see the example project speakhere of the iPhone Dev center.

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.