How to Use ALSA to drive sound card in Linux

Source: Internet
Author: User
Tags dmesg
Article Title: Detailed description of how to use ALSA to drive the sound card in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

 1. What is ALSA;

Advanced Linux Sound Architecture is short for "ALSA", which means the Linux Advanced Sound system (which is literally translated and may not be translated). When it comes to the system, it will be too broad, therefore, ALSA not only supports and drives sound cards;

ALSA has the following features:

Code:

1. efficient support for all audio interfaces, from sound cards of common users to Professional-level multi-channel audio devices;

2. Sound Card drive is completely modular design;

3. SMP and thread-safe design.

4. The Development Library (alsa-lib) provides simple and convenient programming, and has advanced effects and functions;

5. Support the old version of oss api interface to provide compatibility for most OSS applications. OSS is a commercial driver. OSS has a simple installation Code that has been moved into the kernel and ALSA, among them, alsa-oss is: OSS companies are said to be no longer there; we do not need to use the commercial version provided by OSS companies; ALSA and OSS lite versions are enough;

2. Basic information about hardware driver;

1. How to view the hardware chip;

In Linux, all hardware is differentiated by chipset, and the brand is not the most important. The most important identifier of hardware is the chipset. So when you ask for help in the discussion board, if you only use the hardware brand, but do not provide the chipset, you will not be able to help you. Remember;

We can check whether the command of the hardware chipset is lspci-v or dmesg. Because dmesg does not output much information, it is not intuitive enough. Therefore, it is often used lspci-v; it can also be obtained using lshal; lspci-v is the most convenient; lspci-v is better for beginners;

Code:
[Root @ localhost beinan] # lspci-v

After we run lspci-v, if we view the sound card chipset, we will find a section similar to the following;

Code:
[Root @ localhost beinan] # lspci-v

Multimedia audio controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M)
Ac'97 Audio Controller (rev 03)
Subsystem: Hewlett-Packard Company: Unknown device 3080
Flags: bus master, medium devsel, latency 0, IRQ 5
I/O ports at 1c00 size = 256
I/O ports at 18c0 size = 64
Memory at e0100c00 (32-bits, non-prefetchable) size = 512
Memory at e0100800 (32-bit, non-prefetchable) size = 256
Capabilities: [50] Power Management version 2

2. system kernel version;

Code:
[Root @ localhost beinan] # uname-r-m-p-I
2.6.11-1.1369 _ FC4 i686 i686 i386

The above indicates the kernel version and processor architecture of the system;

Tip: If you compile the kernel by yourself, you also need to install kernel-devel (or kernel-source), which is included in the System disc or image file. If you want to download the kernel by yourself using kernel.org, compile it by yourself, and then drive the sound card. You can also download the latest kernel source code from kernel.org;

Generally, if the system's default kernel does not support sound card driver, we recommend that you upgrade the kernel and source code from the upgrade package provided by the release; for example, the ora Extension Project software package is updated extremely fast. We can use apt and yum to upgrade the kernel. We do not recommend that you delete the old kernel when enabling the new kernel; at present, because apt ora/Redhat introduces apt and yum update tools, the system integrity is extremely important; if the system is damaged, it becomes extremely difficult to use the update tool;

For example, if the source upgrade kernel of apt and yum of Fedora cannot solve your problem, we may need to download and compile the kernel through kernel.org; however, the previous kernel packages and source code packages cannot be deleted either. First, for security purposes, we did not succeed in compiling the kernel by ourselves. In addition, the built-in kernel and source code of the system are many software dependencies of the system; apt and yum should check the system integrity every time they update the software package;

For some releases, you can directly download the latest kernel from kernel.org. If you compile the kernel source code (kernel-devel or kernel-source) provided by the system, your problem may not be solved;

3. modprobe. conf content;

In Fedora Core 4.0, the kernel module alias is added or defined in/etc/modprobe. conf file; in other versions, it may be modules. conf; if your system contains modprobe. conf. This file is used as the standard. Different releases have different definition files. For example, slackware is defined in/etc/modules. conf, but also in/etc/rc. d/rc. enable the relevant driver module;

