ALSA and TinyAlsa

57 篇文章 0 订阅

http://blog.csdn.net/myzhzygh/article/details/8468210

分类: Android 919人阅读 评论(0) 收藏 举报

Copyright:http://blog.csdn.net/myzhzygh/article/details/8468210

Alsa

Introduction

The Advanced Linux Sound Architecture(ALSA) is a Linux kernel component intended to replace the original OpenSound System (OSSv3) for providing device drivers for sound cards. Besides thesound device drivers,ALSA also bundles a user space library forapplication developers who want to use driver features with a higher level APIthan direct interaction with the kernel drivers. In a word, the Advanced LinuxSound Architecture (ALSA) comes with a kernel API and a library API.

ALSA Features

ALSA was designed to use some featureswhich were not, at the time of its conception, supported by theOpen SoundSystem (OSS):

ALSA has a larger and more complex API than OSS, so it can be harder to develop anapplication that uses ALSA as its sound technology. While ALSA may beconfigured to provide an OSSemulation layer, such functionality is no longer available in many Linuxdistributions.

Besides the sound device drivers, ALSAbundles a user spacelibrary for application developers whowant to use driver features through an interface that is higher level than the interface provided fordirect interaction with the kernel drivers; unlike the kernel API, which triesto reflect the capabilities of the hardware directly, ALSA's user space librarypresents an abstraction which remains as standardized as possible acrossdisparate underlying hardware. This goal is achieved in part by using softwareplugins. For example, many modern soundcards or built-in sound chips don't havea "master volume" control; for these devices, the user space libraryinstead provides a software volume control using the "softvol"plugin, and ordinary application software need not care whether such a controlis implemented by actual underlying hardware or software emulation of suchunderlying hardware.

ALSA Concepts

This section provides an overview of basicconcepts pertaining to ALSA.

Typically, ALSA supports up to eight cards,numbered 0 through 7; each card is a physical or logical kernel device capableof input, output, or control of sound, and card number 0 is used by defaultwhen no particular card is specified. Furthermore, each card may also beaddressed by its id, which is an explanatory string such as "Headset"or "ICH9".

A card has devices, numberedstarting at 0; a device may be of playback type, meaning it outputssound from the computer, or some other type such ascapture,control,timer, orsequencer; device number 0 is used by default when noparticular device is specified.

A device may have subdevices,numbered starting at 0; a subdevice represents some relevant sound endpoint forthe device, such as a speaker pair. If the subdevice is not specified, or ifsubdevice number -1 is specified, then any available subdevice is used.

A card's interface is a descriptionof an ALSA protocol for accessing the card; possible interfaces include:hw,plughw,default, andplug:dmix. Thehw interfaceprovides direct access to the kernel device, but no software mixing or streamadaptation support. Theplughw anddefault enable sound outputwhere thehw interface would produce an error.

An application typically describes soundoutput by combining all of the aforementioned specifications together in adevicestring, which has one of the following forms (which arecasesensitive):

  • interface:card,device,subdevice
  • interface:CARD=1,DEV=3,SUBDEV=2.

An ALSA stream is a data flowrepresenting sound; the most common stream format isPCM that must be produced in such a way asto match the characteristics or parameters of the hardware, including:

  • sampling rate: 44.1 kHz on home stereos, and 48 kHz on home theaters
  • sample width: measured in some number of bits per sample (such as 8, 16, 24, or 32 bits/sample)
  • sample encoding
  • number of channels: 1 for mono, 2 for stereo, or 6 for AC-3/IEC958

Also, ALSA needs a buffer parameter thatdetermines how often CPU attention is required to supply sound data.

ALSA Kernel Modules

  • snd_hda_codec_hdmi
  • snd_hda_codec_via
  • snd_hda_intel
  • snd_hda_codec         
  • snd_hwdep
  • snd_pcm
  • snd_timer
  • snd
  • snd_page_alloc

ALSA Interfaces

The currently designed interfaces arelisted below:

  1. Information Interface (/proc/asound)
  2. Control Interface (/dev/snd/controlCX)
  3. Mixer Interface (/dev/snd/mixerCXDX)
  4. PCM Interface (/dev/snd/pcmCXDX)
  5. Raw MIDI Interface (/dev/snd/midiCXDX)
  6. Sequencer Interface (/dev/snd/seq)
  7. Timer Interface (/dev/snd/timer)

For the VIA EITX-3002, you might also wantto check the directory /dev/snd for the right device files:

  1. controlC0
  2. hwC0D0
  3. pcmC0D0p
  4. pcmC0D0c
  5. timer

ALSA API usage

The ALSA library API is the interface tothe ALSA drivers. Developers need to use the functions in this API to achievenative ALSA support for their applications, instead of kernel API. How itinterfaces with the kernel API is focused by the library API. Applicationprogrammers should use the library API rather than the kernel API. The libraryoffers 100% of the functionality of the kernel API, but adds major improvementsin usability, making the application code simpler and better looking. Inaddition, future fixes or compatibility code may be placed in the library codeinstead of the kernel driver.

ALSA API links

Tinyalsa

Introduction

Tinyalsa is a small library to interface withALSA in the Linux kernel.

Tinyalsa basic files list:

-         pcm.c                           for control interface

-         mixer.c                         for pcminterface

, and provide three tools:

-         tinyplay.c                    for play

-         tinycap.c                     for capture

-         tinymixer.c                 for mixer

Tinyalsa Aims

Tinyalsa is a small ALSA library, in orderto substituting for original ALSA library in Android platform. 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

Tinyalsa Functions

Provide a basic pcm and mixer API toimplement the Audio HAL (Hardware Abstract Level) for Android platform.

Tinyalsa vs. ALSA-lib

 

Tinyalsa

ALSA-lib

Control Interface

Partly support

Completely support

Mixer Interface

----

Completely support

PCM Interface

Partly support                            

Completely support                                 

Raw MIDI Interface

----

Completely support

Sequencer Interface                        

----

Completely support

Timer Interface

----

Completely support

Why use Tinyalsa

We can use ALSA-lib substitute for Tinyalsacompletely, but we can’t use Tinyalsa substitute for ALSA-lib completely. But,in some times, Tinyalsa can substitute for ALSA-lib to work for some basicfunction.

  • The only reason is that it is smaller and simpler than ALSA-lib.
  • Google Android supplies the Tinyalsa.
  • Audio HAL interface forms changed in Android 4.0.

Tinyalsa API Limitations

Notice: The following function Interfacesupplied by tinyalsa is not implemented.

/* Set and get config */

int pcm_get_config(structpcm *pcm, struct pcm_config *config);

int pcm_set_config(struct pcm *pcm, struct pcm_config *config);

/* Returns the pcm latency in ms */

unsigned int pcm_get_latency(struct pcm *pcm);

Reference:

http://www.alsa-project.org/main/index.php/Main_Page

http://en.wikipedia.org/wiki/Advanced_Linux_Sound_Architecture

https://wiki.archlinux.org/index.php/Advanced_Linux_Sound_Architecture

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值