ALSA 音频工具 amixer、aplay、arecord

ALSA 音频工具 amixer、aplay、arecordALSA 简介 ALSA 是 AdvancedLinu 高级 Linux 声音架构的简称 它在 Linux 操作系统上提供了音频和 MIDI MusicalInstr 音乐设备数字化接口 的支持 在 2 6 系列内核中 ALSA 已经成为默认的声音子系统 用来替换 2 4 系列内核中的 OSS OpenSound

ALSA 简介


ALSA 音频工具编译安装

2、创建 alsa 安装目录(如 /home/rudy/alsa 目录),并在该目录下创建 install 目录,接着把压缩包拷到 alsa 目录下。

3、编译 alsa-lib 用户空间库。

# tar -xvf alsa-lib-1.0.27.2.tar.bz2  # cd alsa-lib-1.0.27.2  # CC=arm-none-linux-gnueabi-gcc ./configure --host=arm-linux --prefix=/home/rudy/alsa/install/ # make  # make install 
# tar -xvf alsa-utils-1.0.27.2.tar.bz2  # cd alsa-utils-1.0.27.2  # CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/home/rudy/alsa/install/ --host=arm-linux --with-alsa-inc-prefix=/home/rudy/alsa/install/include --with-alsa-prefix=/home/rudy/alsa/install/lib --disable-alsamixer --disable-xmlto --disable-nls  # make 

音频录制——arecord

# arecord -h Usage: arecord [OPTION]... [FILE]... -h, --help help  --version print current version -l, --list-devices list all soundcards and digital audio devices -L, --list-pcms list device names -D, --device=NAME select PCM by name -q, --quiet quiet mode -t, --file-type TYPE file type (voc, wav, raw or au) -c, --channels=# channels  -f, --format=FORMAT sample format (case insensitive) -r, --rate=# sample rate  -d, --duration=# interrupt after # seconds  -M, --mmap mmap stream -N, --nonblock nonblocking mode -F, --period-time=# distance between interrupts is # microseconds  -B, --buffer-time=# buffer duration is # microseconds   --period-size=# distance between interrupts is # frames   --buffer-size=# buffer duration is # frames  -A, --avail-min=# min available space for wakeup is # microseconds  -R, --start-delay=# delay for automatic PCM start is # microseconds   (relative to buffer size if <= 0) -T, --stop-delay=# delay for automatic PCM stop is # microseconds from xrun  -v, --verbose show PCM structure and setup (accumulative) -V, --vumeter=TYPE enable VU meter (TYPE: mono or stereo) -I, --separate-channels one file for each channel  --disable-resample disable automatic rate resample  --disable-channels disable automatic channel conversions  --disable-format disable automatic format conversions  --disable-softvol disable software volume control (softvol)  --test-position test ring buffer position  --test-coef=# test coeficient for ring buffer position (default 8)   expression for validation is: coef * (buffer_size / 2) --test-nowait do not wait for ring buffer - eats whole CPU  --max-file-time=# start another output file when the old file has recorded   for this many seconds --process-id-file write the process ID here  --use-strftime apply the strftime facility to the output file name Recognized sample formats are: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW A_LAW IMA_ADPCM MPEG GSM SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE Some of these may not be available on selected hardware The availabled format shortcuts are: -f cd (16 bit little endian, 44100, stereo) -f cdr (16 bit big endian, 44100, stereo) -f dat (16 bit little endian, 48000, stereo) 

  用 # arecord -l 命令可以列出声卡和数字音频设备,如:

card 0: SOUND0 [TI81XX SOUND0], device 0: TVP-PCM tvp5158-hifi-0 [] Subdevices: 1/1 Subdevice #0: subdevice #0 card 0: SOUND0 [TI81XX SOUND0], device 1: AIC3X tlv320aic3x-hifi-1 [] Subdevices: 1/1 Subdevice #0: subdevice #0 

-D 参数用于指定音频设备 PCM,以 hwx,x 开头(前 x 表示声卡号,后 x 表示设备号)。根据上面 # arecord -l 列出的设备,如果选择 tvp5158 来录制声音的话,那么 pcm 设备就为 hw0,0,如果选择 tlv320aic3x,则 pcm 设备为 hw0,1。

-r 指定采样频率:5512/8000/11025/16000/22050/32000/44100/48000/64000/88200/96000//。

-f 指定采样格式:cd/cdr/dat。

用 arecord 录制音频的例子如下(录制完后在 /a 目录下可以找到 1.wmv 文件):

# arecord -Dhw:0,1 -r8000 -f cd /a/1.wmv 

音频播放——aplay