Modprobe. conf or module. conf is to configure the modules that have been loaded by the system, such as setting aliases. These are generally automatically generated by tools. You can also view hardware documents and sites, you can also add one by yourself. Why not add it like that? I don't understand either, because I won't develop what people say in that document. If I understand development, I may understand it. Please understand me;

For example, I am using a 855 motherboard, the system driver is using a snd-intel8x0, in/etc/modprobe. the configuration of conf is as follows. The following content is automatically generated using the alsaconf Configuration tool;

Code:
Alias snd-card-0 snd-intel8x0
Options snd-card-0 index = 0
Options snd-intel8x0 index = 0
Remove snd-intel8x0 {/usr/sbin/alsactl store 0>/dev/null 2> & 1 | |:;};/sbin/modprobe-r -- ignore-remove snd-intel8x0

4. lsmod check the loaded kernel module;

If a device is loaded as a module in kernel compilation, it is mainly viewed through lsmod;

Code:
[Root @ localhost beinan] # lsmod

Some new Linux beginners may ask if we can manually load the module where the kernel module is stored. The kernel module is stored in/lib/modules/kernel version/kernel /, for example, in Fedora 4.0, we can see the following:

Code:
[Root @ localhost beinan] # ls/lib/modules/2.6.11-1.1369 _ FC4/kernel/
Arch/crypto/drivers/fs/lib/net/sound/among them, sound is the directory where the sound card module is stored, most hardware drivers are placed in the drivers directory, and fs is the directory of the file system module; net is the storage directory related to the network, such as some modules supported by the network protocol and firewall; arch is the cpu ......

If we want to load modules by ourselves, we can view the information of the corresponding modules in these directories, and then use modprobe to load them;

Code:
[Root @ localhost beinan] # modinfo snd-intel8x0

View the information of a module. We can use modinfo to view the information of the module. do not include. ko or. o. For example, we can view information similar to the following;

Description: Intel 82801AA, 82901AB, i810, i820, i830, i840, i845, MX440; SiS 7012; Ali 5455

We can see that this is an Intel integrated sound card. The sound card information obtained through lspci-v is very similar, so we can try this module to drive it;

Code:
[Root @ localhost beinan] # modprobe snd-intel8x0

I loaded the module with modprobe, and then we can see it through lsmod; for sound card modules, the driver modules of other devices are also like this;

Note: [/B] [/size] only provides you with some basic knowledge. If you have any problems, you can find out how to solve them, lsmod and/etc/modprobe must be input. conf or modules. post the conf content. This will save a lot of time, otherwise you will not understand where the problem is;

3. Do I need to upgrade the kernel for the sound card of my system;

There may be such a situation. For example, sometimes when I am in Mandriva Linux, the sound card has sound, but after I have installed the Fedora system, there is no sound. Therefore, we need to figure out the following issues; the sound card may have been driven, but we do not know much about the cause of the system. The following uses Fedora as an example;

1. Is the sound card recognized and supported by the system;

We can use the Configuration Tool system-config-soundcard provided by Fedora for testing;

Code:
[Beinan @ localhost ~] # System-config-soundcard

Through the test, if you can hear the sound, it indicates that the sound card has been driven; if you cannot hear the sound, but the response is not slow, instead of opening system-config-soundcard, A false alarm occurs when playing a test sound. It may be that the sound volume is not enabled;

2. Whether to enable the sound card volume, such as PCM and MASTER;

We can use the following tools;

Code:
[Beinan @ localhost ~] # Gnome-volume-control
[Beinan @ localhost ~] # Kmix
[Beinan @ localhost ~] # Alsamixer
[Beinan @ localhost ~] # Aumix

You can try the four tools above. Sometimes these tools have bugs. So we need to introduce aumix, which has been deleted by Fedora; we can install it on our own;

3. My sound card has sound during testing, but why can't I play CD and mp3?

Since Redhat 8.0, that is, Redhat 9.0, Fedora 1.0, Fedora 2.0, Fedora 3.0, and Fedora 4.0 do not support mp3 any more. The reason is the copyright; however, this does not mean that we cannot enable the Player software to support mp3 in the Fedora system; we can install mp3 support patches or download a brand new player; and all this is inseparable from the online Installation Tool apt or yum;

