“ALSA overview”的版本间的差异

来自百问网嵌入式Linux wiki
 
(未显示同一用户的10个中间版本)
第13行: 第13行:
 
===Component descriptions===
 
===Component descriptions===
  
*'''alsa-utils''' (User space)
+
*'''alsa-utils''' (用户空间)
The ALSA utility package, provided by the Linux community, contains the command line utilities for the ALSA project (aplay, arecord, amixer, alsamixer ...). These tools are useful for controlling soundcards. They also provide an example of ALSA API use, for application implementation.
+
Linux社区提供的ALSA实用程序包包含用于ALSA项目的命令行实用程序(aplay, arecord, amixer, alsamixer ...). 这些工具对于控制声卡很有用。 它们还提供了用于应用程序实现的ALSA API使用示例。
 
*'''alsa-lib''' (User space)
 
*'''alsa-lib''' (User space)
The ALSA Library package contains the ALSA library used by programs (for instance alsa-utils programs) requiring an access to the ALSA sound interface. The ALSA library provides a level of abstraction, such as the PCM and control abstractions, over the audio devices provided by the kernel modules.
+
ALSA库软件包包含需要访问ALSA声音接口的程序 (例如alsa-utils程序) 使用的ALSA库。ALSA库在内核模块提供的音频设备上提供了一个抽象级别,例如PCM和控制抽象。
 
*'''ALSA framework''' (Kernel space)
 
*'''ALSA framework''' (Kernel space)
The ALSA core provides an API to implement audio drivers and PCM/control interfaces to expose audio devices on the userland.
+
ALSA内核提供了一个API,用于实现音频驱动程序和PCM /控制接口,以在用户区公开音频设备。
The PCM interface handles the data flow and control. The interface manages controls exported by the ALSA driver (audio path, volumes...).
+
PCM接口处理数据流和控制。 该界面管理由ALSA驱动程序导出的控件(音频路径,音量...)。
  
 
*'''ASoC framework (ALSA System On Chip)''' (Kernel space)
 
*'''ASoC framework (ALSA System On Chip)''' (Kernel space)
The aim of the ALSA System on Chip (ASoC) layer<ref>[https://www.kernel.org/doc/html/latest/sound/soc/index.html ASoC layer documentation]</ref> is to improve ALSA support for embedded system-on-chip processors and audio codecs. The ASoC framework provides a DMA engine which interfaces with DMA framework to handle the transfer of audio samples. ASoC also supports the dynamic power management of audio pathes through the DAPM driver. ASoC acts as an ALSA driver, which splits an embedded audio system into three types of platform independent drivers: the CPU DAI, the codec and the machine drivers.
+
ALSA片上系统(ASoC)层的作用<ref>[https://www.kernel.org/doc/html/latest/sound/soc/index.html ASoC layer documentation]</ref>是为了改进 ALSA支持嵌入式片上系统处理器和音频编解码器。 ASoC框架提供了一个DMA引擎,该引擎与DMA框架接口以处理音频样本的传输。ASoC还通过DAPM驱动程序支持音频路径的动态电源管理。 ASoC充当ALSA驱动程序,它将嵌入式音频系统分为三种与平台无关的驱动程序:CPU DAI,编解码器和机器驱动程序。
  
 
*'''ASoC drivers''' (Kernel space)
 
*'''ASoC drivers''' (Kernel space)
  
ASoC drivers allow the implementation of hardware dependent code for  ASoC driver classes:
+
ASoC驱动程序允许为ASoC驱动程序类实现与硬件相关的代码:
  
 
:* Codec drivers:
 
:* Codec drivers:
::These drivers are the drivers for the backend audio components. (see Codec peripherals below)
+
::这些驱动程序是后端音频组件的驱动程序。 (请参阅下面的编解码器外围设备)
  
 
:* CPU DAI drivers:
 
:* CPU DAI drivers:
::There is a specific CPU DAI driver for each STM32 audio peripheral (see CPU DAI peripherals below). Each CPU DAI supports at least one of the following protocols: I2S, PCM, or S/PDIF.
+
::每个STM32音频外设都有一个特定的CPU DAI驱动程序(请参阅下面的CPU DAI外围设备) 每个CPU DAI至少支持以下协议之一:I2S,PCM或S / PDIF。
  
 
:* Machine drivers:
 
:* Machine drivers:
::The machine drivers describe and bind the CPU DAIs and codec drivers together to create the DAI links and ALSA soundcard. The ASoC framework provides a machine driver implementing a generic soundcard called "audio-graph-card"<ref name="Audio graph card bindings">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/sound/audio-graph-card.txt}}</ref><ref name="Device graph bindings">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/graph.txt}}</ref>. This generic machine driver is used for STM32 MPUs soundcards.
+
::机器驱动程序将CPU DAI和编解码器驱动程序描述并绑定在一起,以创建DAI链接和ALSA声卡。 ASoC框架提供了一种机器驱动程序,用于实现称为“ audio-graph-card”<ref name="Audio graph card bindings">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/sound/audio-graph-card.txt}}</ref><ref name="Device graph bindings">{{CodeSource | Linux kernel | Documentation/devicetree/bindings/graph.txt}}</ref>. 该通用机器驱动程序用于STM32 MPU声卡。
 
 
The schematic below, illustrates the general layout of an ASoC soundcard. Refer to [[Soundcard configuration|soundcard configuration]] to see examples of soundcards implementation for STM32 MPUs boards.
 
  
 +
