DAPM之一:概述

2023-11-07

DAPM--Dynamic Audio Power Management,对应结构体是snd_soc_dapm_widget和snd_soc_dapm_route,对应的操作函数是snd_soc_dapm_new_controls()、snd_soc_dapm_add_routes()和snd_soc_dapm_new_widgets()。在我看来,DAPM是音频驱动初接触者的噩梦。从何处来,到何处去?它字面上的意义是音频电源动态管理,但是往往困惑于它是怎么被触发的?而最郁闷的是:这方面的资料是最少的,我涉猎多日,却战果寥寥,看来看去还是内核文档dapm.txt最有参考性。先把这个文档贴上:


Dynamic Audio Power Management for Portable Devices
===================================================

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 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 spans the whole machine. It covers power control within the entire
audio subsystem, this includes internal codec power blocks and machine
level power systems.

There are 4 power domains within DAPM

   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 sidetone, etc.

   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

   3. Path domain - audio susbsystem signal paths
      Automatically set when mixer and mux settings are changed by the user.
      e.g. alsamixer, amixer.

   4. Stream domain - DACs and ADCs.
      Enabled and disabled when stream playback/capture is started and
      stopped respectively. e.g. 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 interconnections between every audio component (including
internal codec components). All audio components that effect power are called
widgets hereafter.


2. DAPM Widgets
===============

Audio DAPM widgets fall into a number of types:-

 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
 o DAC        - Digital to Analog Converter
 o Switch     - An analog switch
 o Input      - A codec input pin
 o Output     - A codec output 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)
 o Post       - Special POST widget (exec after all others)

(Widgets are defined in 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.

Most widgets have a name, register, shift and invert. Some widgets have extra
parameters for stream name and 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).

Stream widgets have the following format:-

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.

e.g. stream widgets for HiFi playback and capture

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.

e.g. Mixer widget (the kcontrols are declared first)

/* 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.

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.

 o Speaker Amp
 o Microphone Bias
 o Jack connectors

A machine widget can have an optional call back.

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.


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.

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().


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.

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.

e.g., from the WM8731 output mixer (wm8731.c)

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 destination widget (wrt audio signal) with it's source widgets.

 /* 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

Or:-

 Sink, Path, Source

Or :-

 "Output Mixer" is connected to the "DAC" via the "HiFi Playback Switch".

When there is no path name connecting widgets (e.g. a direct connection) we
pass NULL for the path name.

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.


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

e.g. connects the speaker out codec pins to the internal speaker.

 /* 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.


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.

 o Headphone Jack
 o Internal Speaker
 o Internal Mic
 o Mic Jack
 o Codec Pins

When a codec pin is NC it can be marked as not used with a call to

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.

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.


5 DAPM Widget Events
====================

Some widgets can register their interest with the DAPM core in PM events.
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.


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 */

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