As to why the CD cannot be played, I have already mentioned it on the forum for many times. First, ensure that the CDROM audio line is connected to the motherboard. Some may ask why it can be played directly on Windows, I didn't connect the CDROM audio cable to the motherboard either. I replied to you: we have to change our mindset. We are using Linux, not Windows;

4. check whether there are module conflicts with the sound card;

For example, the Intel motherboard integrated cat and sound card, Nic, etc., then the cat may be the system recognized as the sound card, so through lsmod to check whether there is a snd-intel8x0m; if there is to deal with it; rename the snd-intel8x0m.ko in/lib/modules/kernel version/kernel/sound/pci or/lib/modules/kernel version/kernel/drviers/sound/pci to the snd-intel8x0m.koBAK;

There are similar motherboard, such as VIA motherboard integrated sound card and CAT, if sound card does not sound, mostly also related to this, such as the kernel module has snd-via82xx.ko and snd-via82xx-modem.ko, the system may regard the snd-via82xx-modem.ko module as the driver of the sound card. If this happens, change the name;

5. Use alsaconf to configure the sound card;

In general, the sound card is automatically configured when the system is installed. If you can identify anything else, there is basically no problem; but if you identify it, you still do not speak out; or identify it as a cat's buzzer; so we need to re-run the sound card configuration tool alsaconf in addition to renaming the previously mentioned Cat's buzzer module; maybe we need a bit of previous knowledge, for example, modprobe and lsmod. If necessary, start a new machine;

What if I don't have the alsaconf command?

Code:
[Root @ localhost beinan] #/usr/sbin/alsaconf

For example, in Fedora Core 4.0, you may not be able to find this command; you can only re-compile alsa-utils, but you must also compile it conservatively; you cannot delete all packages related to alsa. You can only select the corresponding version for compilation. The current Fedora is upgraded through yum and apt. It is important to remove the packages on which the system depends, alsa is one of them. It will make some programs unavailable. Because of version ing, we cannot break the overall dependency of the system. Of course it doesn't matter, for example, this package depends on other packages, and this package does not provide dependent packages for other packages. Such packages can be removed;

You can compile alsa-utils by yourself:

First, confirm the alsa software package version;

Code:
[Root @ localhost alsa] # rpm-qa | grep alsa
Alsa-utils-1.0.9rf-2.FC4
Alsa-lib-1.0.9rf-2.FC4
Alsa-tools-1.0.9-1.fc4

We want to go to the alsa-project.org to download 1.0.9 source package; mainly download alsa-lib-1.0.9 and alsa-utils-1.0.9a; Do not uninstall the original RPM package; first install the alsa-lib-1.0.9, and then install the alsa-utils-1.0.9a; the compilation method is only tar zxvf file.tar.gz or tar jxvf file.tar.bz2, and then enter the corresponding decompressed directory. /configure; make install;

Of course, you need to install development tools, development libraries, etc. If you cannot install alsa in the source code package, we need to install the software missing by the system; see Fedora/Redhat package management guide

In this way, the alsaconf tool is available, and compiling alsa will not cause damage to the system;

++ ++
Intercept: I'm exhausted. I tried all the above, but I still cannot drive the sound card. What should I do?
++ ++

If you have understood the above content, I would like to congratulate you on your understanding of the hardware driver method. Although the Sound Card problem has not been solved, however, it is not difficult for you to grasp the basic necessary knowledge to solve the sound card voice;

You can see that this is already very exhausting. Well, I am tired of writing it here. But for beginners to hear music in Linux, I have to work hard until I solve your problem;

4. Install the new ALSA version;

1. Description of ALSA software package;

Through the above series of projects, you may find that you still cannot solve your problem, then we need to upgrade ALSA; as to whether to upgrade the kernel, we have to wait for this step to see if it is necessary; for example, in Fedora 4.0, when we query through rpm-qa | grep alsa, we will find that there is no alsa-driver package. What is the problem?

Code:
[Root @ localhost alsa] # rpm-qa | grep alsa
Alsa-utils-1.0.9rf-2.FC4
Alsa-lib-1.0.9rf-2.FC4

