ALSA Core 与 PCM 设备机制与实现详解

ALSA Core 与 PCM 设备机制与实现详解

源码路径rk3588/kernel-6.1/sound/core/
文档目录linuxDoc/sound/


目录


一、原理

ALSA(Advanced Linux Sound Architecture) 在内核提供:

  • 统一 主设备号(通常 116)+ 次设备号 区分 control/pcm/timer
  • PCM 抽象:playback/capture、周期、格式、速率
  • Control:音量、开关、路由(mixer 元素)

ASoC 声卡最终也注册为 ALSA struct snd_card,对用户态 API 一致


二、字符设备复用 sound.c

core/sound.c(含中文综述注释):

  1. 用户 open("/dev/snd/pcmC0D0p")snd_open
  2. minorsnd_minors[]
  3. replace_fops 为真实驱动(pcm/control)
  4. 调用具体 ->open

驱动通过 snd_register_device() 登记,关联 struct device 与 sysfs。


三、声卡与 PCM

文件 作用
sound.c minor 复用、模块加载 snd-card-N
pcm.c PCM 设备创建、runtime、hw_params
pcm_native.c ioctl 路径(用户态接口)
control.c kcontrol
init.c 子系统初始化

关键结构

  • struct snd_card:逻辑声卡(索引 0、1…)
  • struct snd_pcm:逻辑 PCM 设备(device 号)
  • struct snd_pcm_substream:播放或采集流
  • struct snd_pcm_runtime:buffer、period、状态机

硬件参数在 hw_paramssw_params 中协商(格式 S16_LE、采样率、通道)。


四、控制与 proc

  • /dev/snd/controlC0:mixer 与控制项
  • /proc/asound/cardspcmC0D0p:调试信息

五、RK3588

嵌入式通常 card0 为 ASoC 注册声卡;HDMI 与 ES8388 可能为 同一 card 多 PCM多 card,由 DT 与 machine 驱动决定。

用户态:aplay -lamixer contents


附录

工具 对应内核
aplay PCM playback
amixer control API

下一篇02 ASoC

文章互动

阅读 --

留言

0 条留言

正在加载留言…