https://blog.csdn.net/zyuanyun/article/details/59180272#t6
1.Card
For each soundcard, a “card” record must be allocated.
A card record is the headquarters of the soundcard. It manages the whole list of devices (components) on the soundcard, such as PCM, mixers, MIDI, synthesizer, and so on. Also, the card record holds the ID and the name strings of the card, manages the root of proc files, and controls the power-management states and hotplug disconnections. The component list on the card record is used to manage the correct release of resources at destruction.
Card是对声卡硬件的抽象。对于每一个声卡硬件,在alsa driver都对应一个Card record. Card管理声卡上的多个device。
我们可以通过cat /poc/asound/看到机器上的声卡。
2.Device
After the card is created, you can attach the components (devices) to the card instance. In an ALSA driver, a component is represented as a struct snd_device object. A component can be a PCM instance, a control interface, a raw MIDI interface, etc. Each such instance has one component entry.
每个device是一个snd_device 的结构体。device可以是PCM 实例,control interface (mixer),MIDI interface.
3.PCM
Each card device can have up to four pcm instances. A pcm instance corresponds to a pcm device file. The limitation of number of instances comes only from the available bit size of the Linux's device numbers. Once when 64bit device number is used, we'll have more pcm instances available.
A pcm instance consists of pcm playback and capture streams, and each pcm stream consists of one or more pcm substreams. Some soundcards support multiple playback functions. For example, emu10k1 has a PCM playback of 32 stereo substreams. In this case, at each open, a free substream is (usually) automatically chosen and opened. Meanwhile, when only one substream exists and it was already opened, the successful open will either block or error with EAGAIN
according to the file open mode. But you don't have to care about such details in your driver. The PCM middle layer will take care of such work.
个声卡最多可以包含4个pcm的实例,每个pcm实例对应一个pcm设备文件。pcm实例数量的这种限制源于linux设备号所占用的位大小,如果以后使用64位的设备号,我们将可以创建更多的pcm实例。
一个pcm实例由一个playback stream和一个capture stream组成,这两个stream又分别有一个或多个substreams组成。如果playback stream有多个substream, 那么说明声卡支持多路播放。如果只有一个substream, 如果已经有其他的app open了,说明pcm substream被占用,那么在open pcm时,那么open 会block 或者返回EAGAIN。
4. Runtime
When the PCM substream is opened, a PCM runtime instance is allocated and assigned to the substream. This pointer is accessible via substream->runtime
. This runtime pointer holds most information you need to control the PCM: the copy of hw_params and sw_params configurations, the buffer pointers, mmap records, spinlocks, etc.
每个substream都有一个runtime的实例。rutime这个结构体包含了一些control PCM的大部分信息,比如hw_params 和sw_params的配置,buffer pointer等等。