# aplay -h Usage: aplay [OPTION]... [FILE]... -h, --help help  --version print current version -l, --list-devices list all soundcards and digital audio devices -L, --list-pcms list device names -D, --device=NAME select PCM by name -q, --quiet quiet mode -t, --file-type TYPE file type (voc, wav, raw or au) -c, --channels=# channels  -f, --format=FORMAT sample format (case insensitive) -r, --rate=# sample rate  -d, --duration=# interrupt after # seconds  -M, --mmap mmap stream -N, --nonblock nonblocking mode -F, --period-time=# distance between interrupts is # microseconds  -B, --buffer-time=# buffer duration is # microseconds   --period-size=# distance between interrupts is # frames   --buffer-size=# buffer duration is # frames  -A, --avail-min=# min available space for wakeup is # microseconds  -R, --start-delay=# delay for automatic PCM start is # microseconds   (relative to buffer size if <= 0) -T, --stop-delay=# delay for automatic PCM stop is # microseconds from xrun  -v, --verbose show PCM structure and setup (accumulative) -V, --vumeter=TYPE enable VU meter (TYPE: mono or stereo) -I, --separate-channels one file for each channel  --disable-resample disable automatic rate resample  --disable-channels disable automatic channel conversions  --disable-format disable automatic format conversions  --disable-softvol disable software volume control (softvol)  --test-position test ring buffer position  --test-coef=# test coeficient for ring buffer position (default 8)   expression for validation is: coef * (buffer_size / 2) --test-nowait do not wait for ring buffer - eats whole CPU  --max-file-time=# start another output file when the old file has recorded   for this many seconds --process-id-file write the process ID here  --use-strftime apply the strftime facility to the output file name Recognized sample formats are: S8 U8 S16_LE S16_BE U16_LE U16_BE S24_LE S24_BE U24_LE U24_BE S32_LE S32_BE U32_LE U32_BE FLOAT_LE FLOAT_BE FLOAT64_LE FLOAT64_BE IEC958_SUBFRAME_LE IEC958_SUBFRAME_BE MU_LAW A_LAW IMA_ADPCM MPEG GSM SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE Some of these may not be available on selected hardware The availabled format shortcuts are: -f cd (16 bit little endian, 44100, stereo) -f cdr (16 bit big endian, 44100, stereo) -f dat (16 bit little endian, 48000, stereo) 

  与 arecord 命令类似,用 # aplay -l 可以列出声卡和数字音频设备。
一个简单的播放例子如下:

# aplay -Dhw:0,1 -r8000 -f cd /a/1.wmv 

如果想要一边播放一边收听可以用下面利用管道的命令:

# arecord -Dhw:0,1 -r -f cd|aplay -Dhw:0,1 -r 

音频配置——amixer

amixer 用法说明:

# amixer -h Usage: amixer 
   
     [ 
    command]  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  Available commands: scontrols show all mixer simple controls scontents show contents 
    of all mixer simple controls (default 
    command)  sset 
    sID P 
    set contents 
    for 
    one mixer simple control sget 
    sID 
    get contents 
    for 
    one mixer simple control 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 cget cID 
    get control contents 
    for 
    one control 
   
# amixer cget numid=94,iface=MIXER,name='Left PGA Mixer Line1R Switch' numid=94,iface=MIXER,name='Left PGA Mixer Line1R Switch' ; type=BOOLEAN,access=rw------,values=1  : values=off 

4、根据控制参数类型设置控制参数使用 # amixer cset + 控制参数 + 设置参数 命令。如:

# amixer cset numid=94,iface=MIXER,name='Left PGA Mixer Line1R Switch' on numid=94,iface=MIXER,name='Left PGA Mixer Line1R Switch' ; type=BOOLEAN,access=rw------,values=1  : values=on 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208535.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 上午11:21
下一篇 2026年3月19日 上午11:22


相关推荐

  • 使用C++解决八数码问题

    使用C++解决八数码问题八数码问题问题描述:通过单步移动把下面的矩阵移动成1-8环绕一周的矩阵(即0在中间,1-8顺序排成一圈,1在哪无所谓)217860345283164705 \begin{matrix} 2&8&3\\ 1&6&4\\ 7&0&5\\ \end{matrix}(1)分别用宽度和深度搜索进行;(2)假设启发式的方程为f(n)=d(n)+…

    2022年7月12日
    27
  • maven 打的包在哪_maven打包流程学习「建议收藏」

    maven 打的包在哪_maven打包流程学习「建议收藏」前言:最近工作中遇到了几次跟maven打包相关的问题,每个问题上网查资料解决都花了不少时间,很影响工作进度。既然遇到好几次,每次都能发现知识盲点,干脆总结整理一下,啃掉这个难啃的骨头。ps:最近看到了一个很有意思句子:因为今天不想跑步,所以才去跑,这是长距离跑者的思维方式。转载:正文:还是首先描述一下最近遇到的几个问题吧:一、初见springboot多模块项目mvn打包遇到的问题-存在依赖但却…

    2022年5月11日
    44
  • Linux 新建文件命令

    Linux 新建文件命令1 创建文件夹 mkdir p 文件夹名 p 确保目录名称存在 不 bai 存在的就建一个 2 创建文件 toucha txt

    2026年3月19日
    1
  • Redis 修改默认端口号 修改配置文件 redis.windows.conf[通俗易懂]

    Redis 修改默认端口号 修改配置文件 redis.windows.conf[通俗易懂]简单说明一下Redis修改端口号的方法,本文用的是修改redis.windows.conf文件的方式,主要代码已经用橙色标记以便于各位伙伴直接复制使用。1.首先找到redis.windows.conf文件的位置,然后右键选择工具打开,如下图:2.打开之后可以直接Ctrl+F快捷键搜索port63或者port6379前提是你之前没有修改过端口号,或者直接下…

    2026年1月14日
    8
  • 一款不错的Linux命令行下的FTP客户端软件

    一款不错的Linux命令行下的FTP客户端软件文章作者 张宴本文版本 v1 0 最后修改 2008 12 12 转载请注明原文链接 http blog s135 com post 387 一款 Linux 命令行下的 FTP 客户端软件 ncftp 用来作整个目录批量上传 ncftpput 是它的一个附带程序 在 shell 脚本中调用 ncftpput 上传文件到 FTP 服务器 非常方便 详细内容见其官方网站 http

    2026年3月26日
    2
  • JAVA三元运算符_java中三元运算符详解

    JAVA三元运算符_java中三元运算符详解一:三元运算符条件表达式?取值1:取值2三元运算符是ifelse或者ifelseifelse的简写形式,可以使代码看起来简洁些。privateStringternary1(intfirst){System.out.println("=================================================================…

    2022年8月30日
    6

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号