# Linux Audio - ALSA [TOC] ## Abstractions and Hierarchy [ALSA arranges hardware audio devices and their components into a hierarchy of cards, devices and subdevices](https://www.volkerschatz.com/noise/alsa.html). See [ALSA, exposed!](https://rendaw.gitlab.io/blog/2125f09a85f2.html#alsa-exposed) for terminologies. ## Special Files See [ALSA Library API](https://www.alsa-project.org/wiki/ALSA_Library_API) on ALSA Wiki `/proc/asound` directories contain information of a sound card. This is usually created by the [`snd_card_init()`](https://elixir.bootlin.com/linux/latest/source/sound/core/init.c#L276) in the [`snd_card_new()`](https://elixir.bootlin.com/linux/latest/source/sound/core/init.c#L202) or [`snd_devm_card_new()`](https://elixir.bootlin.com/linux/latest/source/sound/core/init.c#L156) during probe. ### `/proc/asound/cards` - List of sound cards ``` $ cat /proc/asound/cards ``` 1. ID of the sound card 2. Name of the driver 3. Short name of the card 4. Long name of the card Those various names can calso be found in members of the [`struct snd_card`](https://elixir.bootlin.com/linux/latest/source/include/sound/core.h#L80) in the `include/sound/core.h`: ```c 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 irq_descr[32]; /* Interrupt description */ char mixername[80]; /* mixer name */ char components[128]; /* card components delimited with space */ ... } ``` For example, the Intel HDA driver [`sound/pci/hda/hda_intel.c`](https://elixir.bootlin.com/linux/latest/source/sound/pci/hda/hda_intel.c#L2024) ```c ... strcpy(card->driver, "HDA-Intel"); strscpy(card->shortname, driver_short_names[chip->driver_type], sizeof(card->shortname)); snprintf(card->longname, sizeof(card->longname), "%s at 0x%lx irq %i", card->shortname, bus->addr, bus->irq); ... ``` Those names are usually set in the `probe()` function for a driver, after a `struct snd_card` has been instantiated. For some devices using the ASoC framework (for example, the Sound Open Firmware, see its [description](https://elixir.bootlin.com/linux/latest/source/sound/soc/sof/Kconfig#L2) in kconfig), the `struct snd_card` is wrapped in the [`struct snd_soc_card`](https://elixir.bootlin.com/linux/latest/source/include/sound/soc.h#L927), and the names are initialized in the [`snd_soc_bind_card()`](https://elixir.bootlin.com/linux/latest/source/sound/soc/soc-core.c#L2149) of the `sound/soc/soc-core.c`: ```c ... snd_soc_set_dmi_name(card, NULL); soc_setup_card_name(card, card->snd_card->shortname, card->name, NULL); soc_setup_card_name(card, card->snd_card->longname, card->long_name, card->name); soc_setup_card_name(card, card->snd_card->driver, card->driver_name, card->name); ... ``` `devm_snd_soc_register_card()` then `snd_soc_register_card()` then `snd_soc_bind_card()` ## Command Line Tools ## Configuration Files ## References