左手tiny(alsa),右手Asoc,浅谈android对ALSA的继承和发扬

android 内核是linux,对alsa使用的时候又增加了自己的扩展,这里主要就是tinyalsa和ASoc两个利器:

对于tinyalsa,其实我一直比较糊涂它干嘛用的,那先看一下github上的介绍

TinyALSA is a small library to interface with ALSA in the Linux kernel.

The aims are:

    Provide a basic pcm and mixer API.
    If it's not absolutely needed, don't add it to the API.
    Avoid supporting complex and unnecessary operations, that could be dealt with at a higher level.
    Provide comprehensive documentation.

从这里看上去TinyAlsa就是为了方便用户而简化了很多复杂的音频驱动操作,为用户实现了很基础的API。据说tinyalsa是Google在Android 4.0之后推的基于alsa内核的用户层音频接口。在Android 4.0之前还一直是使用这alsa-lib接口。Google之所以推出tinyalsa,有网友认为有alsa使用了GPL许可证的缘故,也有可能是因为alsa-lib的库过于复杂繁琐大部分功能在Android平台没有实际实用意义却依然占用屈指可数的内存空间。不过目前看上去你也可以直接将tinyalsa安装在你的linux系统里,因为同时tinyalsa还为用户提供了几个简单的音频小工具,/tinyplay// tinycap/ tinymix/ tinypcminfo/ libtinyalsa-pcm/libtinyalsa-mixer,有兴趣可以看看源码他们是怎么工作的。用户可以利用Android里面tinyalsa提供的这些个小工具,控制管理手机的音频通路,利用工具进行查看、调试。

然而,其实大部分时间没什么具体用处。我总觉得tinyalsa像个玩具,我做的是vendor底层的,也许作应用层的对此工具更有发言权,但网上也找不到更多扩展使用tinyalsa的例子和方案。

ASoC(ALSA System on Chip)是android为了更好的支持嵌入式CPU,在标准linux的ALSA驱动上建立了嵌入式音频架构,如果想搞懂这个,就得从linux的声卡和声卡驱动说起。不过第一手的资料可以从https://www.alsa-project.org/main/index.php/ASoC获得。
首先看看这个项目的目标:

The overall project goal of the ALSA System on Chip (ASoC) layer is to provide better ALSA support for embedded system on chip procesors
 (e.g. pxa2xx, au1x00, iMX, etc) and portable audio codecs. Currently there is some support in the kernel for SoC audio

项目本身还有不完善的地方

however it has some limitations:

   Currently, codec drivers are often tightly coupled to the underlying SoC cpu. This is not really ideal and leads to code duplication i.e. Linux now has 4 different wm8731 drivers for 4 different SoC platforms.
   There is no standard method to signal user initiated audio events. e.g. Headphone/Mic insertion, Headphone/Mic detection after an insertion event. These are quite common events on portable devices and often require machine specific code to re route audio, enable amps etc after such an event.
   Current drivers tend to power up the entire codec when playing (or recording) audio. This is fine for a PC, but tends to waste a lot of power on portable devices. There is also no support for saving power via changing codec oversampling rates, bias currents, etc.

ASoC is currently still work in progress with most features implemented and support for the PXA2xx, AT91xx and S3C24xx SoCs now in the mainline kernel.

设计初衷

The ASoC layer is designed to address these issues and provide the following features:

    Codec independence. Allows reuse of codec drivers on other platforms and machines.
    Easy I2S/PCM audio interface setup between codec and SoC. Each SoC interface and codec registers it's audio interface capabilities with the core and are subsequently matched and configured when the application hw params are known.
    Dynamic Audio Power Management (DAPM). DAPM automatically sets the codec to it's minimum power state at all times. This includes powering up/down internal power blocks depending on the internal codec audio routing and any active streams.
    Pop and click reduction. Pops and clicks can be reduced by powering the codec up/down in the correct sequence (including using digital mute). ASoC signals the codec when to change power states.
    Machine specific controls: Allow machines to add controls to the sound card. e.g. volume control for speaker amp.


因此,ASoc将嵌入式的音频分成三个部件

ASoC basically splits an embedded audio system into 3 components:

    Codec driver: The codec driver is platform independent and contains audio controls, audio interface capabilities, codec dapm definition and codec IO functions.
    Platform driver: The platform driver contains the audio dma engine and audio interface drivers (e.g. I2S, AC97, PCM) for that platform.
    Machine driver: The machine driver handles any machine specific controls and audio events. i.e. turning on an amp at start of playback.

从这三个部件的定义,codec驱动的目的要做到平台无关,实现audio控制、audio接口能力、codec 动态audio功率控制和codec IO四大功能。platform驱动包含audio dma控制和audio接口的驱动。machine驱动处理设备相关的控制和audio事件,如:在播放的时候打开放大器。

阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Android凭借其开源,良好的用户体验,高性价比,庞大的应用程序等优势迅速发展起来并保持强劲的发展势头。如今Android智能手机、Android平板电脑等移动产品已走入人们的日常生活,成为人们通讯、娱乐的重要工具。本设计以malata采用RK2918方案的Android平板电脑项目为背景,主要任务是设计和实现Android平板电脑的音频系统,为广大平板用户提供良好的音频体验。 ALSA(Advanced Linux Sound Architecture,高级Linux声音架构)在Linux操作系统上提供了音频和MIDI(Musical Instrument Digital Interface,音乐设备数字化接口)的支持。它的主要特性包括:高效地支持从消费类入门级声卡到专业级音频设备所有类型的音频接口,完全模块化的设计,支持对称多处理和线程安全,对OSS(Open Sound System,开放声音系统)的向后兼容,以及提供了用户空间的alsa-lib库来简化应用程序的开发[1]。基于ALSA的音频系统能够很好的适应硬件的多样性,因此Android设备厂商能够更灵活地根据不同需求选择不同的音频编解码芯片。ALC5625是一款高度集成低功耗高保真的带I2S/PCM接口并具有多路输入输出的音频编解码器,可满足本次设计的各项需求。 基于ALSA的Andorid音频系统拥有一个标准和健全的架构,自上而下由Audio应用程序、Audio Java框架层、Audio本地框架层、AudioFlinger、Audio硬件抽象层、alsa-lib和底层Audio驱动几个部分组成。本文分析音频系统架构的各个层次,并着重阐述ALSAAndroid音频系统中的应用以及Audio驱动的详细实现。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西岸行者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值