ALSA架构简介

2020-03-27 16:32

ALSA架构简介 收藏 一. 概述

ALSA是Advanced Linux Sound Architecture 的缩写,目前已经成为了linux的主流音频体系结构,想了解更多的关于ALSA的这一开源项目的信息和知识,请查看以下网址:http://www.alsa-project.org/。

在内核设备驱动层,ALSA提供了alsa-driver,同时在应用层,ALSA为我们提供了alsa-lib,应用程序只要调用alsa-lib提供的API,即可以完成对底层音频硬件的控制。

图 1.1 alsa的软件体系结构

由图1.1可以看出,用户空间的alsa-lib对应用程序提供统一的API接口,这样可以隐藏了驱动层的实现细节,简化了应用程序的实现难度。内核空间中,alsa-soc其实是对alsa-driver的进一步封装,他针对嵌入式设备提供了一些列增强的功能。本系列博文仅对嵌入式系统中的alsa-driver和alsa-soc进行讨论。

二. ALSA设备文件结构

我们从alsa在linux中的设备文件结构开始我们的alsa之旅. 看看我的电脑中的alsa驱动的设备文件结构:

$ cd /dev/snd

$ ls -l

crw-rw----+ 1 root audio 116, 8 2011-02-23 21:38 controlC0 crw-rw----+ 1 root audio 116, 4 2011-02-23 21:38 midiC0D0 crw-rw----+ 1 root audio 116, 7 2011-02-23 21:39 pcmC0D0c crw-rw----+ 1 root audio 116, 6 2011-02-23 21:56 pcmC0D0p crw-rw----+ 1 root audio 116, 5 2011-02-23 21:38 pcmC0D1p crw-rw----+ 1 root audio 116, 3 2011-02-23 21:38 seq crw-rw----+ 1 root audio 116, 2 2011-02-23 21:38 timer $

我们可以看到以下设备文件:

controlC0 --> 用于声卡的控制,例如通道选择,混音,麦克风的控制等 midiC0D0 --> 用于播放midi音频 pcmC0D0c --〉 用于录音的pcm设备 pcmC0D0p --〉 用于播放的pcm设备 seq --〉 音序器 timer --〉 定时器

其中,C0D0代表的是声卡0中的设备0,pcmC0D0c最后一个c代表capture,pcmC0D0p最后一个p代表playback,这些都是alsa-driver中的命名规则。从上面的列表可以看出,我的声卡下挂了6个设备,根据声卡的实际能力,驱动实际上可以挂上更多种类的设备,在include/sound/core.h中,定义了以下设备类型:

view plaincopy to clipboardprint?

#define SNDRV_DEV_TOPLEVEL ((__force snd_device_type_t) 0) #define SNDRV_DEV_CONTROL ((__force snd_device_type_t) 1) #define SNDRV_DEV_LOWLEVEL_PRE ((__force snd_device_type_t) 2)

#define SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000) #define SNDRV_DEV_PCM ((__force snd_device_type_t) 0x1001) #define SNDRV_DEV_RAWMIDI ((__force snd_device_type_t) 0x1002) #define SNDRV_DEV_TIMER ((__force snd_device_type_t) 0x1003) #define SNDRV_DEV_SEQUENCER ((__force snd_device_type_t) 0x1004) #define SNDRV_DEV_HWDEP ((__force snd_device_type_t) 0x1005) #define SNDRV_DEV_INFO ((__force snd_device_type_t) 0x1006) #define SNDRV_DEV_BUS ((__force snd_device_type_t) 0x1007) #define SNDRV_DEV_CODEC ((__force snd_device_type_t) 0x1008) #define SNDRV_DEV_JACK ((__force snd_device_type_t) 0x1009) #define SNDRV_DEV_LOWLEVEL ((__force snd_device_type_t) 0x2000) #define SNDRV_DEV_TOPLEVEL ((__force snd_device_type_t) 0) #define SNDRV_DEV_CONTROL ((__force snd_device_type_t) 1) #define SNDRV_DEV_LOWLEVEL_PRE ((__force snd_device_type_t) 2)

#define SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000)

