自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iPhone開發(fā)音頻資料

移動開發(fā) iOS
對于簡單的、無混音音頻,AVAudio ToolBox框架提供了一個簡單的C語言風格的音頻服務(wù)。你可以使用AudioservicesPlaySystemSound函數(shù)來播放簡單的聲音。要遵守以下幾個規(guī)則:1.音頻長度小于30秒;2.格式只能是PCM或者IMA4;3.文件必須被存儲為.caf、.aif、或者.wav格式;4.簡單音頻不能從內(nèi)存播放,而只能是磁盤文件。

每個音頻文件都是由兩部分內(nèi)容所構(gòu)成:它的文件格式(或者音頻容器)以及它的數(shù)據(jù)格式(或者音頻編碼)。

文件格式(或音頻容器)是用于形容文件本身的格式。我們可以通過多種不同的方法為真正的音頻數(shù)據(jù)編碼。例如CAF文件便是一種文件格式,它能夠包含MP3格式,線性PCM以及其它數(shù)據(jù)格式的音頻。

數(shù)據(jù)格式(或音頻編碼)

我們將從音頻編碼開始闡述(而不是文件格式),因為編碼是最重要的環(huán)節(jié)。

線性PCM:這是表示線性脈沖編碼調(diào)制,主要是描寫用于將模擬聲音數(shù)據(jù)轉(zhuǎn)換成數(shù)字格式的技術(shù)。簡單地說也就是未壓縮的數(shù)據(jù)。因為數(shù)據(jù)是未壓縮的,所以我們便可以最快速地播放出音頻,而如果空間不是問題的話這便是iPhone音頻的優(yōu)先代碼選擇。

文件格式(或音頻容器)

iPhone支持許多文件格式,包括MPEG-1(.mp3),MPEG-2 ADTS(.aac),AIFF,CAF以及WAVE。但是通常情況下我們都會選擇CAF,因為它能夠同時包含所有iPhone所支持的編碼,并且它也是 iPhone中的優(yōu)先文件格式選擇。

比特率:

比特率是指一個音頻文件所占有的每秒字節(jié)數(shù)。像AAC或MP3等編碼便能夠指定字節(jié)數(shù)而壓縮音頻文件。當你降低每秒鐘的字節(jié)數(shù)時,你同時也在降低音頻的質(zhì)量。

以下是一些較常見的比特率:

每秒32千比特率:調(diào)頻廣播質(zhì)量

每秒48千比特率:較長的語音博客中常見的頻率

每秒64千比特率:標準長度的語音博客中常見的頻率

每秒96千比特率:調(diào)頻收音機的質(zhì)量

每秒128千比特率:MP3音樂最常見的比特率

每秒160千比特率:音樂家和敏感聽眾的優(yōu)先選擇

每秒192千比特率:數(shù)字無線電廣播的質(zhì)量

每秒320千比特率:和CD的質(zhì)量沒兩樣了

每秒500千至1411千比特率:無失真的音頻編碼,如線性PCM

采樣頻率

我們最后需要提到的一個術(shù)語便是:采樣頻率。

當我們將模擬信號轉(zhuǎn)換成數(shù)字格式時,采樣頻率是指我們多長時間抽取一次聲波去創(chuàng)造數(shù)字信號。

通常情況下44100赫茲便是最常用的采樣頻率,因為這與CD音頻的頻率相同。

轉(zhuǎn)換和記錄

這是iPhone開發(fā)者需要掌握的制作音頻要素的第二部分。

在上文中我提到了文件格式與數(shù)據(jù)格式間的區(qū)別,以及iPhone所支持的各種格式。而接下來我將說說如何在這兩種格式間進行轉(zhuǎn)換。

Which format should I use?

The short answer: Use CAFF (uncompressed) for short sound effects and AIFF IMA4 (compressed) for music. This is also the recommendation from Apple.

  • CAFF (Core Audio File Format) is, in a nutshell, the iPhone's native audio file format for uncompressed sounds.
  • AIFF (Audio Interchange File Format) with IMA4 gets you about 4:1 compression on audio files. It is supported natively by the iPhone. One other advantage of this format is that it loops seamlessly - most other compressed audio files are problematic in this regard.
  1. # creates sound.caf (little endian, 16 bit) afconvert -f caff -d LEI16 sound.wav   
  2.  
  3. # creates sound.caf (little endian, 16 bit, 22kHz) afconvert -f caff -d LEI16@22050 sound.wav   
  4.  
  5. # creates sound.caf (little endian, 16 bit, MONO) afconvert -f caff -d LEI16 -c 1 sound.wav   
  6.  
  7. # creates sound.aifc (IMA4 compression) afconvert -f AIFC -d ima4 sound.wav   
  8.  
  9. # creates sound.aifc (IMA4 compression, MONO) afconvert -f AIFC -d ima4 -c 1 sound.wav 

