天天看點

音頻PCM知識整理

簡介

PCM(Pulse Code Modulation),脈沖編碼調制。人耳聽到的是模拟信号,PCM是把聲音從模拟信号轉化為數字信号的技術。原理是用一個固定的頻率對模拟信号進行采樣,采樣後的信号在波形上看就像一串連續的幅值不一的脈沖(脈搏似的短暫起伏的電沖擊),把這些脈沖的幅值按一定精度進行量化,這些量化後的數值被連續的輸出、傳輸、處理或記錄到存儲媒體中,所有這些組成了數字音頻的産生過程(抽樣、量化、編碼三個過程)。

采樣頻率、量化精度(采樣位數)和聲道數

采樣頻率是裝置一秒鐘内對模拟信号的采樣次數,在主流的采集卡上分為:(8Khz的電話采樣率就可以達到人的對話程度)

22.05KHz:無線電廣播;

44.1KHz:音頻 CD,MP3等;

48KHz:miniDV、數字電視、DVD、電影和專業音頻。

人耳能夠感覺到的最高頻率為20kHz,要滿足人耳的聽覺要求,則需要每秒進行40k次采樣,即40kHz。我們常見的CD采樣率為44.1kHz。(也比如我對接過硬體的揚聲器最高是16KHz,則手機MIC采樣率就不用太高,節省傳輸帶寬)

采樣位數比如8bit(現在少見)、16bit(常用)和24bit,指的是描述數字信号所使用的位數。

聲道數:聲音在錄制或播放時在不同空間位置采集或回放的互相獨立的音頻信号。

單聲道 采樣資料為8位的短整數(short);

雙聲道 采樣資料為16位的整數,(int),高八位(左聲道)和低八位(右聲道)分别代表兩個聲道。

[時長]s * [采樣率]Hz * [采樣位數]bit * [聲道數] / 8 = [檔案大小]byte

某音頻信号是采樣率為8kHz、聲道數、位寬為16bit,時長為1s,則音頻資料的大小為:

1 * 8000 * 16 *2 = 256000 bit / 8 = 32000 byte / 1024 = 31.25 KB

音頻幀

音頻跟視訊很不一樣,視訊每一幀就是一張圖像,音頻資料是流式的,不同的編碼格式各自不同的編碼标準,拿PCM和MP3做一個對比。PCM因為沒有壓縮,根據采樣率位寬等資料可以得到每秒的音頻資料,并不需要幀的概念;MP3則是因為壓縮後資訊比較多,則有了類似H264的幀概念,每一個幀都有一個幀頭,有興趣可以詳見如下,有很詳細的MP3的幀解析:

http://blog.csdn.net/fulinwsuafcie/article/details/8972346

錄播過程

播放音樂時,應用程式從存儲媒體中讀取音頻資料(MP3、WMA、AAC…),經過解碼後,最終送到音頻驅動程式中的就是PCM資料,反過來,在錄音時,音頻驅動不停地把采樣所得的PCM資料送回給應用程式,由應用程式完成壓縮、存儲等任務。是以,音頻驅動的兩大核心任務就是:

playback:如何把使用者空間的應用程式發過來的PCM資料,轉化為人耳可以辨識的模拟音頻

capture:把mic拾取到得模拟信号,經過采樣、量化,轉換為PCM信号送回給使用者空間的應用程式。

總結

看了自己的筆記,太靠近應用層了,音頻學習還有較長的路要走啊,共勉。謝謝浏覽。

參考的部落格,感謝。

http://blog.csdn.net/DroidPhone/article/details/6308006

  • <li class="tool-item tool-active is-like "><a href="javascript:;" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" ><svg class="icon" aria-hidden="true">
                            <use xlink:href="#csdnc-thumbsup" target="_blank" rel="external nofollow" ></use>
                        </svg><span class="name">點贊</span>
                        <span class="count">3</span>
                        </a></li>
                        <li class="tool-item tool-active is-collection "><a href="javascript:;" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-Collection-G" target="_blank" rel="external nofollow" ></use>
                        </svg><span class="name">收藏</span></a></li>
                        <li class="tool-item tool-active is-share"><a href="javascript:;" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" ><svg class="icon" aria-hidden="true">
                            <use xlink:href="#icon-csdnc-fenxiang" target="_blank" rel="external nofollow" ></use>
                        </svg>分享</a></li>
                        <!--打賞開始-->
                                                <!--打賞結束-->
                                                <li class="tool-item tool-more">
                            <a>
                            <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                            </a>
                            <ul class="more-box">
                                <li class="item"><a class="article-report">文章舉報</a></li>
                            </ul>
                        </li>
                                            </ul>
                </div>
                            </div>
            <div class="person-messagebox">
                <div class="left-message"><a href="https://blog.csdn.net/pds574834424" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow" >
                    <img src="https://profile.csdnimg.cn/B/B/E/3_pds574834424" class="avatar_pic" username="pds574834424">
                                            <img src="https://g.csdnimg.cn/static/user-reg-year/1x/7.png" class="user-years">
                                    </a></div>
                <div class="middle-message">
                                        <div class="title"><span class="tit"><a href="https://blog.csdn.net/pds574834424" target="_blank" rel="external nofollow"  target="_blank" rel="external nofollow"  data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">丶每天想睡16小時</a></span>
                                            </div>
                    <div class="text"><span>釋出了9 篇原創文章</span> · <span>獲贊 11</span> · <span>通路量 3萬+</span></div>
                </div>
                                <div class="right-message">
                                            <a href="https://im.csdn.net/im/main.html?userName=pds574834424" target="_blank" rel="external nofollow"  target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                        </a>
                                                            <a class="btn btn-sm  bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">關注</a>
                                    </div>
                            </div>
                    </div>
               

簡介