ALSA sound card NOTE 1---alsa drive frame

Source: Internet
Author: User
1. Sound card driver Sound.c

(1) The entry function registers the file_operations structure with the Register_chrdev () function.

(2) File_operations structure, there is only open function, there is no read and write function, we can see that the open function is the function of the transfer, will definitely find a new file_operations structure


(3) Call procedure

Save the secondary device number of the inode structure of the incoming node with the minor variable to take an entry in the struct array minor as subscript, so that the mptr pointer points to the item
The file_operations structure is taken out of the pointer of the MPTR structure body.
Call the Open function inside the file_operations struct


2. Who will set the snd_minors[] struct-body array

(1) Who will set the snd_minors[] struct-body array


The function has an array item outside the snd_minors, in order to Mdev or Udev can automatically create the device node, we have the class_create () function to create the class, the following create the device Device_create (), class in the Sound_ CORE.C entry function inside is created, SOUND.C entry function inside register character device function, Snd_register_device_for_dev () function inside create sound card logical device has device_create ()


(2) who called the Snd_register_device_for_dev () function (there are two calls)

All the way (Control interface of sound card device)

Another way (data interface for sound card devices)


The---First way of two-way analysis

3. First Call Analysis

(1) Snd_register_device () who is called (Core.h)


(2) Create the control interface function of the sound card device snd_ctl_dev_register () who is called (CONTROL.C)



(3) by the above known function snd_ctl_create () in the INIT.C program


is called in

(4) Creation of a snd_card structure by the knowable

Two-way analysis---the second way

4. Second Call analysis

(1) Create a data interface function for the sound card device Snd_pcm_dev_register () function is called by WHO (PCM.C)


(2) Create a new PCM device function _snd_pcm_new () by WHO call


(3) Snd_pcm_new () who was called

A driver for a sound card 5, code framework re-comb (1th way)

(1) Snd_card_create () function (INIT.C)


In addition to creating a snd_card struct, the Snd_ctl_create () is also called


This means that all sound cards must have a control interface.

(2) Creating a logical device for the control class Snd_ctl_create () function


Snd_device_new () function can be seen, for the same sound card, there may be more than one logical device, device should be the meaning of logical devices (control, PCM, etc.), the parameters sndrv_dev_control the category, the final Snd_ Ctl_dev_register () is called

(3) Snd_ctl_dev_register () function

The Snd_register_device () function inside registers a file_operations struct snd_ctl_f_ops


(4) Snd_register_device () function


(5) Snd_register_device_for_dev () function

Fill structure Array snd_minors[]


6. Code frame re-carding (2nd way)

(1) snd_pcm_new () call


(2) _snd_pcm_new () call (create play stream and record stream)


Create a logical device for the sound card that eventually causes the Snd_pcm_dev_register () function to be called


(3) Snd_pcm_dev_register () function


(4) Snd_pcm_f_ops structure array, No. 0 means play, 1th means recording, in PCM.C

7. Create a value for the name of the device node (1th way)

(1) the device_create () function in the Snd_register_device_for_dev () function, where "%s" originates from name, this name is Snd_register_device_for_dev () Parameters passed in by function



(2) the Snd_register_device_for_dev () function is called by the Snd_register_device () function, that is, the name parameter inside the Snd_register_device_for_dev () function is Snd_ Register_device () function passed over the


(3) The Snd_register_device () function is called by the Snd_ctl_dev_register () function, which can be seen by the name parameter according to the known Controlc%i,c card card, where I value from the right Cardnum , this cardnum is derived from the members of the Snd_card structure. And the Snd_card structure is derived from the snd_card structure of the snd_device structure body.


8. Create a value for the name of the device node (2nd way)

(1) the device_create () function in the Snd_register_device_for_dev () function, where "%s" originates from name, this name is Snd_register_device_for_dev () Parameters passed in by function



(2) the Snd_register_device_for_dev () function is called by the Snd_pcm_dev_register () function


The str parameter inside is exactly the name parameter, below has PCMC%ID%IP and pcmc%id%ic,c to indicate card's meaning,%i indicates which sound card, d indicates which one is under which logic device, p means play, C means recording


9, summary (how to write Alsa sound card driver)

(1) Constructs the Snd_card structure, snd_card_create () constructs the Snd_card structure and automatically creates the control interface. Call Function Snd_ctrl_create

(2) initialization, such as snd_pcm_new (), creating a logical device (playback device or recording device)

(3) Registration Snd_card_register

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.