DAPM之三:audio paths与asound.conf

其实asound.conf真跟dapm没多大关系,之所以把它也纳入dapm系列之一,是为了考虑到知识的连贯性。在<DAPM之二:AUDIO PATHS与dapm kcontrol>提到:通过配置好asound.conf,上层则可打开asound.conf中定义的虚拟设备,而自动选择相应的音频通道。这是asound.conf很重要的一个作用,从这方面来说,并不是跟dapm完全没关系。


一、认识asound.conf

做alsa的基本都能体会到alsa-lib的复杂与强大,而alsa-lib的强大正是从asound.conf与.asoundrc等配置文件体现出来。alsa驱动开发只是一个方面,而真正想随心所欲的配置音频设备,asound.conf与.asoundrc的掌握是必不可少的。所幸,这方面的资料还是比较丰富,所需了解的知识点基本都能从官网上找到文档甚至example。

http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html

http://alsa.opensrc.org/.asoundrc


二、配置audio path

首先我们先看看plugin中hooks:http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html#pcm_plugins_hooks

This plugin is used to call some 'hook' function when this plugin is opened, modified or closed. Typically, it is used to change control values for a certain state specially for the PCM (see the example below).


# Hook arguments definition
hook_args.NAME {
        ...                     # Arbitrary arguments
}


# PCM hook type
pcm_hook_type.NAME {
        [lib STR]               # Library file (default libasound.so)
        [install STR]           # Install function (default _snd_pcm_hook_NAME_install)
}


# PCM hook definition
pcm_hook.NAME {
        type STR                # PCM Hook type (see pcm_hook_type)
        [args STR]              # Arguments for install function (see hook_args)
        # or
        [args { }]              # Arguments for install function
}


# PCM hook plugin
pcm.NAME {
        type hooks              # PCM with hooks
        slave STR               # Slave name
        # or
        slave {                 # Slave definition
                pcm STR         # Slave PCM name
                # or
                pcm { }         # Slave PCM definition
        }
        hooks {
                ID STR          # Hook name (see pcm_hook)
                # or
                ID { }          # Hook definition (see pcm_hook)
        }
}


Example:




        hooks.0 {
                type ctl_elems
                hook_args [
                        {
                                name "Wave Surround Playback Volume"
                                preserve true
                                lock true
                                optional true
                                value [ 0 0 ]
                        }
                        {
                                name "EMU10K1 PCM Send Volume"
                                index { @func private_pcm_subdevice }
                                lock true
                                value [ 0 0 0 0 0 0 255 0 0 0 0 255 ]
                        }
                ]
        }


Here, the controls "Wave Surround Playback Volume" and "EMU10K1 PCM Send Volume" are set to the given values when this pcm is accessed. Since these controls take multi-dimensional values, the value field is written as an array. When preserve is true, the old values are saved and restored when the pcm is closed. The lock means that the control is locked during this pcm is opened, and cannot be changed by others. When optional is set, no error is returned but ignored even if the specified control doesn't exist.

我们可以定义一个名为NAME的hook plugin,在这个plugin中,我们可以操作之前提到的dapm kcontrol,达到音频通道切换的目的。另外注意:

When preserve is true, the old values are saved and restored when the pcm is closed.  当preserve设置为true时,则该pcm关闭时,kcontrol会恢复到之前的值.
The lock means that the control is locked during this pcm is opened, and cannot be changed by others.  当lock设置为true时,则在该pcm打开期间,kcontrol的值不会被其他的pcm改变.
When optional is set, no error is returned but ignored even if the specified control doesn't exist. 当optional设置为true时,则指定的kcontrol不存在时不会返回错误.


三、示范配置

以<DAPM之二:AUDIO PATHS与dapm kcontrol>的红色线路为例,在Android平台上写一个linein录音直送到SPK输出的hooks plugin:

pcm.AndroidPlayback_Speaker_normal {
	type hooks 
	slave.pcm { 
		type hw 
		card 0 
		device 0 
	} 
	hooks.0 { 
		type ctl_elems 
		hook_args [
			{ 
				name 'Left Input PGA Switch' 
				value true 
			}
			{ 
				name 'Left Input PGA LINPUT1 Switch' 
				preserve true
				lock true
				value true 
			}
			{ 
				name 'Left Input Mixer Input PGA Switch'
				preserve true
				lock true 
				value true 
			}
			{ 
				name 'Left Output Mixer Left Input Mixer Switch'
				preserve true
				lock true 
				value true 
			}
			{ 
				name 'LINEOUT1 Switch' 
				value true 
			}
		] 
	}
}

把这个asound.conf放到/etc目录下,再启动Android可以做这个测试,应该可以听到Linein输入的录音信号直接在SPK上输出。

Android的三种模式:normal、ringtone和incall,这些模式的音频通道切换也是可以通过这样配置asound.conf实现的。


  • 1
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
好的,根据您提供的学习需求,我为您提供以下的详细知识点: 1. codec驱动:codec驱动是指用于驱动音频解码器(codec)的软件模块。在Linux系统中,codec驱动通常是通过ALSA(Advanced Linux Sound Architecture)实现的。codec驱动通常包括以下几个部分:硬件接口层、寄存器访问层、音频控制接口层和音频解码接口层。 2. 声卡注册流程:声卡注册是指将声卡的硬件资源与操作系统的声卡驱动程序进行绑定的过程。在Linux系统中,声卡注册一般是通过ALSA框架实现的。声卡注册的流程包括以下几个步骤:声卡硬件资源的探测、声卡驱动程序的加载、声卡驱动程序的初始化、声卡设备的创建和声卡设备的注册。 3. dapmdapm(Dynamic Audio Power Management)是一种动态音频功耗管理技术。它可以根据当前的音频播放情况自动调整音频硬件的功耗,从而实现节能的目的。在Linux系统中,dapm通常是通过ALSA框架实现的。dapm技术包括以下几个部分:DAI(Digital Audio Interface)、Route、Widget和Control。 4. audio routing规则:音频路由规则是指音频数据在不同的硬件模块之间传输的规则。在Linux系统中,音频路由规则通常是通过ALSA框架实现的。音频路由规则包括以下几个部分:音频数据的采集、音频数据的编码、音频数据的解码、音频数据的播放和音频数据的传输。 5. tinymix调试方式:tinymix是一种调试音频驱动的工具。它可以通过命令行界面来设置音频硬件的参数。在Linux系统中,tinymix通常是通过ALSA框架实现的。使用tinymix可以实现以下几个功能:查询音频硬件的参数、设置音频硬件的参数、测试音频硬件的功能和调试音频驱动的问题。 希望这些知识点对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值