下面的示意图说明了ASoC声卡的总体布局。 请参阅 [[Soundcard configuration|soundcard configuration]] 以查看STM32 MPU板的声卡实现示例。
 
[[File:asoc_generic_soundcard.png|link=]]
 
[[File:asoc_generic_soundcard.png|link=]]
  
*'''CPU DAI peripherals''' (Hardware)
+
*'''CPU DAI外围设备''' (硬件)
:The ST microprocessor peripheral provides the CPU audio interface. The audio internal peripheral list can be found in [[:Category:Audio peripherals|Audio peripherals section]].
+
:ST微处理器外围设备提供CPU音频接口。 音频内部外围设备列表可在[[:Category:Audio peripherals|Audio peripherals section]]中找到。
  
*'''Codec peripherals''' (Hardware)
+
*'''编解码器外围设备''' (硬件)
:The codec peripherals are the external (none CPU) hardware audio I/O devices (i.e. audio codec IC, digital microphone, amplifier, simple IO connector ...).
+
:编解码器外设是外部(无CPU)硬件音频I / O设备 (即音频编解码器IC,数字麦克风,放大器,简单的IO连接器...).
  
 
===API descriptions===
 
===API descriptions===
* '''User space interface:'''
+
* '''用户空间接口:'''
:The ALSA library reference <ref>[http://www.alsa-project.org/alsa-doc/alsa-lib/ ALSA library API]</ref> documents the userland API library.
+
:ALSA库参考<ref>[http://www.alsa-project.org/alsa-doc/alsa-lib/ ALSA library API]</ref> 记录了userland API库。
* '''Kernel driver interface:'''
+
* '''内核驱动程序接口:'''
:The ALSA kernel documentation <ref>[https://www.kernel.org/doc/html/latest/sound/kernel-api/index.html ALSA and ASoC driver API documentation]</ref> documents the ASOC and ALSA driver APIs.
+
:ALSA内核文档 <ref>[https://www.kernel.org/doc/html/latest/sound/kernel-api/index.html ALSA and ASoC driver API documentation]</ref> 记录了ASOC和ALSA驱动程序API。
  
 
==Configuration==
 
==Configuration==
  
*'''Kernel Configuration'''
+
*'''内核配置'''
 
 
The ALSA/ASoC and the audio graph card must be enabled in the kernel configuration, as shown below, to enable the sound support. On top of this, the user has to activate the CPU and Codec drivers according to the chosen hardware. The user can use Linux [[Menuconfig or how to configure kernel | Menuconfig tool]] to select the required drivers:
 
  
 +
如下所示,必须在内核配置中启用ALSA / ASoC和音频图形卡,以启用声音支持。最重要的是,用户必须根据所选的硬件激活CPU和编解码器驱动程序。 用户可以使用Linux [[Menuconfig or how to configure kernel | Menuconfig tool]] 以选择所需的驱动程序:
 
<pre>
 
<pre>
 
[*] Device Drivers
 
[*] Device Drivers
第73行: 第71行:
 
</pre>
 
</pre>
  
*'''Device tree configuration'''
+
*'''设备树配置'''
  
The audio sub-system is configured through the soundcard configuration in the [[Device tree|device tree]]. The [[Soundcard configuration|soundcard configuration]] article describes the soundcards available for STM32MPUs on various board. This article details how to configure the [[:Category:Audio peripherals|audio peripherals]] used to implement the soundcards.
+
通过 [[Device tree|device tree]]中的声卡配置来配置音频子系统。[[Soundcard configuration|soundcard configuration]] 文章描述了各种板上可用于STM32MPU的声卡。 本文详细介绍了如何配置用于实现声卡的[[:Category:Audio peripherals|audio peripherals]]
  
 
==How to use==
 
==How to use==
  
The alsa-utils pakage provides a set of utilities to manage audio devices in the Linux kernel: [https://linux.die.net/man/1/aplay aplay], [https://linux.die.net/man/1/arecord arecord], [https://linux.die.net/man/1/amixer amixer], [https://linux.die.net/man/1/iecset iecset] and [https://linux.die.net/man/1/alsactl alsactl]. An overview of these utilities is given below:
+
alsa-utils pakage提供了一组实用程序来管理Linux内核中的音频设备:[https://linux.die.net/man/1/aplay aplay], [https://linux.die.net/man/1/arecord arecord], [https://linux.die.net/man/1/amixer amixer], [https://linux.die.net/man/1/iecset iecset] [https://linux.die.net/man/1/alsactl alsactl]。这些实用程序的概述如下:
 
 
 
=== Playback ===
 
=== Playback ===
*List playback devices
+
*列出播放设备
 
  '''Board $>''' aplay -l
 
  '''Board $>''' aplay -l
  
*Play a wav file on card [X] device [Y]  
+
*在卡[X]设备[Y]上播放wav文件
 
  '''Board $>''' aplay -D hw:[X],[Y] <filename.wav>
 
  '''Board $>''' aplay -D hw:[X],[Y] <filename.wav>
  
*Play a wav file or a generated signal on card [X] device [Y]
+
*在卡[X]设备[Y]上播放wav文件或生成的信号
 
  '''Board $>''' speaker-test -D hw:[X],[Y]
 
  '''Board $>''' speaker-test -D hw:[X],[Y]
  
Refer to [[How to play audio]] article, to find examples of playback use cases on STM32MPU boards.
+
请参阅[[How to play audio]] 一文,以查找STM32MPU板上的回放用例示例。
  
 
=== Record ===
 
=== Record ===
*List record devices
+
*列出记录设备
 
  '''Board $>''' arecord -l
 
  '''Board $>''' arecord -l
*Capture audio from card [X] device [Y]
+
*从卡[X]设备[Y]捕获音频
 
  '''Board $>''' arecord -D hw:[X],[Y] -f dat <filename.wav>
 
  '''Board $>''' arecord -D hw:[X],[Y] -f dat <filename.wav>
  
Refer to [[How to record audio]] article, to find examples of record use cases for the STM32MPU boards.
+
请参阅 [[How to record audio]] 文章,查找STM32MPU主板的录制用例示例。
  
 
=== Controls ===
 
=== Controls ===
*List card [X] controls
+
*列表卡[X]控件
 
  '''Board $>''' amixer -c [X] controls
 
  '''Board $>''' amixer -c [X] controls
*Set card [X] controls [Y] to value [Z]
+
*将卡[X]的控件[Y]设置为[Z]
 
  '''Board $>''' amixer -c [X] cset name='[Y]' '[Z]'
 
  '''Board $>''' amixer -c [X] cset name='[Y]' '[Z]'
*Store soundcard [X] controls state
+
*存储声卡[X]控制状态
 
  '''Board $>''' alsactl store [X]
 
  '''Board $>''' alsactl store [X]
*Restore soundcard [X] controls state
+
*恢复声卡[ x ]控件状态
 
  '''Board $>''' alsactl restore [X]
 
  '''Board $>''' alsactl restore [X]
  
Refer to [[Soundcard configuration]] article to find examples of control configuration for the STM32MPU boards.
+
请参阅[ [[Soundcard configuration]] 文章,以找到STM32MPU板的控制配置示例。
  
 
=== IEC controls ===
 
=== IEC controls ===
*List iec958 parameters
+
*列出iec958参数
 
  '''Board $>''' iecset -h
 
  '''Board $>''' iecset -h
*Set card [X] iec958 parameter [Y] to value [Z]
+
*将卡[X] iec958参数[Y]设置为值[Z]
 
  '''Board $>''' iecset -c [X] cset [Y] [Z]
 
  '''Board $>''' iecset -c [X] cset [Y] [Z]
*Dump card [X] iec958 value
+
*转储卡[X] iec958值
 
  '''Board $>''' iecset -c [X] -x
 
  '''Board $>''' iecset -c [X] -x
  
 
==How to trace and debug the framework==
 
==How to trace and debug the framework==
This chapter introduces tools useful for debugging and monitoring the audio framework and drivers. It comes as an extension to the [[Linux_tracing,_monitoring_and_debugging]] article.
+
本章介绍了可用于调试和监视音频框架和驱动程序的工具。 它是 [[Linux_tracing,_monitoring_and_debugging]] 文章的扩展。
  
 
=== How to monitor ===
 
=== How to monitor ===
This section introduces ALSA framework monitoring methods. Refer to [[:Category:Linux monitoring tools|Linux monitoring tools]] articles for further information.
+
本节介绍ALSA框架监视方法。 有关更多信息,请参阅[[:Category:Linux monitoring tools|Linux monitoring tools]]文章。
 
 
 
==== Procfs filesystem ====
 
==== Procfs filesystem ====
The ALSA '''asound''' directory<ref>[https://www.kernel.org/doc/html/latest/sound/designs/procfile.html ALSA proc files]</ref> in [[Pseudo_filesystem|procfs]] file system, provides a lot of information on sound cards. The PCM proc files, provides useful PCM substream debugging information, such as hardware/software parameters, stream status and buffer information.
+
ALSA'''asound'''目录<ref>[https://www.kernel.org/doc/html/latest/sound/designs/procfile.html ALSA proc files]</ref> [[Pseudo_filesystem|procfs]] 文件系统中, 提供了大量有关声卡的信息。 PCM proc文件提供有用的PCM子流调试信息,例如硬件/软件参数,流状态和缓冲区信息。
 
+
示例:
Examples:
+
:* 列出PCM音频设备:
:* List PCM audio devices:
 
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
 
  '''Board $>''' cat /proc/{{highlight|asound}}/pcm
 
  '''Board $>''' cat /proc/{{highlight|asound}}/pcm
 
</div>
 
</div>
:* Get hardware parameters of a PCM audio device (device "0" of card "0" here):
+
:* 获取PCM音频设备的硬件参数(此处为卡0的设备0)
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
 
  '''Board $>''' cat /proc/{{highlight|asound}}/card0/pcm0p/sub0/hw_params
 
  '''Board $>''' cat /proc/{{highlight|asound}}/card0/pcm0p/sub0/hw_params
第141行: 第136行:
  
 
==== Debugfs filesystem ====
 
==== Debugfs filesystem ====
The '''asoc''' directory in [[Debugfs|debugfs]] file system provides information on sound card components.
+
[[Debugfs|debugfs]]文件系统中的'''asoc'''目录提供有关声卡组件的信息。
  
Examples:
+
示例:
 
:* List DAIs
 
:* List DAIs
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
第149行: 第144行:
  
 
</div>
 
</div>
:* List DAPMs of "xxx.audio-controller" CPU DAI of "{{highlight|STM32MP1-EV}}" soundcard
+
:* 列出 "xxx.audio-controller"声卡的 "{{highlight|STM32MP1-EV}}" CPU DAI的DAPM
 
<div style="margin-left: 2em;">
 
<div style="margin-left: 2em;">
 
  '''Board $>''' ls /sys/kernel/debug/{{highlight|asoc}}/{{highlight|STM32MP1-EV}}/xxx.audio-controller/dapm
 
  '''Board $>''' ls /sys/kernel/debug/{{highlight|asoc}}/{{highlight|STM32MP1-EV}}/xxx.audio-controller/dapm
第155行: 第150行:
  
 
=== How to trace ===
 
=== How to trace ===
This section introduces tracing methods for ALSA framework. Refer to [[:Category:Linux_tracing_tools|Linux_tracing_tools]] articles to go further.
+
本节介绍了ALSA框架的跟踪方法。参见 [[:Category:Linux_tracing_tools|Linux_tracing_tools]] 文章将进一步。
  
 
==== Dynamic traces ====
 
==== Dynamic traces ====
ALSA framework and driver debug traces can be added to the kernel logs by using the [[How_to_use_the_kernel_dynamic_debug|dynamic debug]] mechanism.
+
可以使用 [[How_to_use_the_kernel_dynamic_debug|dynamic debug]] 机制将ALSA框架和驱动程序调试跟踪添加到内核日志中。
* Example: Activate dynamic trace for SAI Linux driver, and print the traces to the console:
+
* 示例:启动SAI Linux驱动的动态跟踪,并将跟踪打印到控制台:
  
 
  '''Board $>''' echo -n 'file stm32_sai.c +p; file stm32_sai_sub.c +p' > /sys/kernel/debug/dynamic_debug/control;  
 
  '''Board $>''' echo -n 'file stm32_sai.c +p; file stm32_sai_sub.c +p' > /sys/kernel/debug/dynamic_debug/control;  
第165行: 第160行:
  
 
==== Tracing filesystem ====
 
==== Tracing filesystem ====
The Linux kernel offers a [[Pseudo_filesystem|tracefs]] filesystem, provided with Linux kernel tracing framework. ALSA and ASoC have their own tracepoints in this tracing filesystem:
+
Linux内核提供了 [[Pseudo_filesystem|tracefs]] 文件系统,并随Linux内核跟踪框架一起提供。 ALSA和ASoC在此跟踪文件系统中具有自己的跟踪点:
* '''asoc''' entry for ASoC, provides the DAPM, jack and bias level tracepoints.<ref name="tracepoints">{{CodeSource | Linux kernel | Documentation/trace/tracepoint-analysis.rst}}</ref>
+
* ASoC的'''asoc''' 条目提供了DAPM,插孔和偏置电平跟踪点。<ref name="tracepoints">{{CodeSource | Linux kernel | Documentation/trace/tracepoint-analysis.rst}}</ref>
* '''snd_pcm''' entry for ALSA, provides the PCM buffers and PCM hardware parameters tracepoints<ref name="tracepoints"></ref><ref name="tracepoints_pcm">[https://www.kernel.org/doc/html/latest/sound/designs/tracepoints.html ALSA tracepoints]</ref>.
+
* ALSA的'''snd_pcm'''条目,提供了PCM缓冲区和PCM硬件参数跟踪点<ref name="tracepoints"></ref><ref name="tracepoints_pcm">[https://www.kernel.org/doc/html/latest/sound/designs/tracepoints.html ALSA tracepoints]</ref>.
  
 
===== Activate DAPM traces =====
 
===== Activate DAPM traces =====
Prerequisite: the CONFIG_FUNCTION_TRACER configuration must first be enabled in the [[Menuconfig or how to configure kernel | Linux kernel configuration]]
+
先决条件:必须首先在 [[Menuconfig or how to configure kernel | Linux kernel configuration]]中启用CONFIG_FUNCTION_TRACER配置
* Enable trace<ref name="tracepoints"></ref>
+
* 启用追踪<ref name="tracepoints"></ref>
 
  '''Board $>''' echo '1' > /sys/kernel/debug/tracing/events/{{highlight|asoc}}/enable
 
  '''Board $>''' echo '1' > /sys/kernel/debug/tracing/events/{{highlight|asoc}}/enable
* Check log:
+
* 检查日志:
 
  '''Board $>''' cat /sys/kernel/debug/tracing/trace
 
  '''Board $>''' cat /sys/kernel/debug/tracing/trace
  
 
===== Activate PCM hardware parameter traces =====
 
===== Activate PCM hardware parameter traces =====
Prerequisite: the CONFIG_FUNCTION_TRACER and CONFIG_SND_DEBUG configurations must first be enabled in the [[Menuconfig or how to configure kernel | Linux kernel configuration]]
+
先决条件:必须首先在 [[Menuconfig or how to configure kernel | Linux kernel configuration]]中启用CONFIG_FUNCTION_TRACER和CONFIG_SND_DEBUG配置。
* Enable trace<ref name="tracepoints"></ref>
+
* 启用追踪<ref name="tracepoints"></ref>
 
  '''Board $>''' echo '1' > /sys/kernel/debug/tracing/events/{{highlight|snd_pcm}}/enable
 
  '''Board $>''' echo '1' > /sys/kernel/debug/tracing/events/{{highlight|snd_pcm}}/enable
* Check log:
+
* 检查日志:
 
  '''Board $>''' cat /sys/kernel/debug/tracing/trace
 
  '''Board $>''' cat /sys/kernel/debug/tracing/trace
  
 
===== Activate PCM buffer state traces (PCM ring buffer overrun/underrun debugging) =====
 
===== Activate PCM buffer state traces (PCM ring buffer overrun/underrun debugging) =====
Prerequisite: the CONFIG_FUNCTION_TRACER, CONFIG_SND_DEBUG, CONFIG_SND_DEBUG_VERBOSE and SND_PCM_XRUN_DEBUG configurations must first be enabled in the [[Menuconfig or how to configure kernel | Linux kernel configuration]]
+
先决条件:必须首先在 [[Menuconfig or how to configure kernel | Linux kernel configuration]]中启用CONFIG_Function_TRACE、CONFIG_SND_DEBUG、CONFIG_SND_DEBUG_VERBOSE和SND_PCM_XRUN_DEBUG配置
* Set XRUN trace verbosity<ref>[http://www.alsa-project.org/main/index.php/XRUN_Debug XRUN Debug]</ref>
+
* 设置XRUN跟踪详细程度<ref>[http://www.alsa-project.org/main/index.php/XRUN_Debug XRUN Debug]</ref>
  # Enable basic debugging and stack dump
+
  # 启用基本调试和堆栈转储
 
  '''Board $>''' echo 3 > /proc/asound/card0/pcm0p/xrun_debug
 
  '''Board $>''' echo 3 > /proc/asound/card0/pcm0p/xrun_debug
* Enable trace<ref name="tracepoints"></ref>
+
* 启用追踪<ref name="tracepoints"></ref>
 
  '''Board $>''' echo '1' > /sys/kernel/debug/tracing/events/{{highlight|snd_pcm}}/enable
 
  '''Board $>''' echo '1' > /sys/kernel/debug/tracing/events/{{highlight|snd_pcm}}/enable
* Check log:
+
* 检查日志:
 
  '''Board $>''' cat /sys/kernel/debug/tracing/trace
 
  '''Board $>''' cat /sys/kernel/debug/tracing/trace
  
 
=== How to debug ===
 
=== How to debug ===
Refer to the [[:Category:Linux debugging tools|Linux debugging tools]] articles.
+
请参阅 [[:Category:Linux debugging tools|Linux debugging tools]] 文章。
  
 
==Source code location==
 
==Source code location==
第212行: 第207行:
 
==References==
 
==References==
 
<references />
 
<references />
 
<noinclude>
 
[[Category:ALSA]]
 
{{PublicationRequestId | 10644 | 2019-02-06 | StephenG}}
 
{{ArticleBasedOnModel | Framework overview article model}}
 
</noinclude>
 

2020年11月5日 (四) 10:00的最新版本

本文提供有关高级Linux声音体系结构(ALSA)的信息,该体系结构为Linux操作系统提供音频功能。

Purpose

本文的目的是介绍ALSA框架。

ALSA框架为Linux提供了全面的音频功能,包括音频流的录制和播放,模拟或数字格式,以及路由和混合功能。 ALSA还支持音频中间件,如 PulseAudio, Gstreamer或Android。

System overview

ALSAOverview.png

Component descriptions

  • alsa-utils (用户空间)

Linux社区提供的ALSA实用程序包包含用于ALSA项目的命令行实用程序(aplay, arecord, amixer, alsamixer ...). 这些工具对于控制声卡很有用。 它们还提供了用于应用程序实现的ALSA API使用示例。

  • alsa-lib (User space)

ALSA库软件包包含需要访问ALSA声音接口的程序 (例如alsa-utils程序) 使用的ALSA库。ALSA库在内核模块提供的音频设备上提供了一个抽象级别,例如PCM和控制抽象。

  • ALSA framework (Kernel space)

ALSA内核提供了一个API,用于实现音频驱动程序和PCM /控制接口,以在用户区公开音频设备。 PCM接口处理数据流和控制。 该界面管理由ALSA驱动程序导出的控件(音频路径,音量...)。

  • ASoC framework (ALSA System On Chip) (Kernel space)

ALSA片上系统(ASoC)层的作用[1]是为了改进 ALSA支持嵌入式片上系统处理器和音频编解码器。 ASoC框架提供了一个DMA引擎,该引擎与DMA框架接口以处理音频样本的传输。ASoC还通过DAPM驱动程序支持音频路径的动态电源管理。 ASoC充当ALSA驱动程序,它将嵌入式音频系统分为三种与平台无关的驱动程序:CPU DAI,编解码器和机器驱动程序。

  • ASoC drivers (Kernel space)

ASoC驱动程序允许为ASoC驱动程序类实现与硬件相关的代码:

  • Codec drivers:
这些驱动程序是后端音频组件的驱动程序。 (请参阅下面的编解码器外围设备)
  • CPU DAI drivers:
每个STM32音频外设都有一个特定的CPU DAI驱动程序(请参阅下面的CPU DAI外围设备) 每个CPU DAI至少支持以下协议之一:I2S,PCM或S / PDIF。
  • Machine drivers:
机器驱动程序将CPU DAI和编解码器驱动程序描述并绑定在一起,以创建DAI链接和ALSA声卡。 ASoC框架提供了一种机器驱动程序,用于实现称为“ audio-graph-card”[2][3]. 该通用机器驱动程序用于STM32 MPU声卡。

下面的示意图说明了ASoC声卡的总体布局。 请参阅 soundcard configuration 以查看STM32 MPU板的声卡实现示例。 Asoc generic soundcard.png

  • CPU DAI外围设备 (硬件)
ST微处理器外围设备提供CPU音频接口。 音频内部外围设备列表可在Audio peripherals section中找到。
  • 编解码器外围设备 (硬件)
编解码器外设是外部(无CPU)硬件音频I / O设备 (即音频编解码器IC,数字麦克风,放大器,简单的IO连接器...).

API descriptions

  • 用户空间接口:
ALSA库参考[4] 记录了userland API库。
  • 内核驱动程序接口:
ALSA内核文档 [5] 记录了ASOC和ALSA驱动程序API。

Configuration

  • 内核配置

如下所示,必须在内核配置中启用ALSA / ASoC和音频图形卡,以启用声音支持。最重要的是,用户必须根据所选的硬件激活CPU和编解码器驱动程序。 用户可以使用Linux Menuconfig tool 以选择所需的驱动程序:

[*] Device Drivers
    [*] Sound card support
        [*] Advanced Linux Sound Architecture
            [*] ALSA for SoC audio support
                STMicroelectronics STM32 SOC audio support
	             [ ] STM32 SAI interface (Serial Audio Interface) support
	             [ ] STM32 I2S interface (SPI/I2S block) support
	             [ ] STM32 S/PDIF receiver (SPDIFRX) support
                CODEC drivers
	             [ ] ...
                [*] ASoC Audio Graph sound card support
  • 设备树配置

通过 device tree中的声卡配置来配置音频子系统。soundcard configuration 文章描述了各种板上可用于STM32MPU的声卡。 本文详细介绍了如何配置用于实现声卡的audio peripherals

How to use

alsa-utils pakage提供了一组实用程序来管理Linux内核中的音频设备:aplay, arecord, amixer, iecsetalsactl。这些实用程序的概述如下:

Playback

  • 列出播放设备
Board $> aplay -l
  • 在卡[X]设备[Y]上播放wav文件
Board $> aplay -D hw:[X],[Y] <filename.wav>
  • 在卡[X]设备[Y]上播放wav文件或生成的信号
Board $> speaker-test -D hw:[X],[Y]

请参阅How to play audio 一文,以查找STM32MPU板上的回放用例示例。

Record

  • 列出记录设备
Board $> arecord -l
  • 从卡[X]设备[Y]捕获音频
Board $> arecord -D hw:[X],[Y] -f dat <filename.wav>

请参阅 如何录制音频 文章,查找STM32MPU主板的录制用例示例。

Controls

  • 列表卡[X]控件
Board $> amixer -c [X] controls
  • 将卡[X]的控件[Y]设置为[Z]
Board $> amixer -c [X] cset name='[Y]' '[Z]'
  • 存储声卡[X]控制状态
Board $> alsactl store [X]
  • 恢复声卡[ x ]控件状态
Board $> alsactl restore [X]

请参阅[ Soundcard configuration 文章,以找到STM32MPU板的控制配置示例。

IEC controls

  • 列出iec958参数
Board $> iecset -h
  • 将卡[X] iec958参数[Y]设置为值[Z]
Board $> iecset -c [X] cset [Y] [Z]
  • 转储卡[X] iec958值
Board $> iecset -c [X] -x

How to trace and debug the framework

本章介绍了可用于调试和监视音频框架和驱动程序的工具。 它是 top命令 文章的扩展。

How to monitor

本节介绍ALSA框架监视方法。 有关更多信息,请参阅Linux monitoring tools文章。

Procfs filesystem

ALSAasound目录[6]procfs 文件系统中, 提供了大量有关声卡的信息。 PCM proc文件提供有用的PCM子流调试信息,例如硬件/软件参数,流状态和缓冲区信息。 示例:

  • 列出PCM音频设备:
Board $> cat /proc/asound/pcm
  • 获取PCM音频设备的硬件参数(此处为卡0的设备0):
Board $> cat /proc/asound/card0/pcm0p/sub0/hw_params

Debugfs filesystem

调试文件系统(debugfs)文件系统中的asoc目录提供有关声卡组件的信息。

示例:

  • List DAIs
Board $> cat /sys/kernel/debug/asoc/dais
  • 列出 "xxx.audio-controller"声卡的 "STM32MP1-EV" CPU DAI的DAPM
Board $> ls /sys/kernel/debug/asoc/STM32MP1-EV/xxx.audio-controller/dapm

How to trace

本节介绍了ALSA框架的跟踪方法。参见 Linux_tracing_tools 文章将进一步。

Dynamic traces

可以使用 dynamic debug 机制将ALSA框架和驱动程序调试跟踪添加到内核日志中。

  • 示例:启动SAI Linux驱动的动态跟踪,并将跟踪打印到控制台:
Board $> echo -n 'file stm32_sai.c +p; file stm32_sai_sub.c +p' > /sys/kernel/debug/dynamic_debug/control; 
Board $> dmesg -n8;

Tracing filesystem

Linux内核提供了 tracefs 文件系统,并随Linux内核跟踪框架一起提供。 ALSA和ASoC在此跟踪文件系统中具有自己的跟踪点:

  • ASoC的asoc 条目提供了DAPM,插孔和偏置电平跟踪点。[7]
  • ALSA的snd_pcm条目,提供了PCM缓冲区和PCM硬件参数跟踪点[7][8].
Activate DAPM traces

先决条件:必须首先在 Linux kernel configuration中启用CONFIG_FUNCTION_TRACER配置

  • 启用追踪[7]
Board $> echo '1' > /sys/kernel/debug/tracing/events/asoc/enable
  • 检查日志:
Board $> cat /sys/kernel/debug/tracing/trace
Activate PCM hardware parameter traces

先决条件:必须首先在 Linux kernel configuration中启用CONFIG_FUNCTION_TRACER和CONFIG_SND_DEBUG配置。

  • 启用追踪[7]
Board $> echo '1' > /sys/kernel/debug/tracing/events/snd_pcm/enable
  • 检查日志:
Board $> cat /sys/kernel/debug/tracing/trace
Activate PCM buffer state traces (PCM ring buffer overrun/underrun debugging)

先决条件:必须首先在 Linux kernel configuration中启用CONFIG_Function_TRACE、CONFIG_SND_DEBUG、CONFIG_SND_DEBUG_VERBOSE和SND_PCM_XRUN_DEBUG配置

  • 设置XRUN跟踪详细程度[9]
# 启用基本调试和堆栈转储
Board $> echo 3 > /proc/asound/card0/pcm0p/xrun_debug
  • 启用追踪[7]
Board $> echo '1' > /sys/kernel/debug/tracing/events/snd_pcm/enable
  • 检查日志:
Board $> cat /sys/kernel/debug/tracing/trace

How to debug

请参阅 Linux debugging tools 文章。