DAPM之一:概述 的相关文章

  • 菜鸟修炼笔记-alsa-调节音频音量大小

    alsa 调节音频音量大小 前言一 方法一 xff1a 直接放大缓存中的数据1 基本原理2 相关尝试和结果2 1 在播放前放大音频缓存数据2 2 在录制前放大缓存 二 方法二 xff1a 在linux终端直接设置alsa的参数 1 基本原理
  • Linux ALSA 之四:Tinyalsa->Alsa Driver Flow分析

    Tinyalsa gt Alsa Driver Flow 一 概述二 Tinyalsa2 1 tinypcminfo2 2 tinymix2 3 tinyplay2 4 tinycap 三 Tinyalsa gt alsa driver f
  • Linux ALSA 之十:ALSA ASOC Machine Driver

    ALSA ASOC Machine Driver 一 Machine 简介二 ASoC Machine Driver2 1 Machine Driver 的 Platform Driver amp Platform Device 驱动模型2
  • Linux ALSA 之十二:ALSA ASOC Kcontrol

    ALSA ASOC Kcontrol 一 结构体 snd kcontrol new二 ASoC 系统定义的 kcontrol 宏2 1 SOC SINGLE2 2 SOC SINGLE TLV2 3 SOC DOUBLE2 4 Mixer
  • Linux 下ALSA音频工具amixer,aplay,arecord使用

    ALSA音频工具amixer aplay arecord ALSA音频工具编译安装 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61
  • alsa amixer 使用介绍

    alsa utils 提供的工具中 xff0c arecord 可以用来录音 xff0c aplay 可以用来播放 xff0c amixer 可以用来控制音量 增益等 amixer controls numid 61 34 iface 61
  • 龙芯1B核心板使用alsa音频播放设置,aplay播放

    龙芯1B核心板是默认启用alsa音频工具的 只需要进行一些配置就能使用 1 先检查你的板子的alsa工具是否正常 aplay l 可以查看 xff0c 是否已正确安装音频驱动 如果正常 xff0c 能看到你的音频驱动的信息 可能会出现 xf
  • yum解决办法:fatal error: alsa/asoundlib.h: No such file or directory #include <alsa/asoundlib.h>

    错误 libavdevice alsa c 31 28 fatal error alsa asoundlib h No such file or directory include lt alsa asoundlib h gt 安装命令 s
  • DAPM之一:概述

    DAPM Dynamic Audio Power Management 对应结构体是snd soc dapm widget和snd soc dapm route 对应的操作函数是snd soc dapm new controls snd s
  • 以 root 身份运行 python 脚本

    我有以下脚本 usr bin env python import sys import pyttsx def main print running
  • 在 NodeJS 中写入音频文件时读取音频文件

    我正在使用 ffmpeg 通过 alsa 捕获音频并将其写入 wav 文件 但在编写过程中 我需要将捕获的音频发送给第三方 我尝试过几种方法 包括节点生长文件但没能成功 有没有一种方法可以将文件作为流读取 只要它正在写入并根据需要进行处理
  • Alsa全双工通信

    我想使用alsa实现全双工通信 我首先编写了捕获和回放程序 并使用 UDP 通信将数据从捕获的进程传输到回放进程 当我运行两个进程时工作正常 其中一个正在捕获 另一个正在播放 将其视为从 A 到 B 的半双工 当我尝试实现另一个半双工 从
  • 安卓 OpenAL?

    有没有人为 Android 构建过 OpenAL 或者在系统上找到了它的共享库 这似乎是任何类型的游戏的明显需求 但没有可用的资源 据我所知 Android java 声音库似乎无法进行音高变化 因此似乎需要 OpenAL 我知道 Open
  • ALSA:不支持非交错访问?

    ALSA s snd pcm hw params set access http www alsa project org alsa doc alsa lib group p c m h w params html ga4c8f1c6329
  • ALSA中句号的含义

    我在 Linux 上使用 ALSA 和音频应用程序 我发现很棒的文档解释了如何使用它 1 http www linuxjournal com article 6735 page 0 1 and this one http users sus
  • Android:如何配置“tinymix”以使用“tinycap”录制系统音频

    在 Android 中 目前无法使用 Android SDK 录制系统音频 因此 我尝试了一下 TinyALSA 自 Android 4 起 希望可以重新路由音频输出 以便可以录制它 当我在设备上调用 tinymix 时 我得到以下配置 c
  • 枚举捕获 ALSA 设备并从中捕获

    我正在编写一个 C 程序 我想枚举系统中的所有捕获设备 实际上 我知道我有三个网络摄像头加上 集成 麦克风 识别它们并同时开始捕获它们 我使用 snd device name hint 枚举所有 PCM 设备 然后使用 snd device
  • 通话录音 - 使其在 Nexus 5X 上运行(可以生根或定制 ROM)

    我正在尝试使用AudioRecord with AudioSource VOICE DOWNLINK在 Nexus 5X Android 7 1 我自己的 AOSP 版本 上 我已经过了权限阶段 将我的 APK 移至特权应用程序 并进行了调
  • 在 Linux 上使用 PyAudio 列出设备

    在 Linux 上列出音频设备时 我尝试使用 Raspbian RaspberryPi import pyaudio p pyaudio PyAudio for i in range p get device count print p g
  • 是否可以记录虚拟卡的输出?

    我正在尝试使用 dmix 和 dsnoop 通过虚拟卡混合音频文件 aplay s1 wav aplay s2 wav arecord f dat t wav d 3 result wav 但这可能吗 我只有虚拟卡 modprobe snd

