- 简介
alsa-utils提供了一些linux下的alsa声卡测试程序,如声卡控制amixer、播放aplay和录音record,注意声音播放和录音时同一个程序,只需要将aplay名字改为arecord就是录音应用程序; - 下载
下载地址 - 移植
解压后进入解压目录并运行脚本程序:
#!/bin/bash
#INSTALL_DIR=$(pwd)/_install
#cross_compiler=arm-linux-gnueabihf-
HOST=arm-linux-gnueabihf
./configure --host=${HOST} --disable-bat --disable-alsamixer
make
编译成功后在当前目录下amixer/生成amixer应用程序主要用于控制声卡操作,如设置声卡音量,数据链路等;
在aplay/目录中生成aplay应用程序,用于声音播放,注意声音播放和录音用同一个程序,只需cp aplay arecord
就能得到录音程序arecord;将amixer、aplay和arecord三个应用程序拷贝到开发板上;
- 命令简单实用
amixer命令:
#查看amixer帮助
amixer -h
Available options:
-h,--help this help
-c,--card N select the card
-D,--device N select the device, default 'default'
-d,--debug debug mode
-n,--nocheck do not perform range checking
-v,--version print version of this program
-q,--quiet be quiet
-i,--inactive show also inactive controls
-a,--abstract L select abstraction level (none or basic)
-s,--stdin Read and execute commands from stdin sequentially
-R,--raw-volume Use the raw value (default)
-M,--mapped-volume Use the mapped volume
Available commands:
scontrols show all mixer simple controls 显示所有的mixer控件
scontents show contents of all mixer simple controls (default command) 显示所有的mixer控件详细信息
sset sID P set contents for one mixer simple control 设置 scontrols参数
sget sID get contents for one mixer simple control 获取 scontrols参数
controls show all controls for given card 显示所有控件
contents show contents of all controls for given card 显示所有控件详细信息
cset cID P set control contents for one control 设置 controls参数
cget cID get control contents for one control 获取 controls参数
#注意 sset和sget是针对amixer scontrols列举的控件
#而cset和cget则是针对amixer controls列举的控件
#两者有重叠的部分,两者命令使用有一点点差别
amixer sset Headphone 90,90
amixer sget Headphone
amixer cset numid=11,iface=MIXER,name='Headphone Playback Volume' 90,90
amixer cget numid=11,iface=MIXER,name='Headphone Playback Volume'
#其中Headphone 和 numid=11,iface=MIXER,name='Headphone Playback Volume'根据
#amixer scontrols和amixer controls得到
aplay播放音频:
aplay XXX.wav
arecord录音:
#-r 采样率
#-f 格式
#-c 通道数
#-d 录音秒数
arecord -r 44100 -f S16_LE -c 2 -d 3 record.wav