Changes

ALSA

11,136 bytes added, 05:17, 9 October 2022
/* Stop Automatic Microphone Gain */
The following lines were added (+) and removed (-):
ALSA or the Advanced Linux Sound Architecture provides audio support for Linux.  It is a replacement for the old OSS linux sound system.  The Alsa-utils package contains both the Alsamixer and Amixer utilities.ALSA or the Advanced Linux Sound Architecture provides audio support for Linux.  It is a replacement for the old OSS linux sound system.  The Alsa-utils package contains both the Alsamixer and Amixer utilities.  Various linux distributions once used the Open Sound System, or OSS until ALSA superseded it.  ALSA provides kernel driven sound card drivers and bundles a user space driven library for application developers.==CLI Utilities==ALSA supports up to eight cards, numbered 0 through 7; each card is a physical or logical kernel device capable of input and output. Furthermore, each card may also be addressed by its id.  A card has devices, numbered starting at 0; a device may be of playback type or a capture type.  A device may have subdevices, numbered starting at 0.  Card interface types include hw, plughw, default, and plug:dmix.  Software will reference it like: interface:card,device,subdevice.===Alsamixer===Get a quick list of audio playback and audio capture devices/cards on your system: aplay -l && arecord -l ==ALSA CLI Utilities== ===alsamixer===Enable the microphone:  switch to the Capture tab with F4 and enable a channel with Space.Select your correct sound card using F6 and select F5 to see recording controls.===Amider===Move around with left and right arrow keys. Increase and decrease volume with up and down arrow keys. Increase and decrease volume for left/right channel individually with "Q", "E", "Z", and "C" keys. Mute/Unmute with the "M" key. An "MM" means muted, and "OO" means unmuted. When you exit by pressing the ESCAPE key your changes will be saved. ===mixer======apulse===The apulse utility lets you use ALSA for applications that support only PulseAudio for sound.===aplay===Alsa play - play an audio fileAn example: aplay /usr/share/sounds/alsa/Noise.wavAn example which specifies a particular sound card aplay -D hw:0,0 /usr/share/sounds/alsa/Noise.wavto access the first device on the first soundcard/device, you would use hw:0,0to access the first device on the second soundcard/device, you would use hw:1,0to access the second device on the third soundcard/device, you would use hw:2,1You can display a List of PLAYBACK Hardware Devices: aplay -lUseful to see what soundcards are available to play audio===arecord==={{:Arecord_alsa_audio_input_testing}}===speaker-test===as the name impliesExample: Testing audio input / microphone input{{:Speaker-test_stereo_separation_test_with_ALSA}}===asoundconf===creates a ~/.asoundrc.asoundconf which should be included from ~/.asoundrc.==Configuration==All files in /proc/asound are created and used by ALSA.  these files describe the sound card or related devices.  */proc/asound/cardX/ (where X is the sound card number, from 0-7) : a cardX directory exists for each sound card */proc/asound/cards is the list of registered cards*/proc/asound/dev/ is a directory listing the specific device files used by programs for sound operations if your system uses devfs*/proc/asound/devices is a read-only file showing the registered alsa devices such as digital audio capture and playback */proc/asound/hwdep hardware dependent controls*/proc/asound/meminfo shows kernel level memory space*/proc/asound/modules lists registered ALSA soundcard drivers for specific things such as each soundcard*/proc/asound/oss/ old oss emulation*/proc/asound/pcm helpful for identification of hw:0,0 labels, technically they are streams/devices but think of it as how you find the hw:X,X values you are looking for.*/proc/asound/seq/ sequencer data*/proc/asound/timers a list of timers ALSA knows about, and also describe which ones are in active use.  (could this be useful in resolving Device or resource busy issues?)*/proc/asound/version version and date the ALSA subsystemAs an example, this break down the output of lsof /dev/snd/pcm*we see (this is an example, yours will be different) fungame 4854 nicolep  mem  CHR  116,10          632 /dev/snd/pcmC0D0c fungame 4854 nicolep  68u  CHR  116,10      0t0  632 /dev/snd/pcmC0D0cwhich is* fungame - the process name, in this case a game that is using ALSA to do sound (play or capture)* 4854 - PID* nicolep - the username owns the process* /dev/snd/pcmC0D0c - device files are what applications connect to in order to perform sound operationsThe device file here is 'pcmC0D0c'* pcm is the service name or type, ours is clearly a pcm which is an alsa stream type * C0 is the card number, C for card and 0 as the first card (numbering starting with 0 and going up 1,2,3...)* D0 is the device number, D for device and 0 as the first device* c indicates it is a capture device.  If it is a 'p' then it is a PCM playback device, if it is a 'c' then it is a PCM capture device.The example we used is only showing capture devices.  It is more common to see some devices ending in 'p' and 'c' both.  The pcm devices (physical I/O channels) are represented in ALSA starting at pcm0c (capture), pcm0p (playback).  ==Sound Mixing with the ALSA Dmix Instead of Pulse Audio==Neither the user-side .asoundrc nor the asound.conf configuration files are required for ALSA to work properly.  Most software will work with sound even if you are not using a sound server and have never created the configuration files.  Sometimes you may find that to resolve issues such as resource busy problems and you discover the software is not capable of using your sound server you have to create the alsa configuration file.You can uninstall PulseAudio or just disable it after boot.  For Ubuntu/Mint you can stop the service: systemctl --user stop pulseaudio.socket systemctl --user stop pulseaudio.serviceYou are doing this because you dont want to get rid of PulseAudio at this time, but  you do what do experiment with dmix or using alsa directly because you are a developer or are trying to work through some trouble with your system.  Pulseaudio is a sound server, and it helps deal with the complexities of sharing sound device resources.  You don't really need a sound server, you can do this with ALSA directly.Testing dmix aplay -D plug:dmix Front_Left.wav & aplay -D plug:dmix Front_Right.wavTo take advantage of dmix in alsa you will create .asoundrc configuration file for your soundcard. vi ~/.asoundrcThen populate the file with the correct entries for your card.You can alternatively make a /etc/asound.conf file which is the system wide version of .asoundrc sudo vi /etc/asound.confYou have to configure each sound application to use alsa:dmix.  This is the catch.  If the software you are using lets you choose the dmix device, then it is reasonable to assume it would just as easily have let you choose pulseaudio.  This has to be tested.  Some older games and software won't use a sound server or try to access it.  They may try for ALSA directly, meaning it is possible they might also be able to see your dmix device that you created.Sample asound.conf - the beginnings of the configuration file pcm.!default {        type hw        card 0 } ctl.!default {        type hw                  card 0 }Exercise 1:Lets create a an alias of a sound card for alsa.  We will call our alias testabc.  If we try this: aplay -D testabc /usr/share/sounds/alsa/Noise.wavWe get an error, no sound plays.  But if we create an alias: vi ~/.asoundrcand enter pcm.testabc {        type hw        card 0        device 0 }save and try to play the audio again (assuming you have the Noise.wav file) aplay -D testabc /usr/share/sounds/alsa/Noise.wavyou have sound!== Troubleshoot =====Microphone Input Low / Microphone Boost Needed===Even though you have the microphone input max in alsamixer you still have low microphone input.  You really have to shout into the mic to get any detectable input on the recorder.How to test? arecord -vvv -f dat /dev/nullHow to Boost alsamixerOnce alsamixer is loaded, goto the mic boost and press the 'm" key to toggle from mute to boost.  See image:[[File:alsa-micboost.jpg|thumb|none|100px]]by highlighting the "Mic Boos" (aka Mic Boost) and pressing the 'm' key you should observe the MM in the box change to 00 which indicates microphone boost is now activated.Microphone boosting is a toggle, MM indicates off, and 00 indicates on.===Intentionally Disabling and Hiding HDMI Audio When Using an Add-on Soundboard===It can be somewhat problematic under certain circumstances to have all of those HDMI audio interfaces detected and visible to ALSA and PulseAudio.  Rather than just muting or disabling them, you can blacklist the drives so the system does not  load them on boot.  However, under some circumstances this can also disable other sound cards depending on your configuration and chipset.On a Dell Precision system with an AMD video card (this is an example system) the four video ports create four HDMI audio devices in addition to the motherboard audio.  Disabling the HDMI audio interface by blacklisting snd_hda_intel will also disable the onboard audio.  However, when an addon soundcard is used, such as an installed PCI card or USB sound card, there are advantages to blacklisting snd_hda_intel so HDMI and onboard sound are neither loaded nor recognized by the system.  This cleans things up and resolves issues with some games that improperly request the ALSA device including SteamOS games. For the example a PCI sound card was added to the system and onboard audio was also disabled on bios.  Then do this: sudo vi /etc/modprobe.d/blacklist.confand add blacklist snd_hda_intel blacklist snd_hda_codec_hdmithen reboot.Now the only audio playback and capture devices visible to the system are those provided by the addon soundboard.  This worked with an Ensoniq PCI card and was also tested with an MAudio USB soundboard.===Stop Automatic Microphone Gain===Some applications, like Google Chrome, or Discord, will automatically adjust the microphone input gain.  Often, they do a poor job of it.  The UI has no option to disable automatic mic gain adjustment.  ''Question:  Is there any way to prevent application from changing volume level of my microphone?''Yes.  This solution has been tested and confirmed working on Linux Mint (Ubuntu).  Edit the configuration file /usr/share/pulseaudio/alsa-mixer/paths/analog-input-internal-mic.conf  sudo vi /usr/share/pulseaudio/alsa-mixer/paths/analog-input-internal-mic.confLook for this block: [Element Capture] switch = mute volume = merge override-map.1 = all override-map.2 = all-left,all-rightAnd specifically change the line volume = mute to: [Element Capture] switch = mute volume = 80 override-map.1 = all override-map.2 = all-left,all-rightIn my example I set the mic gain to 80.  You can adjust that number to best suit your needs via trial and error.  Once the edit is done and saved you need to issue the following command.  It is best to close whatever application is using the mic first. sudo alsa force-reloadThis solution comes from the web site [https://askubuntu.com/questions/749407/is-there-any-way-to-prevent-application-from-changing-volume-level-of-my-microph AskUbuntu - Is there any way to prevent application from changing volume level of my microphone?] or see also [https://askubuntu.com/questions/279407/how-to-disable-microphone-from-auto-adjusting-its-input-volume this post].[[Category:Linux_Sound]]
Bureaucrat, administrator
16,199
edits