Now a description of ALSA-related software packages (listed on the alsa-project.org );

When alsa-lib is an alsa-driver or alsa package, you must first install this package;

The alsa-driver is the driver of the audio device. Generally, the kernel is integrated into it, mostly in the module mode, installed in/lib/modules/kernel version/kernel/sound or/lib/modules/kernel version/kernel/drviers/sound; this is true for each version of the kernel. This is why we did not find alsa-driver in Fedora Core 4.0. If we compile and upgrade alsa by ourselves, among them, alsa-driver is also installed in/lib/modules/kernel version/kernel/sound or/lib/modules/kernel version/kernel/drviers/sound; see it;

Alsa-utils is mainly used for sound card configuration tools, such as alsaconf and alsamixer;

The alsa-oss package is the same as the alsa-driver package and does not appear in the Fedora Core 4.0 as an independent package. The reason is that like the alsa-driver, it is integrated into the kernel, this package is extremely necessary; if we upgrade ALSA, some sound cards cannot be driven by ALSA, but alsa-oss must be used; alsa-oss includes the oss driver library; alsa-oss, which is usually installed in the/usr directory by default;

Alsa-tools is an additional toolkit, not required. It is a tool or decoder for some special sound cards. You can install it based on your own sound card;

Other packages won't talk about it, go to the alsa-project.org to see it; more important is alsa-lib, alsa-driver, alsa-utils, alsa-oss;

2. Prepare for compilation and installation of ALSA;

Compile and install alsaand compile the environment. Just like we open a file.doc file in windows, we need to install the Word first. Is this true for Linux? Install the tools required for compiling the software package first, and install kerenel-devel or some other supported libraries. If you do not install these tools, the compilation will fail; in this way, all development tools are in the system installation disk. If you do not know how to install them, for Fedora/Redhat, see Fedora/Redhat package management guide.

You also need to upgrade the kernel and the kernel source code package online. Taking Fedora 4.0 as an example, ensure that the kernel and the kernel-devel package are in the same version. You may see a lot of kernel packages, what else is smp? If you only use a single processor, do not use smp; view the graph job (click to see the big picture, when upgrading the kernel, select the kernel and source code upgrade corresponding to the color marked in the figure, that is, the version must match)

  

Important: upgrading the kernel online may solve the problem of your sound card. Try to solve it with the aforementioned solution. You can also upgrade alsa-lib online; alsa-tools; alsa-utils and other packages;

If you can solve your problem by upgrading the kernel and alsa-lib; alsa-utils; alsa-tools online, do not read the following content;

Why is it solved through online long-term nuclear energy? Because of kernel upgrade, the built-in alsa-driver of the kernel package may also be upgraded. If the package person upgrades alsa-driver, it indicates that alsa-driver is an old version. It plays an important role in alsa-driver. If alsa-lib does not have a new version during online upgrade, certainly the alsa-driver in the new kernel is not updated, because they are compatible; understand it;

Determine whether it is necessary to re-compile the kernel:

Code:
[Root @ localhost beinan] # modinfo soundcore
Filename:/lib/modules/BRL. 11-1.1369 _ FC4/kernel/soundBAK/soundcore. ko
Description: Core sound module
Author: Alan Cox
License: GPL
Alias: char-major-14 -*
Vermagic: 2.6.11-1.1369 _ FC4 686 REGParm 4 KSTACKS gcc-4.0
Depends:
Srcversion: E11490DC3F523551C4C2A6D

If the above information is similar, you do not need to compile the kernel;

One of the misunderstandings: I have seen many of my friends on the Forum and I think that if I upgrade alsa-lib, alsa-utils, or alsa-tools online, the sound card will not sound. This is actually not the case; because the key is the kernel, and the audio card driver in the kernel is also from alsa-driver, we need to try to upgrade alsa-driver to solve the problem, how can I upgrade alsa-lib and alsa-utils only? The driver of the sound card is not updated; sometimes the upgrade of alsa-lib and alsa-utils may also enable sound card voice; the sound card does not sound when alsa-lib or alsa-utils is faulty;

