首页 > 系统相关 >Linux音频(3):alsa-lib以及alsa-utils

Linux音频(3):alsa-lib以及alsa-utils

时间:2024-05-02 17:01:21浏览次数:14  
标签:LE lib -- utils buffer amixer device alsa

alsa-lib是为了简化、便利用户空间对ALSA驱动框架声卡编程的开源库。

alsa-utils是alsa的一个工具包,里面包含有声卡测试和音频编辑的工具.

1 alsa-lib

alsa-lib在Buildroot中配置如下,包含一系列库插件:

Target packages
  ->Libraries
    ->Audio/Sound
      ->alsa-lib
        ->(/dev/snd) directory with ALSA device files
        ->(all) built PCM plugins
        ->(all) built control plugins
        ->aload
        ->mixer
        ->pcm
        ->rawmidi
        ->hwdep
        ->seq
        ->ucm
        ->alisp
        ->old-symbols
        ->alsa-plugins

2 alsa-utils

alsa-utils是基于alsa-lib以及Kernel ALSA的一系列工具包:

Target packages
  Audio and video applications
    alsa-utils
      alsaconf
      aconnect
      alsactl
      alsaloop
      alsamixer
      alsaucm
      alsatplg
      amidi
      amixer
      aplay/arecord
      aplaymidi
      arecordmidi
      aseqdump
      aseqnet
      bat
      iecset
      speaker-test

2.1 aplay

aplay命令用于播放音频文件,可以使用它来播放 WAV、MP3 等格式的音频文件。aplay支持不同的音频设备,并提供一些选项以调整播放参数。

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--支持Playback的硬件设备列表。
-D, --device=NAME       select PCM by name--选择特定的PCM硬件作为播放设备。
-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--指定播放时长。
-s, --samples=#         interrupt after # samples per channel
-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
-i, --interactive       allow interactive operation from stdin
-m, --chmap=ch1,ch2,..  Give the channel map to override or follow
    --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 coefficient 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
    --dump-hw-params    dump hw_params of the device
    --fatal-errors      treat all errors as fatal
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 S20_LE S20_BE U20_LE U20_BE SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE U18_3BE G723_24 G723_24_1B G723_40 G723_40_1B DSD_U8 DSD_U16_LE DSD_U32_LE DSD_U16_BE DSD_U32_BE
Some of these may not be available on selected hardware
The available 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)

 aplay -l显示当前Playback设备:

