文章目录

  • 1、Description //描述
  • 2、DAPM Widgets //动态音频电源管理部件
    • 2.1 Stream Domain Widgets //流域部件
    • 2.2 Path Domain Widgets //路径域部件
    • 2.3 Platform/Machine domain Widgets
    • 2.4 Codec Domain
    • 2.5 Virtual Widgets //虚拟部件
  • 3、Codec Widget Interconnections //编解码器部件互连
    • 3.1 Machine Widget Interconnections //machine部件连接
  • 4 、Endpoint Widgets //端点部件
  • 5 、DAPM Widget Events //DAPM部件事件
    • 5.1 Event types //事件类型
  • 总结

DAPM(Dynamic Audio Power Management for Portable Devices )//便携式设备的动态音频电源管理。

如下是内核文档 dapm.txt以及我的翻译,其中精简介绍了 dapm 概念、设计目的、如何声明一个 dapm widget、dapm widgets 的类型和域、如何建立一个音频路径、endpoint 的概念、dapm 事件回调函数等。对于dapm 的初学者有很好的指导意义。

1、Description //描述

================================
Dynamic Audio Power Management (DAPM) is designed to allow portable Linux devices to use the minimum amount of power within the audio subsystem at all times. It is independent of other kernel PM and as such, can easily co-exist with the other PM systems.

(DAPM)是为了使基于linux的移动设备上的音频子系统,在任何时候都工作在最小功耗状态下。不依赖kernel其他电源管理,可以方便地和其他电源管理系统共同存在

DAPM is also completely transparent to all user space applications as all power switching is done within the ASoC core. No code changes or recompiling are required for user space applications. DAPM makes power switching decisions based upon any audio stream (capture/playback) activity and audio mixer settings within the device.

DAPM对用户空间的应用程序来说是透明的,所有与电源相关的开关都在ASoc core层中完成。用户空间的应用程序无需对代码做出修改,也无需重新编译。DAPM使得电源切换是基于设备的音频流(捕获/回放)、行为和音频混音设置。

DAPM spans the whole machine. It covers power control within the entire audio subsystem, this includes internal codec power blocks and machine level power systems.

DAPM跨越整个machine,覆盖了全部音频子系统的电源控制,包括内部codec电源模块和machine层的电源系统。

There are 4 power domains within DAPM //DAPM有4个电源域

  1. Codec domain - VREF, VMID (core codec and audio power)
    Usually controlled at codec probe/remove and suspend / resume, although can be set at stream time if power is not needed for side-tone, etc.
    Codec域-VREF,VMID(核心编码器和音频功率)
    通常在codec的 probe/remove(探测/移除)和suspend /resume(暂停/恢复)时设置,但是如果侧音等不需要电源,可以在流时设置。

  2. Platform/Machine domain - physically connected inputs and outputs is platform/machine and user action specific, is configured by the machine driver and responds to asynchronous events e.g when HP are inserted
    Platform/Machine域-有物理连接的输入输出是Platform/Machine 与用户动作相关的,由驱动实现其相应函数。比如耳机插入时,会调用相应的异步处理接口。

  3. Path domain - audio susbsystem signal paths .
    Automatically set when mixer and mux settings are changed by the user. e.g. alsamixer, amixer.
    路径域-音频子系统信号路径
    当mixer(混音器)和mux(多路复用器)被用户改变时自动设置。如alsomixer,amixer.

  4. Stream domain - DACs and ADCs.
    Enabled and disabled when stream playback/capture is started and stopped respectively. e.g. aplay, arecord.
    流域-DAC和ADC
    分别启动和停止流 播放/捕获 时使能和禁用,如aplay,arecord.

All DAPM power switching decisions are made automatically by consulting an audio routing map of the whole machine. This map is specific to each machine and consists of the intercon-nections between every audio component (including internal codec components). All audio components that effect power are called
widgets hereafter.

所有的DAPM的电源开关状态由一个音频路由映射表自动决定。此映射表跟具体的机器有关,由内部每一个音频模块(包括内部codec组件)连接组成。今后,所有的影响电源的音频模块被称为widgets(部件)。

================================

2、DAPM Widgets //动态音频电源管理部件

================================
Audio DAPM widgets fall into a number of types:-
//音频DAPM widgets分为以下几种类型:

o Mixer - Mixes several analog signals into a single analog signal. //混音,将多个模拟信号混合为单个模拟信号
o Mux - An analog switch that outputs only one of many inputs.   //多路输出的选择控制,模拟开关,仅输出许多输入中的一个
o PGA - A programmable gain amplifier or attenuation widget. //一种可编程的增益放大器或衰减的小部件
o ADC - Analog to Digital Converter   //AD转换
o DAC - Digital to Analog Converter  //DA转换
o Switch - An analog switch   //模拟开关
o Input - A codec input pin   //codec输入pin
o Output - A codec output pin //codec输出pin
o Headphone - Headphone (and optional Jack)   //耳机(和可插选孔)
o Mic - Mic (and optional Jack)             //麦克风(和可插选孔)
o Line - Line Input/Output (and optional Jack)  //线路线路输入输出(和可选插孔)
o Speaker - Speaker                         //喇叭
o Supply - Power or clock supply widget used by other widgets. //其他小部件使用的电源或时钟供应小部件。
o Pre - Special PRE widget (exec before all others)//特别的PRE小部件(exec在所有其他之前)

o Post - Special POST widget (exec after all others)//特殊的POST小部件(exec跟随所有其他小部件)

(Widgets are defined in include/sound/soc-dapm.h) //文件路径:include/sound/soc-dapm.h

Widgets are usually added in the codec driver and the machine driver. There are convenience macros defined in soc-dapm.h that can be used to quickly build a list of widgets of the codecs and machines DAPM widgets.

widge一般是在codec和machine驱动中添加。在soc-dapm.h中定义了便利宏,可用于快速定义codec widget和 machine DAPM widget。

Most widgets have a name, register, shift and invert. Some widgets have extra parameters for stream name and kcontrols.

大多数的widget有名称、寄存器、位偏移、反转字段。还有的widget有流名称和kcontrols的额外参数。

================================

2.1 Stream Domain Widgets //流域部件

================================

Stream Widgets relate to the stream power domain and only consist of ADCs (analog to digital converters) and DACs (digital to analog converters).
//流widgets 与流功率域相关,仅由ADC(模数转换器),DAC(数模转换器)组成。

Stream widgets have the following format:-
//流widgets 使用以下格式:

SND_SOC_DAPM_DAC(name, stream name, reg, shift, invert),

NOTE: the stream name must match the corresponding stream name in your codec snd_soc_codec_dai.
//注意:流名称必须与编解码器snd_soc_codec_dai中的相应流名称匹配。

e.g. stream widgets for HiFi playback and capture
//例如:用于HiFi播放和录音的流 widgets
//【Hi-Fi是High-Fidelity的缩写,“高保真”,定义:与原来的声音高度相似的重放声音】

SND_SOC_DAPM_DAC("HiFi DAC", "HiFi Playback", REG, 3, 1).
SND_SOC_DAPM_ADC("HiFi ADC", "HiFi Capture", REG, 2, 1),.

================================

2.2 Path Domain Widgets //路径域部件

================================

Path domain widgets have a ability to control or affect the audio signal or audio paths within the audio subsystem. They have the following form:-

//路径域小部件具有控制或影响音频子系统内的音频信号或音频路径的能力。 它们具有以下形式:

SND_SOC_DAPM_PGA(name, reg, shift, invert, controls, num_controls)

Any widget kcontrols can be set using the controls and num_controls members.
//可以使用controls和num_controls成员设置任何窗口小部件kcontrols。

e.g. Mixer widget (the kcontrols are declared first)
//例如:混音器widget (首先声明kcontrols)

/* Output Mixer */
static const snd_kcontrol_new_t wm8731_output_mixer_controls[] = { SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0), SOC_DAPM_SINGLE("Mic Sidetone Switch", WM8731_APANA, 5, 1, 0), SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),}; SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls, ARRAY_SIZE(wm8731_output_mixer_controls)),

If you dont want the mixer elements prefixed with the name of the mixer widget, you can use SND_SOC_DAPM_MIXER_NAMED_CTL instead. the parameters are the same as for SND_SOC_DAPM_MIXER.

如果您不希望混音器元素以混音器widget的名称为前缀,则可以使用SND_SOC_DAPM_MIXER_NAMED_CTL。 参数与SND_SOC_DAPM_MIXER相同。

================================

2.3 Platform/Machine domain Widgets

================================

Machine widgets are different from codec widgets in that they don’t have a codec register bit associated with them. A machine widget is assigned to each machine audio component (non codec) that can be independently powered. e.g.