#define SNDRV_DEV_PCM ((__force snd_device_type_t) 0x1001) #define SNDRV_DEV_RAWMIDI ((__force snd_device_type_t) 0x1002) #define SNDRV_DEV_TIMER ((__force snd_device_type_t) 0x1003) #define SNDRV_DEV_SEQUENCER ((__force snd_device_type_t) 0x1004) #define SNDRV_DEV_HWDEP ((__force snd_device_type_t) 0x1005) #define SNDRV_DEV_INFO ((__force snd_device_type_t) 0x1006) #define SNDRV_DEV_BUS ((__force snd_device_type_t) 0x1007) #define SNDRV_DEV_CODEC ((__force snd_device_type_t) 0x1008) #define SNDRV_DEV_JACK ((__force snd_device_type_t) 0x1009) #define SNDRV_DEV_LOWLEVEL ((__force snd_device_type_t) 0x2000)

通常,我们更关心的是pcm和control这两种设备。

三. 驱动的代码文件结构

在Linux2.6代码树中,Alsa的代码文件结构如下:

sound

/core

/oss /seq /ioctl32 /include /drivers /i2c /synth

/emux /pci

/(cards) /isa

/(cards) /arm /ppc /sparc /usb

/pcmcia /(cards) /oss /soc

/codecs

core 该目录包含了ALSA驱动的中间层,它是整个ALSA驱动的核心部分 core/oss 包含模拟旧的OSS架构的PCM和Mixer模块 core/seq 有关音序器相关的代码

include ALSA驱动的公共头文件目录,该目录的头文件需要导出给用户空间的应用程序使用,通常,驱动模块私有的头文件不应放置在这里

drivers 放置一些与CPU、BUS架构无关的公用代码 i2c ALSA自己的I2C控制代码

pci pci声卡的顶层目录,子目录包含各种pci声卡的代码 isa isa声卡的顶层目录,子目录包含各种isa声卡的代码 soc 针对system-on-chip体系的中间层代码 soc/codecs 针对soc体系的各种codec的代码,与平台无关

本文来自CSDN博客,转载请标http://blog.csdn.net/DroidPhone/archive/2011/03/23/6271122.aspx

声卡的创建

1. struct snd_card

1.1. snd_card是什么

snd_card可以说是整个ALSA音频驱动最顶层的一个结构,整个声卡的软件逻辑结构开始于该结构,几乎所有与声音相关的逻辑设备都是在snd_card的管理之下,声卡驱动的第一个动作通常就是创建一个snd_card结构体。正因为如此,本节中,我们也从 struct cnd_card开始吧。

1.2. snd_card的定义

snd_card的定义位于改头文件中:include/sound/core.h

view plaincopy to clipboardprint? /* main structure for soundcard */

struct snd_card {

int number; /* number of soundcard (index to snd_cards) */

char id[16]; /* id string of this card */ char driver[16]; /* driver name */

char shortname[32]; /* short name of this soundcard */ char longname[80]; /* name of this soundcard */ char mixername[80]; /* mixer name */

char components[128]; /* card components delimited with space */

struct module *module; /* top-level module */

void *private_data; /* private data for soundcard */

void (*private_free) (struct snd_card *card); /* callback for freeing of private data */ struct list_head devices; /* devices */

unsigned int last_numid; /* last used numeric ID */

struct rw_semaphore controls_rwsem; /* controls list lock */ rwlock_t ctl_files_rwlock; /* ctl_files list lock */ int controls_count; /* count of all controls */ int user_ctl_count; /* count of all user controls */ struct list_head controls; /* all controls for this card */ struct list_head ctl_files; /* active control files */

struct snd_info_entry *proc_root; /* root for soundcard specific files */ struct snd_info_entry *proc_id; /* the card id */

struct proc_dir_entry *proc_root_link; /* number link to real id */

struct list_head files_list; /* all files associated to this card */

struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown state */

spinlock_t files_lock; /* lock the files for this card */ int shutdown; /* this card is going down */

int free_on_last_close; /* free in context of file_release */ wait_queue_head_t shutdown_sleep;

struct device *dev; /* device assigned to this card */ #ifndef CONFIG_SYSFS_DEPRECATED

struct device *card_dev; /* cardX object for sysfs */ #endif

#ifdef CONFIG_PM

unsigned int power_state; /* power state */ struct mutex power_lock; /* power lock */ wait_queue_head_t power_sleep; #endif

#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) struct snd_mixer_oss *mixer_oss; int mixer_oss_change_count; #endif };

/* main structure for soundcard */

struct snd_card { int number; /* number of soundcard (index to snd_cards) */ char id[16]; /* id string of this card */ char driver[16]; /* driver name */ char shortname[32]; /* short name of this soundcard */


ALSA架构简介.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:县新型农村社会养老保险试点特见成效工作汇报[可编辑版]

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: