[Alsa Document]6, DAI.txt

本文介绍了ASoC支持的三种主要数字音频接口(DAI):AC97,I2S和PCM,详细解释了每种接口的特点、工作原理及应用场景,如位时钟、左/右时钟、帧时钟等关键概念。

其实本来不想来介绍DAI,但是为了文档的完整性,还是放在这边,内容比较简单,就说了一个事情——DAI包含三种总线接口:AC97,I2S和PCM。

本篇来介绍DAI (Digital Audio Interface, 数字音频接口)
基于4.9.123版本内核 Documentation/sound/alsa/soc/DAI.txt

ASoC currently supports the three main Digital Audio Interfaces (DAI) found on
SoC controllers and portable audio CODECs today, namely AC97, I2S and PCM.
ASoC目前支持SoC控制器和便携式音频编解码器上的三种主要数字音频接口(DAI),即
AC97,I2S和PCM。

AC97
====

  AC97 is a five wire interface commonly found on many PC sound cards. It is
now also popular in many portable devices. This DAI has a reset line and time
multiplexes its data on its SDATA_OUT (playback) and SDATA_IN (capture) lines.
The bit clock (BCLK) is always driven by the CODEC (usually 12.288MHz) and the
frame (FRAME) (usually 48kHz) is always driven by the controller. Each AC97
frame is 21uS long and is divided into 13 time slots.
AC97是许多PC声卡上常见的五线接口。 它现在在许多便携式设备中也很流行。 该DAI具有复
位线,并在其SDATA_OUT(回放)和SDATA_IN(捕获)线上对其数据进行时间复用。 位时
钟(BCLK)始终由CODEC(通常为12.288MHz)驱动,帧(FRAME)(通常为48kHz)始
终由控制器驱动。 每个AC97帧长21uS,分为13个时隙。

The AC97 specification can be found at :-
http://www.intel.com/p/en_US/business/design

I2S
===

 I2S is a common 4 wire DAI used in HiFi, STB and portable devices. The Tx and
Rx lines are used for audio transmission, whilst the bit clock (BCLK) and
left/right clock (LRC) synchronise the link. I2S is flexible in that either the
controller or CODEC can drive (master) the BCLK and LRC clock lines. Bit clock
usually varies depending on the sample rate and the master system clock
(SYSCLK). LRCLK is the same as the sample rate. A few devices support separate
ADC and DAC LRCLKs, this allows for simultaneous capture and playback at
different sample rates.
I2S是HiFi,STB和便携式设备中常用的4线DAI。 Tx和Rx线用于音频传输,而位时钟(BCLK)
和左/右时钟(LRC)同步链路。 I2S非常灵活,控制器或CODEC可以驱动(主控)BCLK和
LRC时钟线。 位时钟通常根据采样速率和主系统时钟(SYSCLK)而变化。 LRCLK与采样率
相同。 一些器件支持单独的ADC和DAC LRCLK,这允许以不同的采样率同时捕获和回放。

I2S has several different operating modes:-
I2S有几种不同的操作模式: - 

 o I2S - MSB is transmitted on the falling edge of the first BCLK after LRC transition.
   I2S  - 在LRC转换后,在第一个BCLK的下降沿发送MSB。

 o Left Justified - MSB is transmitted on transition of LRC.
   左对齐 - 在LRC转换时发送MSB。

 o Right Justified - MSB is transmitted sample size BCLKs before LRC transition.
   右对齐 - 在LRC转换之前,MSB传输样本大小BCLK。

PCM
===

PCM is another 4 wire interface, very similar to I2S, which can support a more
flexible protocol. It has bit clock (BCLK) and sync (SYNC) lines that are used
to synchronise the link whilst the Tx and Rx lines are used to transmit and
receive the audio data. Bit clock usually varies depending on sample rate
whilst sync runs at the sample rate. PCM also supports Time Division
Multiplexing (TDM) in that several devices can use the bus simultaneously (this
is sometimes referred to as network mode).
PCM是另一种4线接口,与I2S非常相似,可以支持更灵活的协议。 它具有位时钟(BCLK)和
同步(SYNC)线,用于同步链路,而Tx和Rx线用于发送和接收音频数据。 位时钟通常根据
采样率而变化,而同步以采样率运行。 PCM还支持时分复用(TDM),因为几个设备可以同
时使用总线(这有时称为网络模式)。

Common PCM operating modes:-
常见的PCM操作模式: - 

 o Mode A - MSB is transmitted on falling edge of first BCLK after FRAME/SYNC.
   模式A  - 在FRAME / SYNC之后,在第一个BCLK的下降沿发送MSB。

 o Mode B - MSB is transmitted on rising edge of FRAME/SYNC.
   模式B  -  MSB在FRAME / SYNC的上升沿发送。
### 配置和使用 ALSA Machine DAI #### 了解Machine DAI的概念 ASoC (ALSA System on Chip) 是为了更好地支持嵌入式系统和应用于移动设备的音频 codec 而设计的一套软件体系。其核心组成部分之一就是Machine,负责连接Platform和Codec,并定义了具体硬件平台上的DAI(Digital Audio Interface)链接方式[^1]。 #### 定义DAI链路 在实际应用中,`dai-link`属性被用来描述CPU端口(CPU_DAI),编解码器端口(CODEC_DAI),以及它们之间的通信协议等信息。这些设置通常会在特定板级支持包中的`.c`文件里完成,比如`mt76xx_machine.c`文件就包含了关于机器及其DAI链的具体实现细节[^4]。 对于配置Machine DAI来说,主要涉及以下几个方面: - **指定Master/Slave角色**: 可通过DTB(Device Tree Blob)节点来设定哪个组件作为位时钟(bitclock)和帧同步(frame-sync)信号的主人(master)[^3]。 ```device-tree simple-audio-card,bitclock-master = <&master>; simple-audio-card,frame-master = <&master>; ``` - **创建并注册DAI链表项**: 这部分工作一般是在内核模块初始化过程中完成,在对应的machine驱动程序中编写相应的结构体实例化语句,并将其加入到系统的全局列表中去[^2]。 ```c static struct snd_soc_dai_link dai_links[] = { { .name = "my-dai", .stream_name = "My Stream Name", .cpu_dai_name = "snd-soc-dummy-dai", /* CPU侧 */ .codec_dai_name = "wm8960-hifi", /* Codec侧 */ ... }, }; static struct snd_soc_card soc_card = { .name = "My Sound Card", .owner = THIS_MODULE, .dai_link = dai_links, .num_links = ARRAY_SIZE(dai_links), ... }; module_snd_soc_card(soc_card); ``` 以上代码片段展示了如何在一个Linux内核模块中声明一个名为`my-dai`的新DAI接口,并指定了它的流名称、所关联的CPU与Codec两侧的实际物理实体名称。最后将此新创建的对象添加到了整个声音子系统的管理之下。 #### 使用Machine DAI 一旦上述配置完成后,应用程序就可以像操作其他任何标准ALSA PCM设备一样访问该DAI资源了。用户空间可以通过命令行工具如`aplay`播放音频文件至指定的声音卡;也可以利用编程API开发更复杂的应用场景下的音视频处理逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值