随机推荐

  • 实现ListView中每行显示进度条,并且各自显示自己的进度

    package com sagaware process list import java util ArrayList import java util HashMap import java util List import java
  • Web2.0网站一些通用业务采用NoSql的解决方案

    首先理解NoSql的划分 Often NoSQL databases are categorized according to the way they store the data and fall under categories su
  • MySQL生产环境高可用架构实战

    分布式技术MongoDB 1 MySQL高可用集群介绍 1 1 数据库主从架构与分库分表 1 2 MySQL主从同步原理 2 动手搭建MySQL主从集群 2 1 基础环境搭建 2 2 安装MySQL服务 2 2 1 初始化MySQL 2 2
  • 仿射密码 affine

    参考链接 https www cnblogs com 0yst3r 2046 p 12172757 html 仿射加密法 在仿射加密法中 字母表的字母被赋予一个数字 例如 a 0 b 1 c 2 z 25 仿射加密法的密钥为0 25直接的数
  • Incorrect integer value: '' for column 'id' at row 1 错误解决办法

    最近一个项目 在本地php环境里一切正常 ftp上传到虚拟空间后 当执行更新操作 我的目的是为了设置id为空 set id 时提示 Incorrect integer value for column id at row 1 解决办法 方法
  • 广工人福利,openwrt+gduth3c通过inode认证,妈妈再也不用担心我要用电脑开wifi了

    刚开校园网的时候 天天都只能用电脑开wifi 用类似于360wifi 猎豹wifi之类的软件要经常开着电脑 而且电脑网卡发射功率又小 上个厕所wifi就断了 睡觉前在床上还没wifi用 超级不爽 于是从家里面拿来了放在自己房间挂迅雷百度云的
  • x86下的C函数调用惯例

    1 从汇编到C 1 1 汇编语言的局限性 汇编语言是一种符号化了的机器语言 machine code 即用指令助记符 符号地址 标号等符号书写程序的语言 汇编语句与机器语句一一对应 它只是把每条指令及数据用便于记忆的符号书写而已 汇编语言
  • 用自己的数据增量训练预训练语言模型

    预训练模型给各类NLP任务的性能带来了巨大的提升 预训练模型通常是在通用领域的大规模文本上进行训练的 而很多场景下 使用预训练语言模型的下游任务是某些特定场景 如金融 法律等 这是如果可以用这些垂直领域的语料继续训练原始的预训练模型 对于下
  • spring配置文件解读——applicationContext.xml

    spring的配置文件 applicationContext xml 听着晴天看星晴的博客 CSDN博客
  • binutils internal struct

    http fossies org dox binutils 2 23 2 structelf internal sym html dl iterate phdr REPAIR RAX inline hook
  • [动态规划] leetcode 416. 分割等和子集

    问题描述 分割等和子集 给你一个只包含正整数的非空数组 nums 请你判断是否可以将这个数组分割成两个子集 使得两个子集的元素和相等 例子 输入nums 1 5 11 5 输出true 动态规划求解 这是一个0 1背包问题的变种 也就是每种
  • Idea工具使用经典总结

    安装教程 下载地址 https www jetbrains com idea download section windows 准备idea ideaIU 2017 2 3 exe 软件与激活包 JetbrainsCrack 2 6 9 r
  • 设备节点如何与设备驱动关联

    1 上层应用如何调用设备驱动 1 在linux中一切皆是文件 设备驱动程序对上层应用程序来说和普通文件没什么差异 2 上层应用程序通过设备节点来访问驱动程序 在驱动程序注册到内核后 用申请到的主次设备号来创建设备节点 2 向内核注册字符驱动
  • 【已解决】Error: Unable to access jarfile .\xxxx.jar

    报错类型 Error Unable to access jarfile xxxx jar 复现工具的时候 通过命令 java jar xxxx jar 运行 jar 包报了这个错误 报错原因是 在命令行中出现的路径下找不到 xxxx jar
  • micro-app在vue-element-admin中一些使用研究

    1 简述 本文承接上一篇micro app在vue element admi中的搭建 对micro app在vue element admin中的一些平时开发中常用的功能做了一些研究 本文代码 2 路由 关于路由 这边从两方面进行研究 一方
  • ass字幕格式

    ssa ass字幕格式全解析 内容 一 概述 二 文件各个部分解析 三 各种类型的行 四 Script Info 部分的标题行 五 v4 Styles 部分的风格行Style 六 Events 事件部分的对话行Dialogue 七 Even
  • 高通功耗调试18之Tsensor中断频繁触发导致低温下待机功耗高的问题

    问题背景 在内核4 9及之后的版本 低于5C环境温度下待机 由于触发了Tsensor的低温保护机制 可能会遇到较频繁 的tsens中断 11 22 07 12 27 914969 0 0 W GICv3 gic show resume ir
  • [echarts]柱状图的点击事件

    先来一段简洁的写echarts图表的代码 这样获取echarts的dom节点是因为 如果将柱状图封装成了一个组件 在一个页面中多次使用 若还是按常规获取dom节点 会报一个警告 let charts echarts getInstanceB
  • Linux驱动开发(应用程序如何调用驱动)

    1 添加读写接口 1 在应用代码中 2 在驱动代码中 2 应用和驱动之间的数据交换 1 copy from user 用来将数据从用户空间复制到内核空间 2 copy to user 用来将数据从内核空间复制到用户空间 3 write和re
  • DAPM之一:概述

    DAPM Dynamic Audio Power Management 对应结构体是snd soc dapm widget和snd soc dapm route 对应的操作函数是snd soc dapm new controls snd s