歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux嵌入式 >> Linux嵌入式應用開發- Ubuntu 音頻錄音編程

Linux嵌入式應用開發- Ubuntu 音頻錄音編程

日期:2017/3/1 10:33:00   编辑:Linux嵌入式

軟件:Ubuntu eclipse gcc

1,音頻開發模型:

OSS(open sound system) linux/unix 平台的上早期的統一音頻接口。linux kernl 2.6 版本以前其它提供兩種設備文件以供編程。 常用的操作函數為open、close、read、write、ioctl.

(/dev/dsp錄音設備文件/dev/audio播放設備文件)

ALSA(a)目前流行的編譯框架。linux 2.6 版本發後支持。

提供統一的編程接口:snd_pcm_open、snd_pcm_close、snd_pcm_hw_params

基設備文件為:/dev/snd/pcmC0D0p/dev/snd/pcmC0D0c /dev/snd/pcmC0D1p/dev/snd/timer

可以通過bash命令查看 alsa 驅動版本:

root@ubuntu:cat /proc/asound/version

Advanced linux Sound Architecture Driver Version 1.0.23

2,Alsa-lib 編譯

a,下載並安裝 alsa-lib庫

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /2012年資料/2月/12日/Linux嵌入式應用開發- Ubuntu 音頻錄音編程/

root@ubuntu: tar -xvf alsa-lib-1.0.13.tar.bz2

root@ubuntu:./configure

root@ubuntu:make

root@ubuntu: make install

3,編程

a,添加頭文件

#include <alsa/asoundlib.h>

b,編程錄音代碼.

  1. >#include <stdio.h>
  2. #include <stdlib.h>
  3. #include <alsa/asoundlib.h>
  4. main (int argc, char *argv[])
  5. {
  6. int i;
  7. int err;
  8. short buf[128];
  9. snd_pcm_t *playback_handle;
  10. snd_pcm_hw_params_t *hw_params;
  11. if ((err = snd_pcm_open (&playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
  12. fprintf (stderr, "cannot open audio device %s (%s)\n",
  13. argv[1],
  14. snd_strerror (err));
  15. exit (1);
  16. }

寫完程序 在link 時 添加參數 -lasound

Copyright © Linux教程網 All Rights Reserved