IPhone audio 101 (Part 2): conversion and recording

Source: Internet
Author: User
ArticleDirectory
    • Afplay, afconvert, afinfo
    • Recording audio files on Mac
    • Next
IPhone audio 101 (Part 2): conversion and recording

Translator: Xia laiyou

 

Disclaimer (read only !) : The original translations of all tutorials provided by this blog are from the Internet and are only for learning and communication purposes. Do not conduct commercial communications. At the same time, do not remove this statement when reprinting. In the event of any dispute, it has nothing to do with the owner of this blog and the person who published the translation. Thank you for your cooperation!

 

Original article URL:Http://www.raywenderlich.com/233/audio-101-for-iphone-developers-converting-and-recording

 

This article is the second in this series (covering audio topics that iPhone developers are interested in.

In the first article in this series, I explained the differences between file formats and data formats, and what formats are supported on the iPhone. Now, let's discuss how to convert between different formats.

Afplay, afconvert, afinfo

Converting audio on Mac is quite simple, because there are three built-in command line tools on Mac: afplay, afconvert, and afinfo.

The easiest way to use afplay is to enter your audio name in the terminal, which will play back the video. It is quite convenient to listen to the differences between compressed audio files at different bit rates.

The next step is afinfo. You only need to enter your audio name. Then you can see the file format, data format, bit rate, and other useful information of this file. Example:

 

The above example shows that the file type of this file is Caf, the data format is 16-bit low-byte order signed integer (lei16), the sampling frequency is 44100Hz, the bit rate is 705600 bits/second.

Finally, let's discuss the best tool: afconvert. Afconvert is quite simple to use. You only need a command line like the following:

Afconvert-d [out data format]-f [out file format] [in file] [out file]

Therefore, convert a file to the iPhone's preferred non-compressed audio encoding (Note: Linear PCM's 16-bit low-byte Integer Conversion, that is, lei16 (the little-Endian integer 16-bit variant of linear PCM), and iPhone preferred file format (reminder: Core audio file format, that is, CAFF ), you can enter the following command line:

Afconvert-D lei16-F 'caff' input_file.xxx output_file.caf

Note: I didn't point out the extension of this input file, because afconvert can intelligently detect the audio file type and convert it accordingly, therefore, the input file can be any data format or audio file format.

Also note: you can add a "-B" option before the input or output file to set the bit rate. In this example, we use 32bit/sec to save the file and 128-bit/sec to save it.

Afconvert-d aac-F 'caff'-B 32768 background-music-lei.caf test_32.caf

Afconvert-d aac-F 'caff'-B 131072 background-music-lei.caf test_128.caf

Recording audio files on Mac

I want to write down two good ways to make music and sound for your app on Mac.

First, garageband is required. Garageband can easily combine pre-prepared drums, guitar, and other musical instrument sounds into a small song. If you like music very much, you can play and record some music on your own and make some cool things.

 

If you are not ready yet and do not know much about it, you can take some time to understand it.Apple's garageband tutorial. I found that this chapter, especially "using built-in software instruments", is most useful.

If you think your song is good, you can export it to iTunes and select "reveal in Finder" to get your file for future use.

I found garageband is not the best tool for recording simple sound effects. Therefore, I prefer a great free audio.ProgramThe name is audacity. You can plug in your microphone (I use my rock band microphone, it works just fine !), Record your voice effect and save it easily.

 

 

 

Do not forget that when you make your own sound like this, you are most likely to use 16-bit high-byte ordered signed integer for storage, or use "bei16" for storage. Therefore, do not forget to convert them to lei16 before they are included in your program.

If you find that you don't have a good artistic cell, there are some sound effects inFree Voice ProjectThere is a Creative Commons license, or you can hire a professional.

Next

The next part will be the last article in this series.How to play audio through a program on iPhone.

 

Appendix 1 view the file format in Mac

If you want to know which file formats support those data formats, you can enter afconvert-HF on the console.

Then you can see some information:

$ Afconvert-HF

Audio file and data formats:

'3gpp '= 3GP audio (. 3GP)

Data_formats: 'aac ''aace ''aach ''acacl' 'aacp ''samr'

'3gp2' = paipp-2 audio (. 3g2)

Data_formats: 'aac ''aace ''aach ''acacl' 'aacp ''samr'

'Adts' = aac adts (. AAC,. ADTs)

Data_formats: 'aac ''aach ''aacp'

'Ac-3' = AC3 (. Ac3)

Data_formats: 'ac-3'

'Aifc '= aifc (. aifc,. AIFF,. AIF)

Data_formats: i8 bei16 bei24 bei32 bef32 bef64 ui8 'ulaw'

'Alaw' 'mac3' 'mac6' 'ima4' 'qdm'

'Qclp ''agsm'

'Aiff '= AIFF (. AIFF,. AIF)

Data_formats: i8 bei16 bei24 bei32

'Amrf '= Amr (. AMR)

Data_formats: 'samr'

'Caff' = Apple CAF (. CAF)

Data_formats: '. mp1'. mp2' 'comment ''' qdm2' qdm''' qclp'

'Qclq' 'aac' 'aacl'

'Alac' 'alaw' 'dvi8' 'ilbc' 'ima4' i8 bei16

Bei24 bei32 bef32 bef64 lei16 lei24 lei32

Lef32 lef64 'Ms \ x00 \ x02 ''Ms \ x00 \ X11'' Ms \ x001'

'Sample' ulaw'

'M4af' = Apple MPEG-4 audio (. m4a)

Data_formats: 'aac ''aace ''aach ''acacl' 'aacp ''alac'

'Mpg1' = MPEG Layer 1 (. MP1,. MPEG,. MPa)

Data_formats: '. mp1'

'Mpg2' = MPEG Layer 2 (. MP2,. MPEG,. MPa)

Data_formats: '. mp2'

'Mpg3' = MPEG Layer 3 (upload,. MPEG,. MPa)

Data_formats: 'alipay'

'Mp4f '= MPEG-4 audio (.mp4)

Data_formats: 'aac ''aace ''aach ''aacl' 'aacp'

'Next' = Next/Sun (. SND,. au)

Data_formats: i8 bei16 bei24 bei32 bef32 bef64 'ulaw'

'Sd2f '= Sound Designer II (. sd2)

Data_formats: i8 bei16 bei24 bei32

'Wave '= wave (.wav)

Data_formats: ui8 lei16 lei24 lei32 lef32 lef64 'ulaw' 'alaw'

 

 

 

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.