**** List of PLAYBACK Hardware Devices ****
card 0: rockchipes8388 [rockchip-es8388], device 0: dailink-multicodecs ES8323.7-0011-0 [dailink-multicodecs ES8323.7-0011-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

选择Card 0 Device 0硬件,立体声方式来播放wav格式音频,对应的设备节点为/dev/snd/pcmC0D0p:

aplay -D hw:0,0 -t wav -v -V stereo topeet_test/05_headphone/1.wav

播放显示如下:

Playing WAVE 'topeet_test/05_headphone/1.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo--音频格式为16bit 44.1KHz Stereo音源。
Hardware PCM card 0 'rockchip-es8388' device 0 subdevice 0
Its setup is:
  stream       : PLAYBACK
  access       : RW_INTERLEAVED
  format       : S16_LE
  subformat    : STD
  channels     : 2
  rate         : 44100
  exact rate   : 44100 (44100/1)
  msbits       : 16
  buffer_size  : 22052
  period_size  : 5513
  period_time  : 125011
  tstamp_mode  : NONE
  tstamp_type  : MONOTONIC
  period_step  : 1
  avail_min    : 5513
  period_event : 0
  start_threshold  : 22052
  stop_threshold   : 22052
  silence_threshold: 0
  silence_size : 0
  boundary     : 6207086186423386112
  appl_ptr     : 0
  hw_ptr       : 0
         +#########################76%|75%#########################+

2.2 arecord

arecord命令用于录制音频,您可以使用它从麦克风、线路输入等音频输入设备中录制声音,并将录制的音频保存为文件。arecord支持不同的音频设备,并提供一些选项以调整录制参数。

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--指定录音Channel数,默认mono,即1。
-f, --format=FORMAT     sample format (case insensitive)
-r, --rate=#            sample rate--指定采样频率。
-d, --duration=#        interrupt after # seconds--指定录音时长。
-s, --samples=#         interrupt after # samples per channel
-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
-i, --interactive       allow interactive operation from stdin
-m, --chmap=ch1,ch2,..  Give the channel map to override or follow
    --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 coefficient 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
    --dump-hw-params    dump hw_params of the device
    --fatal-errors      treat all errors as fatal
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 S20_LE S20_BE U20_LE U20_BE SPECIAL S24_3LE S24_3BE U24_3LE U24_3BE S20_3LE S20_3BE U20_3LE U20_3BE S18_3LE S18_3BE U18_3LE U18_3BE G723_24 G723_24_1B G723_40 G723_40_1B DSD_U8 DSD_U16_LE DSD_U32_LE DSD_U16_BE DSD_U32_BE
Some of these may not be available on selected hardware
The available 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显示Capture硬件设备列表:

**** List of CAPTURE Hardware Devices ****
card 0: rockchipes8388 [rockchip-es8388], device 0: dailink-multicodecs ES8323.7-0011-0 [dailink-multicodecs ES8323.7-0011-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: rockchiphdmiin [rockchip,hdmiin], device 0: fddf8000.i2s-dummy_codec hdmiin-dc-0 [fddf8000.i2s-dummy_codec hdmiin-dc-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

arecord录音:

arecord -f S16_LE -V stereo -r 48000 -d 10 stereo.wav -v
arecord -d 10 -f cd -r 44100 -c 2 -t wav test.wav

将arecord录音通过管道直接给aplay播放:

arecord -f S16_LE -V stereo -r 48000 | aplay

2.3 amixer

amixer命令用于管理音频设置,可以显示和调整音量、切换通道、静音等。您可以使用amixer来获取和设置音频设备的状态和参数。

Usage: amixer <options> [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
  -R,--raw-volume Use the raw value (default)
  -M,--mapped-volume Use the mapped volume

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--显示某一Card Control的序号、接口类型、名称。
  contents        show contents of all controls for given card--显示某一个Card Control的详细信息。
  cset cID P      set control contents for one control
  cget cID        get control contents for one control

Available advanced commands:
  sevents         show the mixer events for simple controls
  events          show the mixer events for simple controls

amixer contents查看Control详细信息:

numid=21,iface=MIXER,name='PCM Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=192,step=0
  : values=181,181
  | dBscale-min=-96.00dB,step=0.50dB,mute=1
amixer cget获取某一个cID的值:amixer cget numid=21,iface=MIXER,name='PCM Volume'。
numid=21,iface=MIXER,name='PCM Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=192,step=0
  : values=192,192
  | dBscale-min=-96.00dB,step=0.50dB,mute=1

 amixer cset设置某一个cID的值:amixer cset numid=21,iface=MIXER,name='PCM Volume' 100。

numid=21,iface=MIXER,name='PCM Volume'
  ; type=INTEGER,access=rw---R--,values=2,min=0,max=192,step=0
  : values=100,100
  | dBscale-min=-96.00dB,step=0.50dB,mute=1

2.4 alsamixer

alsamixer是一个交互式的音频混音控制台程序,它提供了对音量、通道、增益等设置的直观界面。

Usage: alsamixer [options]
Useful options:
  -h, --help              this help
  -c, --card=NUMBER       sound card number or id
  -D, --device=NAME       mixer device name
  -m, --mouse             enable mouse
  -M, --no-mouse          disable mouse
  -f, --config=FILE       configuration file
  -F, --no-config         do not load configuration file
  -V, --view=MODE         starting view mode: playback/capture/all
Debugging options:
  -g, --no-color          toggle using of colors
  -a, --abstraction=NAME  mixer abstraction level: none/basic

alsamixer界面中的操作快捷键:

│Esc     Exit                               
│F1 ? H  Help                               
│F2 /    System information                 
│F3      Show playback controls             
│F4      Show capture controls              
│F5      Show all controls                  
│Tab     Toggle view mode (F3/F4/F5)        
│F6 S    Select sound card                  
│L       Redraw screen                      
│                                           
│Left    Move to the previous control--选择Control。
│Right   Move to the next control           
│                                           
│Up/Down    Change volume--音量了解快捷键。
│+ -        Change volume                   
│Page Up/Dn Change volume in big steps      
│End        Set volume to 0%                
│0-9        Set volume to 0%-90%            
│Q W E      Increase left/both/right volumes
│Z X C      Decrease left/both/right volumes
│B          Balance left and right volumes  
│M          Toggle mute--静音开关。
│< >        Toggle left/right mute          
│                                           
│Space      Toggle capture                  
│; '        Toggle left/right capture       

 alsamixer界面如下:

3 amixer/alsamixer和Control关联

从amixer或者alsamixer中看到的Control,可以在Machine/Platform/Codec的驱动中找到Control原型:

 

标签:LE,lib,--,utils,buffer,amixer,device,alsa
From: https://www.cnblogs.com/arnoldlu/p/18057517

相关文章

  • 使用 python matplotlib 将 LaTex 公式转为 svg
    使用pythonmatplotlib将LaTex公式转为svg,从而方便插入无法打出所需公式的ppt中。importmatplotlib.pyplotaspltdeflatex_formula2svg(text,font_size=12,save_fig='formula.svg'):plt.rc('text',usetex=True)#使用LaTeX渲染文本plt.rc('f......
  • 怎么在windows上用vcpkg方法安装libcurl
    1、到网站上找libcurl的下载页面   https://curl.se/download.html  2、在windows64bit(或者其它下载栏目)中的“Windows64-bit8.7.1libcurlVcpkg”里点击 "8.7.1"(意味着下载libcurl的windows64位版本8.7.7下用vcpkg编译的源码);3、下面是相关说明:Build......
  • 简单解决version 'GLIBC_2.34' not found,version 'GLIBC_2.25' not found
    简单解决version'GLIBC_2.34'notfound,version'GLIBC_2.25'notfound无需手动下载安装包编译前言很多博客都是要手动下载安装包进行编译升级,但这样很容易导致系统崩溃,本博文提供一个简单的方法,参考自博客1,博客2.检查版本strings/usr/lib64/libc.so.6|grepGLIBC_或者......
  • 瑞芯微-I2S | ALSA基础-3
    针对音频设备,linux内核中包含了两类音频设备驱动框架;OSS:开放声音系统包含dsp和mixer字符设备接口,应用访问底层硬件是直接通过sound设备节点实现的;ALSA:先进linux声音架构(AdvancedLinuxSoundArchiecture)以card和组件(PCM、mixer等)为组件,应用是通过ALSA提供的alsa-lib库访......
  • Could not find module '.../libtorchaudio_ffmpeg.pyd' | RuntimeError: StreamRea
    Windows中使用torchaudio.io.StreamReader时报错:FileNotFoundError:Couldnotfindmodule'D:\software\miniconda3\envs\pytorch\Lib\site-packages\torchaudio\lib\libtorchaudio_ffmpeg.pyd'(oroneofitsdependencies).Tryusingthefullpathwith......
  • MATLAB运行simulink模型显示找不到库Failed to load library
    MATLAB运行simulink模型显示找不到库Failedtoloadlibrary‘原因上述的错误即提示加载某一个库失败了,原因就是MATLAB需要在其设定的setpath中寻找。设置paths查看paths添加成功后再次打开MATLAB的setpath,可以看到相关文件及库被添加进来了。点击save进行保存,重新运......
  • [转载] RPATH/LD_LIBRARY_PATH/RUNPATH
    原文地址:https://zhuanlan.zhihu.com/p/534778561rpath和runpath都是用来指定搜索动态链接库的目录的,如果不清楚动态链接库是什么,可见静态库vs动态库。动态链接库(sharedlibraries)作为库并不像静态库一样和可执行文件绑定,而是在运行时加载。但,可执行文件在运行时怎么知道库的......
  • cglib
    测试服务publicclassDataConverterComponent{publicvoidconvert(){System.out.println("DataConverterComponentconvert");}}cglib代理类,需要实现MethodInterceptor接口publicclassDataConverterComponentInterceptorimplementsMethodInte......
  • Frontend basic library and DLL sharing technology
    一、前端基础库第一部分frame_dependency  序号 名称 引入来源 gzip大小 使用版本 最新版本 描述 1@optimizely/react-sdkmichaels-ssr29.41kb2.9.22.9.2Optimizely功能实验是一款面向产品开发......
  • VS2008 LIB的升级改造
    今天用VS2019编译一个在VS2008下Coding的工程的时候,VS给出了一堆链接错误信息,如下图所示的一些错误: Error47errorLNK2019:unresolvedexternalsymbol"public:__thiscallstd::_Mutex::~_Mutex(void)"(??1_Mutex@std@@QAE@XZ)referencedinfunction"public:void__t......