Misunderstanding 2: some brothers think that the driver sound card must download the kernel from kernel.org again, and then compile the kernel to solve the problem of the sound card. The kernel downloaded through kernel.org, is able to solve your problem; but the kernel integration sound card driver of kernel.org is also from the alsa-project.org; if we are trying to solve the sound card driver without trying to use the new version of alsa-driver, there is no need to re-compile the kernel;

Correct Opinion: as long as the soundcore in the kernel is compiled in the form of modules and the version information output is viewed through modinfo soundcore, we do not need to re-compile the kernel much; because almost all sound cards and devices are compiled in the system, do not re-compile the kernel first. The problem cannot be solved unless alsa-driver is upgraded, at this time, the kernel can be re-compiled. alsa-driver is associated with the Kernel configuration file. That is to say, alsa-driver is determined based on the Kernel configuration file and which sound cards should be supported; if the Kernel configuration file is not configured to support your sound card, then we need to configure the kernel. In addition, the driver supporting the sound card in the kernel is also from alsa-driver;

3. Compile and install ALSA;

For example, if I have downloaded alsa 1.0.10rc1 and want to download the corresponding packages, such as alsa-driver, alsa-lib, alsa-oss, and alsa-utils, I want to download the same series of versions; we need to install alsa-lib first, and then install other packages;

Warning during compilation of all alsa packages, do not uninstall the built-in alsa-lib and alsa-utils of the Fedora Core. This will fool the system and show that the system is complete; alsa is one of the basic packages and can not be detached at will, because many packages depend on these old packages. For example, if you unload the package that comes with the alsa-lib system, xmms cannot use the alsa driver. It can only use the oss driver, unless you re-compile xmms after upgrading alsa-lib. In addition, the most serious consequence is that if you unload these packages, it will damage the overall dependency of the system, and the yum and apt upgrade systems will not work properly;

Code:
[Root @ localhost alsa] # tar jxvf alsa-lib-1.0.10rc1.tar.bz2
[Root @ localhost alsa] # alsa-lib-1.0.10rc1 cd
[Root @ localhost alsa-lib-1.0.10rc1] #./configure; make install

[Root @ localhost alsa] # tar jxvf alsa-utils-1.0.10rc1.tar.bz2
[Root @ localhost alsa] # alsa-utils-1.0.10rc1 cd
[Root @ localhost alsa-utils-1.0.10rc1] #./configure; make install

[Root @ localhost alsa] # tar jxvf alsa-driver-1.0.10rc1.tar.bz2
[Root @ localhost alsa] # alsa-driver-1.0.10rc1 cd
[Root @ localhost alsa-driver-1.0.10rc1] #./configure; make install

[Root @ localhost alsa] # tar zxvf alsa-oss-1.0.10rc1.tar.bz2
[Root @ localhost alsa] # alsa-oss-1.0.10rc1 cd
[Root @ localhost alsa-oss-1.0.10rc1] #./configure; make install

Tip: the alsa-driver can define the sound card for compilation. This is suitable for veterans. If you are not very familiar with alsa documentation, you can directly use the general-purpose driver. /configure; make install to install; so that all sound cards are installed;

4. Try to use a new ALSA driver to configure the sound card;

At this time, we will use the basic knowledge mentioned above ..... When books are used, they hate less. If you don't learn, you can't do it either;

1) Use alsaconf to configure the sound card;

We need to configure alsaconf to check whether the sound card can be found. When running alsaconf, modify/etc/modprobe for FC4. conf may be/etc/modules for other versions. conf. Add # to or delete all items related to the sound card;

When selecting alsaconf, it is necessary to run the following two commands to update the file index database;

Code:
[Root @ localhost beinan] # rpm-rebuilddb is for the RPM package system;
[Root @ localhost beinan] # updatedb and then run alsaconf

Code:
[Root @ localhost beinan] #/usr/sbin/alsaconf

After alsaconf is used, check/etc/modprobe. conf or/etc/modules. conf, and lsmod to see if the sound card module has been loaded in. If it is not loaded, we will use modprobe to load the module. As mentioned above, please refer to it;

