Alsa-lib层,为不同的驱动提供统一的接口alsa API,简化了开发人员对于驱动层的调用开发。接口定义地址:
https://www.alsa-project.org/alsa-doc/alsa-lib/
关于asound.conf的配置,可以参考官网解释:
https://www.alsa-project.org/main/index.php/Asoundrc
详细的插件讲解,官网网址:
https://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html
1. 什么是asound.conf
asound.conf配置文件,是alsa-lib的默认配置文件,路径在 /etc/,可以用来配置alsa库的一些附加功能。这个文件不是alsa库运行时所必须的,没有它alsa库也可以正常运行。asound.conf允许对声卡或者设备进行更高级的控制,提供访问alsa-lib中的pcm插件方法,允许你做更多的复杂的控制,比如可以把声卡组合成一个或者多声卡访问多个I/O。
ps:在usr/local/shar/alsa/中有一个文件叫---alsa.conf,asound.conf 这个文件在调用snd_pcm_open这个api函数时,会被加载同时解析。
2. 什么是插件(plugins)?
在ALSA中,PCM插件扩展了PCM设备的功能和特性。插件可以自动处理诸如:命名设备、采样率转换、通道间的采样复制、写入文件、为多个输入/输出连接声卡/设备(不同步采样)、使用多通道声卡/设备等工作。
3. Plugin: hw
此插件直接与ALSA内核驱动程序通信,它是一种没有任何转换的原始通信。
pcm.name {
type hw # Kernel PCM
card INT/STR # Card name (string) or number (integer)
[device INT] # Device number (default 0)
[subdevice INT] # Subdevice number (default -1: first available)
[sync_ptr_ioctl BOOL] # Use SYNC_PTR ioctl rather than the direct mmap access for control structures
[nonblock BOOL] # Force non-blocking open mode
[format STR] # Restrict only to the given format
[channels INT] # Restrict only to the given channels
[rate INT] # Restrict only to the given rate
[chmap MAP] # Override channel maps; MAP is a string array
}
nonblock选项指定设备是否以非阻塞方式打开。注意此选项并不会更改读/写访问的阻塞行为。只影响打开设备时的阻塞行为。如果想保持与旧ALSA版本的兼容性,请关闭此选项。
下面是一个例子:
pcm.!default {
type hw
card 0
}
ctl.!default {
type hw