Audio 101 for iPhone Development (Part 1): file and Data Types

Source: Internet
Author: User

Http://article.ityran.com/archives/253

This translation is produced by tairan translation team. Please indicate the source for reprinting and inform tairan !!

Translation

Before I developed the iPhone, Ray had little knowledge about sound formats. I know the differences between some "WAV" and "MP3" sound formats, but I certainly cannot tell you exactly what formats "AAC" and "caf" are, I also don't know what the best way to convert audio files on Mac is.

I know that if you want to become a qualified iPhone developer, you must have a basic understanding of the audio file data format, conversion, recording, and audio operation APIs.

This article is the first of three covering audio development tutorials. In this article, we will start with the file and data format.

File Format and Data Format

First, we need to know that each audio file has two parts: 1 is the file format (also called the audio container) and 2 is the data format (also called the Audio Encoding ).

The file format (or audio container) describes its own format. The actual audio data in it can be encoded in many different ways. For example, a file suffixed with CAF is a file format that can contain audio data encoded in MP3, linear PCM (lpcm), and many other formats.

Next let's take a deeper look.

Data format (or audio encoding)

Next we will begin to understand audio encoding, not file format, because audio encoding is the most important thing.

The following are the audio data encoding formats supported by the iPhone and the descriptions for each of them:

· AAC: AAC is short for "Advanced Audio Coding". It is designed to replace the MP3 format. You may think that it compresses the original sound, resulting in low capacity usage but the quality will definitely decrease. However, the loss of these quality depends on the sound bit rate. When the bit rate is suitable, the loss is hard to hear. In fact, AAC has a better compression rate than MP3, especially when the bit rate is lower than bit/s.

· HE-AAC: HE-AAC is a superset of AAC, which "he" represents "high efficiency ". HE-AAC is a kind of audio encoding format specially optimized for low bit rate. For example, streaming audio is especially suitable for this encoding format.

· AMR: The full name of AMR is "adaptive multi-rate". It is also another encoding format specially optimized for "speech" and is also suitable for Low Bit Rate environments.

· ALAC: The full name is "Apple lossless". This is an audio encoding method without any quality loss, that is, lossless compression. In actual use, it can compress 40%-60% of raw data. The decoding speed of this encoding format is very fast, which is very suitable for small devices such as iPhone or iPod.

· Ilbc: This is another audio encoding format specially designed for speech. It is very suitable for IP phones and other scenarios that require streaming audio.

· Ima4: This is a 16-bit audio file compressed. This is a very important encoding format for the iPhone. We will discuss the cause later.

· Linear PCM: it is a linear pulse-coded modulation used to convert analog sound data into digital sound data. In short, it means no data compression. Since the data is not compressed, it can play very quickly, and when the space is not a problem, this is the preferred audio encoding method on the iPhone.

· μ-law and a-law: As far as I know, this encoding is an alternative of analog data encoding in digital format, but it is better than linear PCM in terms of speech optimization.

· MP3: we all know and like this format. Although many years have passed, MP3 is still a very popular encoding format so far and can be well supported by the iPhone.

What encoding format should we choose?

The above seems to be a large table, but only some of them are the first choice for development. When making specific choices, you must remember the following points:

· You can play linear PCM, ima4, and some other audio formats without compression or simple compression, which can be well decoded by iPhone hardware.

· For more advanced compression formats, such as AAC, MP3, and ALAC, the iPhone does not provide support for hardware codecs to quickly decompress the data, you can process only one file at a time. Therefore, if you play more than one audio file using these encoding, the system will use software to decode it, which will be slow and occupy CPU.

Therefore, there are two suggestions for choosing the data format:

· If the space is not a problem, use linear PCM to encode each audio. This not only enables you to play audio as quickly as possible, but also enables you to play multiple sounds simultaneously without occupying CPU resources.

· If space is a problem, most of the time you use AAC to encode your background music and ima4 to encode your sound effects.

Many variants of linear PCM

Another important issue about linear PCM needs to be emphasized, that is, this uncompressed data format is the preferred programming method for iPhone. There are some linear PCM variants for different data storage. These data can be stored in the high-tail or low-tail format. The differences between them are like the bit widths occupied by floating point and integer types.

The most important thing here is that the preferred linear PCM on the iPhone is a 16-bit integer in the little-Endian format, or "lei16" (It seems to be an encoding format, Apple caf audio format code: lei16, iOS device audio format is 16-bit low-end code ). This is different from Mac OS X. It uses local 32-bit floating-point tail number encoding. Because audio files are often created on Mac, it is a good idea to check the files and convert them to the preferred audio encoding format for iPhone.

File Format (or audio container)

IPhone supports many file formats including MPEG-1 ((), MPEG-2 ADTS (. AAC), AIFF, caf, and wave. But the most important thing is that you can only use caf because it can contain any encoding format data supported by the iPhone. On the iPhone, it is the recommended file format.

Here I am talking about it. In fact, the file format is like a bucket. There is a lot of water in it, and the water is the audio data. There are many types of buckets, that is, there are many file formats, and different buckets also need different water. The CAF bucket can hold a variety of water, but some can only hold several types of water. I hope you can better understand this metaphor .)

Bit Rate

This is a term important to audio encoding, which we will mention next: bit rate.

The bit rate is the number of bytes (BITs) occupied by audio files per second ). For example, AAC or mp3 encoding specifies the number of BITs compressed by the audio file. When you use a low bit rate, you will lose the sound quality.

You should select different bit rates based on the specific audio files, and try to use different bit rates to compare which one is the most suitable, weigh the sound file size and sound quality. If most of your files are speech data, you can use a relatively low bit rate.

Here is a table that gives you an overview of the most common bit rates:

· 32 kbit/s: the quality of AM broadcast

· 48 kbit/s: Generally, the bit rate of a long-time speech podcast.

· 64 kbit/s: the bit rate of normal-length speech podcasts

· 96 kbit/s: quality of FM Broadcast

· 128 kbit/s: Bit Rate of most MP3 music

· 160 kbit/s: A bit rate higher than 128 kbit/s that people who like music and want to hear.

· 192 kbit/s: Digital station quality

· 320 kbit/s: At this bit rate, people play almost the same effect as CD.

· 500 kbit/S-1, 411 kbit/s: lossless audio encoding, like linear PCM

Sampling Rate

Before we continue to introduce the audio, we need to know the terms "Sampling Rate.

When a analog signal is converted to a digital format, the sampling rate indicates how often the acoustic waveform sample is extracted to convert it into a digital signal.

In most cases, 44100hz is frequently used because it is the same as the sampling rate of CD audio.

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 link: http://www.raywenderlich.com/204/audio-101-for-iphone-developers-file-and-data-formats

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.