linux下的音訊裝置檔案編程

來源:互聯網
上載者:User

1. Linux下的音訊裝置檔案

/dev/console:與擴音器相關的裝置檔案。

 

/dev/dsp:與音效卡裝置上的DSP相關的裝置檔案,提供了數字採樣和數字錄音的功能。音效卡裝置通過DSP實現類比訊號和數字訊號的轉換。向該裝置寫入資料將啟用音效卡上的數模轉換器播放聲音。而從該裝置上讀取資料,則會啟用音效卡上的模數轉換進行錄音操作。

 

/dev/audio:與/dev/dsp類似。使用的編碼方式為mu-law。

 

/dev/mixer:音效卡中混音器的軟體介面,用於將多個聲音訊號組合或進行疊加。對混音器的編程包括如何設定增益,以及如何在不同的音源之間進行切換。

 

/dev/sequencer:用於提供對音效卡中的波表合成器的支援,主要用於電腦音樂軟體上。

 

2. 執行個體

執行個體1:讓擴音器發生

#include <stdio.h><br />#include <stdlib.h><br />#include <unistd.h><br />#include <sys/types.h><br />#include <sys/stat.h><br />#include <fcntl.h><br />#include <sys/ioctl.h><br />#include <linux/kd.h></p><p>#define SPEAKER_DEVICE"/dev/console"</p><p>int main(int argc, char *argv[])<br />{<br />int fd;<br />int freq;</p><p>if(argc !=2)<br />{<br />printf("Usage: %s frequence /n", argv[0]);<br />return 1;<br />}</p><p>freq = atoi(argv[1]);<br />if(freq <=0 || freq > 10000)<br />{<br />printf("the frequence must be in the range from 0 to 10000./n");<br />return 1;<br />}</p><p>fd = open(SPEAKER_DEVICE, O_WRONLY);</p><p>if(fd == -1)<br />{<br />perror("connot open device./n");<br />return 1;<br />}</p><p>int i;<br />int cnt;<br />for(i = 0; i<1000; ++i)<br />{<br />int set_freq = 1190000/freq;<br />ioctl(fd, KIOCSOUND, set_freq);<br />usleep(200);<br />ioctl(fd, KIOCSOUND, 0);<br />usleep(100);<br />}<br />return 0;<br />}<br />

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.