若是要轉(zhuǎn)換一個文件夾內(nèi)的所有音頻文件,可創(chuàng)建如下的一個腳本:

  1. #!/bin/bash  
  2.  
  3. for i in *.wav; do    
  4.  
  5. afconvert -f caff -d LEI16 $i  
  6.  
  7. done   
  8.  
  9. # move new files to project directory  
  10.  
  11. mv *.caf ~/my_project_path/sounds/ 

存儲該腳本文件名為 convert_sounds.sh,拷貝到要轉(zhuǎn)換的音頻文件夾內(nèi),在終端執(zhí)行如下命令:

  1. chmod u+x convert_sounds.sh     
  2.  
  3. ./convert_sounds.sh 

不在乎內(nèi)存空間大小的話,采用 linear PCM數(shù)據(jù)格式的音頻,因為該格式播放最快,而且也可以同時播放多個音頻且沒有cpu消耗資源問題;否則采用 AAC(背景音樂)和 IMA4(音效)

linear PCM在iphone上的采用的是 little-endian integer 16-bit,簡稱 LEI16,而在mac上用的是 native-endian float 32-bit;
ios都采用caf格式音頻文件
采樣率使用 44,100Hz
比特率列表:
  • 32kbit/s: AM Radio quality
  • 48kbit/s: Common rate for long speech podcasts
  • 64kbit/s: Common rate for normal-length speech podcasts
  • 96kbit/s: FM Radio quality
  • 128kbit/s: Most common bit rate for MP3 music
  • 160kbit/s: Musicians or sensitive listeners prefer this from 128kbit/s
  • 192kbit/s: Digital radio broadcasting quality
  • 320kbit/s: Virtually indistinguishable from CDs
  • 500kbit/s-1,411kbit/s: Lossless audio encoding such as linear PCM
3個命令行指令:

afplay, afinfo,  afconvert-hf可打印出能轉(zhuǎn)換的所有音頻格式 )

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

afconvert -d LEI16 -f caff input_file.xxx output_file.caf (使用linear PCM數(shù)據(jù)格式創(chuàng)建caf格式音頻,ios最常用)
afconvert -d aac -f caff -b 32768 background-music-lei.caf test_32.caf (-b后跟比特率32768=32*1024,即32kbit)

錄制音效Audacity軟件: http://audacity.sourceforge.net/
該軟件保存的是 16-bit big-endian signed integer格式,所以最后還要轉(zhuǎn)換成 LEI16
 
播放音效,此種方式僅支持數(shù)據(jù)格式為linear PCM和IMA4,文件格式為caf,aif和wav,長度不超過30秒的音頻文件:

NSString *pewPewPath = [[NSBundle mainBundle] pathForResource:@"pew-pew-lei" ofType:@"caf"]
NSURL *pewPewURL = [NSURL fileURLWithPath:pewPewPath]
AudioServicesCreateSystemSoundID((CFURLRef)pewPewURL, &_pewPewSound)
AudioServicesPlaySystemSound(_pewPewSound);
播放背景音樂,開始播放前會有一定的延遲:
NSError *error; 
_backgroundMusicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:backgroundMusicURL error:&error]
[_backgroundMusicPlayer prepareToPlay]
[_backgroundMusicPlayer play];
OpenAL:有一個開源引擎:下載地址:
a nice Sound Engine library using OpenAL

責任編輯:閆佳明 來源: oschina
相關(guān)推薦

2012-12-24 14:48:14

ios

2011-08-08 18:19:09

iPhone音頻播放

2012-12-24 09:04:04

iOSUnity3D

2011-07-27 09:50:31

iPhone AVAudioPla 音頻

2011-08-02 16:58:15

iPhone AVAudioPla 音頻播放

2011-07-06 17:53:40

iPhone SDK Xcode

2011-07-25 18:02:51

iPhone LibFetion 移植

2011-07-08 10:58:47

2011-08-10 15:48:10

iPhone網(wǎng)絡(luò)

2011-07-06 17:34:47

iPhone

2012-03-28 22:38:20

iPhone

2011-07-19 09:46:38

2011-08-12 09:52:35

iPhone開發(fā)TableviewUITextField

2011-08-22 14:31:53

iPhone開發(fā)

2011-08-10 15:58:58

iPhone視頻

2011-07-08 14:58:16

iPhone Xcode iOS

2011-07-08 16:02:24

iphone

2011-07-19 09:58:36

2011-08-10 18:24:22

iPhone 圖形 繪圖

2011-08-15 10:06:22

iPhone開發(fā)nib 文件
點贊
收藏

51CTO技術(shù)棧公眾號