machine widgets与codec widgets的不同之处在于它们没有与它们相关联的codec寄存器位。machine widget被分配给可以独立供电的每个机器音频组件(非编解码器或DSP)。 例如

o Speaker Amp                //扬声器放大器
o Microphone Bias           //麦克风偏置
o Jack connectors           //插头连接器

A machine widget can have an optional call back.
machine widget可以具有可选的调用函数。

e.g. Jack connector widget for an external Mic that enables Mic Bias
when the Mic is inserted:-
例如:用于外接麦克风的插孔连接器小部件,可在插入麦克风时启用麦克风偏置: -

static int spitz_mic_bias(struct snd_soc_dapm_widget* w, int event) { gpio_set_value(SPITZ_GPIO_MIC_BIAS,SND_SOC_DAPM_EVENT_ON(event)); return 0;

}

SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),

================================

2.4 Codec Domain

================================
The codec power domain has no widgets and is handled by the codecs DAPM event handler. This handler is called when the codec powerstate is changed wrt to any stream event or by kernel PM events.
codec电源域没有widgets ,由codec DAPM事件处理程序处理。当编解码器powerstate被更改为任何流事件或内核PM事件时,将调用此处理程序。

================================

2.5 Virtual Widgets //虚拟部件

================================
Sometimes widgets exist in the codec or machine audio map that don’t have any corresponding soft power control. In this case it is necessary to create a virtual widget - a widget with no control bits e.g.
有时,codec和machine中的部件在音频映射中没有相关电源控制的操作。 在这种情况下,有必要创建一个虚拟小部件 - 一个没有控制位的小部件,例如

SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_DAPM_NOPM, 0, 0, NULL, 0),

This can be used to merge to signal paths together in software.
这可以用于在软件中合并到信号路径。

After all the widgets have been defined, they can then be added to the DAPM subsystem individually with a call to snd_soc_dapm_new_control().

//在定义了所有小部件之后,可以通过调用snd_soc_dapm_new_control()将它们单独添加到DAPM子系统。

================================

3、Codec Widget Interconnections //编解码器部件互连

================================

Widgets are connected to each other within the codec and machine by audio paths (called interconnections). Each interconnection must be defined in order to create a map of all audio paths between widgets.

codec和machine的部件通过音频路径(称为互连)来建立相互连接。 每个连接必须按顺序通过创建部件之间的path映射来定义。

This is easiest with a diagram of the codec (and schematic of the machine audio system), as it requires joining widgets together via their audio signal paths.

这对于codec(以及机器音频系统的原理图)的图表来说是最简单的,因为它需要通过其音频信号路径将部件连接在一起。

e.g., from the WM8731 output mixer (wm8731.c) //以WM8731输出混音器为例

The WM8731 output mixer has 3 inputs (sources)

  1. Line Bypass Input
  2. DAC (HiFi playback)
  3. Mic Sidetone Input

Each input in this example has a kcontrol associated with it (defined in example above) and is connected to the output mixer via it’s kcontrol name. We can now connect the desti-nation widget (wrt audio signal) with it’s source widgets.

此示例中的每个输入都有一个与之关联的kcontrol(在上面的示例中定义),并通过其kcontrol名称连接到输出混合器。 我们现在可以将目标窗口小部件(wrt音频信号)与其源窗口小部件连接起来。

/* output mixer */
{"Output Mixer", "Line Bypass Switch", "Line Input"},
{"Output Mixer", "HiFi Playback Switch", "DAC"},
{"Output Mixer", "Mic Sidetone Switch", "Mic Bias"},

So we have :-

Destination Widget <=== Path Name <=== Source Widget //目标Widget <===路径名称 <===源Widget

Or:-

Sink, Path, Source

Or :-

“Output Mixer” is connected to the “DAC” via the “HiFi Playback Switch”. // “输出混音器”通过“HiFi播放开关”连接到“DAC”。

When there is no path name connecting widgets (e.g. a direct connection) we pass NULL for the path name.
//当相互连接的部件的没有路径名(例如直接连接)时,我们为路径名传递NULL。

Interconnections are created with a call to:- //连接的建立通过调用下面的函数: -

snd_soc_dapm_connect_input(codec, sink, path, source);

Finally, snd_soc_dapm_new_widgets(codec) must be called after all widgets and interconnections have been registered with the core. This causes the core to scan the codec and machine so that the internal DAPM state matches the physical state of the machine.