If the configuration file/etc/modprobe is used after alsaconf is run. conf does not change, no sound card configuration content; you want to view the corresponding information on the alsa-project.org, only look at the/etc/modprobe. conf. conf, you can directly write to modprobe. conf (if it is Fedora), the configuration files of each system are similar, if it is not modprobe. conf is modules. conf;

See the ALSA sound card support list and documentation.

Load the module and configure modprobe. conf or modules. conf according to the document;

2) adjust the volume;

We may have already driven the sound card, but there is no sound, you must turn on the volume; adjustment tools: kmix, aumix, alsamixer, system-config-soundcard and other tools;

3) it is worth noting that if you play mp3, pay attention to the following systems;

Since Redhat 8.0, that is, Redhat 9.0, Fedora 1.0, Fedora 2.0, Fedora 3.0, and Fedora 4.0 do not support mp3 any more. The reason is the copyright; however, this does not mean that we cannot enable the Player software to support mp3 in the Fedora system; we can install mp3 support patches or download a brand new player; and all this is inseparable from the online Installation Tool apt or yum;

Tip: test .... Can it be successful? Fail. Next, let's look at the following ......

++ ++
In the second half: after the first half, you still cannot solve the Sound Card problem. You can only use the last trick. Re-compile the kernel ~
++ ++

5. recompile the kernel;

1. Why should we compile the kernel?

Because your sound card is not configured by the current kernel version, we need to compile the kernel;

2. What should I do if I do not compile the kernel ?;

Maybe the novice brother will say that I won't compile the kernel. What should I do? Answer: If you don't want to compile the kernel, you have to learn. No one is born with it. Learning changes fate, isn't it? In fact, compiling the kernel seems to be extremely simple at present, but we were so familiar with Linux for the first time that we were too accustomed to mouse clicks on Windows and Linux Command Line operations. As long as you work hard, nothing can't be done; you can refer to tutorials at the level of north and south. Oh... Sit in front of the computer, if you think that this article by North and South may be helpful to you, you can also do it. Come on ~~~~

3. kernel Selection;

Generally, it is better to select the kernel upgrade package and source code package provided by the release version. You can choose to install the kernel through apt + synaptic, but do not delete the old kernel, system Integrity is very important. In general, if the problem can be solved through the online upgrade of the new kernel, we do not need to compile it. We have already said that; if the new kernel cannot be used for driver, we can compile it based on the new kernel. Of course, we must download the kernel-devel or kernel-source package;

  Why choose the kernel and source code upgrade package provided by the system?

First, it is mainly for convenience. For most options, we can use the default setting. We only need to change the setting for important items. For example, for Fedora Core 4.0, currently, many versions of the online upgrade source can be downloaded and used. We need to install the kernel package and source package of the same version;

Second, if we cannot start the system with the new kernel, we can use the old kernel for guidance, which is for the sake of system security. Applicable to beginners and veterans;

Of course, you can also download the latest and most stable kernel from kernel.org; the latest version is 2.6.13; the kernel downloaded from kernel.org also contains the audio card driver from alsa-driver;

4. Compile the kernel reference document;

Procedure for compiling the kernel-a beginner's Guide

According to the procedures for compiling the kernel-as described in the beginner's guide, this solution is targeted. After compiling the kernel, use alsaconf to configure the sound card; or re-compile alsa-lib, alsa-oss, alsa-utils, etc. After my tests, after re-compile the kernel, you can use alsaconf to configure it;

Postscript:

Now, the sound card solution process is complete. If you think that my document is not detailed enough or cannot solve your problem, there are only two problems, first, your sound card is not supported by ALSA. Please check the corresponding list. Second, if ALSA already supports your sound card, after reading my documents, you still cannot solve your problem (reading or not reading is just a hypothesis, so it's worth reading my documents );

There are two reasons for the second case. One is that documents written in the north and south cannot be understood; the other is that you may be a real beginner and may need more attempts and efforts;

If you still cannot solve the problem, or you can take a closer look at the process mentioned in this document, you may find some inspiration for you. It is best ......

What can I do if you are in the same city as the North and South, and then hold the machine to me? I feel like it can be solved. Haha .........

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.