在原先的文章中,我已经恶补过一些音频的相关知识了。其实音频开发本身就是一门非常博大的工程,至少包含声波学、数学,当然,还包含你所使用开发语言的相关知识。
前面音频的基础知识可以看做我们了解学习一下声波学,现在剩下的就还有两座大山。
一个是iOS本身对于声音处理的知识(第一次如此深入的涉及iOS音频开发框架的底层)。
一个是数学(将要面临蛋疼的算法用以分析音频数据)。
首先解决第一个问题。
Apple关于音频开发术语的解释文档Core Audio Glossary已经贴出。
Apple关于音频底层的设计文档Audio Unit Hosting Guide For iOS已经贴出。
非常建议首先看一下这两个文档,它们对于理解苹果音频开发将会非常有帮助。两个文档穿插着看,能够帮助理解。我会尽力把它翻译成中文的,看英文文档看得我蛋都快碎了,但是这还只是冰山一角。我们有大量的专业知识需要理解,这将会是一个痛苦的过程。
我在这里简述一些必不可少、最基本的词语。
bit rate The data rate (or bandwidth) of a digital channel, in bits per second.
比特率。一个数字声道的数据率,以bit/s为单位。
buffer Memory assigned to temporarily hold data between a source and a destination. For example, Core Audio uses buffers to supply audio to, and receive audio from, audio units. See also audio queue buffer.
缓冲区。被分配用来暂时保存源和目标之间数据的内存。底层音频开发大多都涉及缓冲区,比如麦克风获取的声音存储在缓冲区,喇叭播放的声音来源于缓冲区。
bus See element.
element In Core Audio, an audio unit programming context nested within a scope. When part of an input or output scope of an audio unit, an element is analogous to a device signal bus—and is sometimes called a bus. See also audio unit, scope.
首先,在CoreAudio中,bus与element是同一概念。在CoreAudio中,一个音频单元处理上下文嵌套于一个范围。当区分一个音频单元的输入范围和输出范围的时候,一个element就相当于一个设备的信号bus——某些时候被称作总线。
channel A discrete track of audio. A monaural recording or live performance has exactly one channel. A stereo recording or live performance has two channels. A multitrack recording or performance can have any number of channels. Between audio units, a connection has one or more channels. See also channel layout.
声道。音频独立的轨道。单声道(录音或者现场表演)只有一个声道。立体声(录音或者现场表演)具有两个声道。多轨道(录音或者现场表演)有任意的声道数(大于两个)。音频单元之间的连接具有一个或者多个声道。
component In OS X, a plug-in whose interface is defined by the Component Manager. An audio unit is a component.
组件。OS X系统中,接口由组件管理器定义的插件。音频单元就是组件。
digital signal processing (DSP) In audio, analyzing or transforming digital representations of audio. Such transformations include, among others, filtering and equalization, reverberation, level compression, data compression, and sound effects such as pitch shifting. Digital signal processing can be performed by hardware, software, or a combination of both.
数字信号处理(这TM是一门学科...好吧,我承认我没学过)。音频中分析或者转换音频的数字特征。转换包括过滤、均衡、混响、级压缩、数据压缩、音效等。数字信号处理可以由硬件、软件完成,或者是两者的结合。DSP主要用于处理音频原始数据。
frame In Core Audio, a set of samples that contains one sample from each channel in an audio data stream. In the most common case, the samples in a frame are time-coincident—that is, sampled at the same moment. For example, in a stereo stream each frame contains one sample from the left channel and a time-coincident sample from the right channel. More generally, the various channels in a stream, and therefore in a frame, may be from unrelated sources and may have originated at unrelated times. In video, a single image in a series that constitutes a movie. See also packet.
帧。CoreAudio中,音频数据流中由每个声道一个样本组成的样本组。大多数情况中,帧中的样本具有时间一致性——也就是说样本都是在同一时间取样。比如一个立体声数据流每一帧包含一个左声道样本和一个同一时间的右声道样本。更一般的情况,数据流中含有多个声道,因此在一帧中,可能含有来自于不相干的声音源的样本,而这些样本又可能源于不相干的时间。视频中,表示构成电影的连续画面中一个单独的画面。
frame rate In Core Audio, the number of frames played per second for an audio data stream. Compare sample rate. In video playback, the number of video frames displayed per second.
帧速率。CoreAudio中,音频数据流每秒播放的帧数。与样本率相对。视频播放中,表示每秒显示的视频帧数。
frequency The number of times a repeating phenomenon or activity occurs per unit time. The frequency of a sound wave is determined by the number of wavelengths (or fractions thereof) that pass a particular point per unit time. Sampling frequency indicates the number of digital samples taken per unit time. Frequency is typically measured in Hertz (cycles per second).
频率。单位时间内的现象重复或者活动重现的次数。声波的频率由单位时间内通过某一个特定点的波长(或其中的小片段)决定。取样频率表明单位时间获取数字样本的数量。频率通常以赫兹(周期/s)计量。
packet In Core Audio, an encoding-defined unit of audio data comprising one or more frames. For PCM audio, each packet corresponds to one frame. For compressed audio, each packet corresponds to an encoding-defined number of uncompressed frames. For example, one packet of MPEG-2 AAC data decompresses to 1,024 frames of PCM data. In information technology, a packet is a block of data formatted for delivery over a network. Compare frame, sample.
包。CoreAudio中,编码格式确定的一单位音频数据包含一个或者多个帧。对于PCM音频来说,一个包对应一帧音频。对于压缩的音频,一个包对应一组编码格式确定的未压缩的帧。比如说,MPEG-2 AAC编码格式的一个数据包可以解压缩为1024帧PCM数据。信息技术中,一个包就是用于网络传输的一块儿格式化的数据。与帧和样本相比较。
render In Core Audio, to apply a recipe or specification for signal processing to some audio data. An audio unit typically contains a rendering method to obtain audio data and perform processing.
渲染。CoreAudio中,申请一个用于将信号加工成音频数据的方法或者说明。一个音频单元通常都包含一个用于获取音频数据和执行处理的渲染方法。
sample 1. (noun) An instantaneous amplitude of the signal in a single audio channel, represented as an integer, floating-point, or fixed-point number. 2. (verb) To collect samples from an audio source, typically an analog audio source. Sampling typically involves collecting samples at regular, very brief intervals such as 1/44,100 seconds. 3. (noun) An excerpt of a longer recording. When the excerpt is intended to be played repeatedly, it is called a loop. 4. (verb) To record a sample to use as a loop or for inclusion in a another recording. See also fixed-point sample.
样本。样本有四种概念。1、(名词)单一声道种一个瞬间的振幅,以整形、浮点挥着定点数表示。2、(动词)从声源收集样本,通常是一个模拟音频源。取样通常涉及到收集样本的规律性,非常短的间隔比如说1/44100秒。3、(名词)一段更长记录的摘录。当摘录的部分反复播放的时候,称之为循环。4、(动词)记录一个样本用于循环,或者包含在另一段录音中。
sample rate During playback, the number of samples played per second for each channel of an audio file. During recording, the number of samples acquired per second for each channel. Also called sampling rate. More properly, but less commonly, called sampling frequency. Compare frame rate.
样本率。当回放时,音频文件中每个声道每秒钟播放的样本数。当录音时,每个声道回去的样本数。也称为取样率。更贴切,但不常用,被称之为取样频率。
slice The number of frames requested and processed during one rendering cycle of an audio unit. See also frame.
片。CoreAudio中,AudioUnit的一个渲染循环要求和处理的帧数量。
scope In Core Audio, a programmatic context within an audio unit. Unlike the general computer science notion of scopes, however, audio unit scopes cannot be nested. Each scope is a discrete context. You use scopes when writing code that sets or retrieves values of parameters or properties. Compare element. See also parameter, property.
范围。CoreAudio中,AudioUnit中纲领性的上下文。不像一般的计算机科学的概念范围,AudioUnit的范围不可被嵌套。每个范围都是一个离散的上下文。你编写代码时要使用范围概念来设置或检索参数或属性的值。
从这些最基本的概念中已经看出很多东西了。
1、像大多数的系统设计一样,音频使用的是一种pull模式,所以需要使用缓冲区。
2、无论是我们获取麦克风的数据,还是喇叭获取我们的数据,都是通过渲染回调函数,也就是实现pull模式。
3、渲染回调函数一次会操作一片数据。片由帧组成。帧由样本组成。
4、片是连续的帧组成的,帧具有时间先后性和连续性。
5、帧是同一时间来自于每个声道的一个样本组成,样本具有时间一致性。
6、很多时候,不太好区分包和片的关系。简单说,片用于渲染回调函数,包用于存储或者传输音频数据。