最后,在所有的部件和连接都注册到系统后,snd_soc_dapm_new_widgets(codec)必须被调用。 这会导致系统扫描codec和machine,以便内部DAPM状态与machine的物理状态相匹配。

================================

3.1 Machine Widget Interconnections //machine部件连接

================================
Machine widget interconnections are created in the same way as codec ones and directly connect the codec pins to machine level widgets.

//machine部件互连的创建方式与codec相同,直接连接codec到machine层部件。

e.g. connects the speaker out codec pins to the internal speaker. //例如:将扬声器输出codec引脚连接到内部扬声器

/* ext speaker connected to codec pins LOUT2, ROUT2 */
{"Ext Spk", NULL , "ROUT2"},
{"Ext Spk", NULL , "LOUT2"},

This allows the DAPM to power on and off pins that are connected (and in use) and pins that are NC respectively.
//这允许DAPM对有连接的引脚和未使用的引脚来上下电。

================================

4 、Endpoint Widgets //端点部件

================================
An endpoint is a start or end point (widget) of an audio signal within the machine and includes the codec. e.g.
//一个端点是machine包括codec音频信号的开始或结束,例如:

o Headphone Jack                 //耳机插孔
o Internal Speaker              //内置扬声器
o Internal Mic                  //内置麦克风
o Mic Jack                      //麦克风插孔
o Codec Pins                    //Codec引脚

When a codec pin is NC it can be marked as not used with a call to
//当一个codec的引脚是NC时,它可以被标志为未使用,可以用以下函数来设置

snd_soc_dapm_set_endpoint(codec, "Widget Name", 0);

The last argument is 0 for inactive and 1 for active. This way the pin and its input widget will never be powered up and consume power.
//最后的参数0代表未活动状态,1代表活动状态,通过这种方式可以让某些部件永远不会上电,从而节省功耗。

This also applies to machine widgets. e.g. if a headphone is connected to a jack then the jack can be marked active. If the headphone is removed, then the headphone jack can be marked inactive.

这个也适用于machine部件,例如:一个耳机连接到一个插孔,那么这个插孔需要被标记为活动的,如果耳机被拔出,则耳机插孔需要被标记为未活动的

================================

5 、DAPM Widget Events //DAPM部件事件

================================

Some widgets can register their interest with the DAPM core in PM events.
一些部件可以在注册他们感兴趣的到系统的DAPM事件中

e.g. A Speaker with an amplifier registers a widget so the amplifier can be powered only when the spk is in use.
例如:带放大器的扬声器可以注册部件,因此放大器只能在扬声器使用时上电。

/* turn speaker amplifier on/off depending on use 根据使用情况打开/关闭扬声器放大器*/ static int corgi_amp_event(struct snd_soc_dapm_widget *w, int event)
{ gpio_set_value(CORGI_GPIO_APM_ON, SND_SOC_DAPM_EVENT_ON(event)); return 0;
} /* corgi machine dapm widgets */
static const struct snd_soc_dapm_widget wm8731_dapm_widgets = SND_SOC_DAPM_SPK("Ext Spk", corgi_amp_event);

Please see soc-dapm.h for all other widgets that support events.
//对于所有支持事件的部件请看文档soc-dapm.h

================================

5.1 Event types //事件类型

================================

The following event types are supported by event widgets. ///部件支持下面几种类型

/* dapm event types */
#define SND_SOC_DAPM_PRE_PMU 0x1 /* before widget power up */
#define SND_SOC_DAPM_POST_PMU 0x2 /* after widget power up */
#define SND_SOC_DAPM_PRE_PMD 0x4 /* before widget power down */
#define SND_SOC_DAPM_POST_PMD 0x8 /* after widget power down */
#define SND_SOC_DAPM_PRE_REG 0x10 /* before audio path setup */
#define SND_SOC_DAPM_POST_REG 0x20 /* after audio path setup */

思维导图如下:

================================

总结

================================

dapm 是音频系统颇难理解的一块,然而又非常重要,建立音频路径和最小化便携设备的音频能耗都依赖它。以上是内核文档dapm.txt以及对文档内容的翻译,我花了点时间把这块内容整理出来写了这篇博客,希望能对后来者有所帮助。 如若翻译内容有误欢迎大家批评指正!

Linux音频系统-DAPM(一)dapm.txt相关推荐

  1. Linux音频子系统(2) - ALSA ASoC

    1. linux音频子系统介绍 Linux音频系统比较复杂,各层间有很多交叉,可能是最无序的子系统. 1.1 ALSA ALSA 是 Advanced Linux Sound Architecture ...

  2. Linux 音频 API 指南

    http://www.wavecn.com/content.php?id=198 由于历史的原因,在 Linux环境下有多种API系统可用于声音编程.但没有合适的指引就难以找到合乎自己需要的体系.这里 ...

  3. Linux音频软件:Alsa、OSS和Pulseaudio、ESD、

    Linux 音频系统简析 https://blog.csdn.net/meizum10/article/details/17437959 PulseAudio,ESD和ALSA,OSS的关系 http ...

  4. Linux ALSA 音频系统:物理链路篇

    原址 1. Overview 硬件平台及软件版本: Kernel - 3.4.5 SoC - Samsung exynos CODEC - WM8994 Machine - goni_wm8994 U ...

  5. (一)Linux ALSA 音频系统:物理链路篇

    物理链路篇 转自:https://me.csdn.net/zyuanyun Linux ALSA 音频系统:物理链路篇 Linux ALSA 音频系统:物理链路篇 原创 zyuanyun 最后发布于2 ...

  6. Linux ALSA音频系统:platform,machine,codec

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/weixin_41965270/arti ...

  7. (二)Linux ALSA 音频系统:逻辑设备篇

    逻辑设备篇 转自:https://me.csdn.net/zyuanyun Linux ALSA 音频系统:逻辑设备篇 Linux ALSA 音频系统:逻辑设备篇 原创 zyuanyun 最后发布于2 ...

  8. linux文本文件导入数据库,Linux系统下如何将txt文档导入到数据库mysql的方法教程...

    前段时间做小项目的时候遇到了一个需求:把txt文档的数据导入到mysql数据库中,开始本来想直接用Mysql Workbench导入TXT文件,但是最后发现不支持TXT导入,结果我吧嗒吧嗒的去把TXT ...

  9. linux 音频文件切割_适用于 Linux 系统的 6 款最佳音频编辑软件

    适用于 Linux 系统的 6 款最佳音频编辑软件 无论你是专业的音乐制作人,还是只拿来剪辑剪辑音频,搞个手机铃声啥的,音频编辑软件总会派上用场.对于 Linux 系统而言,好用的音频编辑器就有很多款 ...

最新文章

  1. (C++)1046 Shortest Distance
  2. 计算机技能需求新排名:Python 仅排第 3,第 1 你可能猜不到哦
  3. 基于概率统计分析的应用流特征分析
  4. 隐马尔可夫模型中的Viterbi算法zz
  5. Windows下无法新建文件夹
  6. linux时钟告警,Linux记录-告警脚本
  7. 用于单元测试的JUnit教程–最终指南(PDF下载)
  8. iOS-property属性介绍
  9. MySQL执行计划extra中的using index 和 using where using index 的区别
  10. android zxing-3.3.3的用法_Android使用RecyclerView实现复杂的多布局效果
  11. 安装python时需要勾选_软件应用 | 用Python爬取网络站点数据时需要哪些必备库
  12. 趣味实验python,Python小实验:疯狂填词
  13. android流光动画和流光字体
  14. CHECK约束在表继承中的使用
  15. HTTP POST 参数格式
  16. 修改war包中数据库配置信息
  17. 本周AI热点回顾:「时空版」Transformer训练速度远超3D CNN;拒绝内卷的AI狼火了!不想抓羊只想躺!...
  18. Android应用在新浪微博授权提示:文件不存在 C8998 的解决方法
  19. 设计分享|基于51单片机的万年历(汇编)
  20. Python 爬虫实战(1):分析豆瓣中最新电影的影评并制作词云

热门文章

  1. 开机直接进入bios解决方法
  2. 一年了.......
  3. [附源码]java毕业设计家居装修网站
  4. web前端期末大作业【仿12306铁路官网首页】学生网页设计作业源码
  5. 二进制,八进制,十进制,十六进制之间的转换
  6. 软件测试面试题及答案,2021最强版!
  7. 夏普手机要回归中国市场,它真的还有机会吗?
  8. 测试Qt Quick在各个平台上的3D渲染性能
  9. html里的图片地址怎么搞,HTML图片的地址怎么写
  10. C# | WriteLine写入.txt 文件