Tips and tricks for Linux
In the following, we will show you a few commands for the Linux® command line that you can use to control the sound card. We assume that ALSA is installed with PipeWire or PulseAudio. We also assume that the sound card has been started in "Full-Featured Mode". We have described this in more detail in the manual.
This is the case with most Linux® distributions. You should also install the programs ffmpeg
, ffplay
, alsamixer
, amixer
and pactl
. With Ubuntu, for example, you have to install the packages ffmpeg
and alsa-utils
. For other Linux® distributions, you can find out how to install the above programs on the distributor’s website or in the relevant forums.
ALSA vs. sound server
When using Linux®, a so-called sound server such as PulseAudio or PipeWire is typically installed. These sound servers do not display the controls of the audio hardware. The volume controls of these sound servers are purely software-based and therefore do not change the corresponding control element on the sound card. The sound servers do not communicate directly with the audio hardware, but only with an abstraction layer called ALSA (Advanced Linux Sound Architecture). With ALSA, a standardized programming interface is available that allows a program, such as a sound server, to control any sound card supported by ALSA without having to worry about the specific implementation details for the respective audio hardware. Of course, it is also possible to output audio directly via ALSA using a program. However, the sound servers offer some convenient functions that are not available with ALSA or can only be configured with some effort.
ALSA control with text-based interface
At ALSA, the states of the control elements can be displayed and changed with the following command:
alsamixer -c DSC8
The program can essentially be controlled using the cursor keys and space bar. Further information can be found in the program help.
Volume and muting
Strictly speaking, you have two volume controls. One slider controls the volume on the sound server and the other on ALSA. With most distributions, you can already control the volume of the sound server using the multimedia keys on your keyboard without any further action. If this is not already the case, it makes sense to change the volume at ALSA to the maximum. You can adjust the volume using the program alsamixer, which we have already described above.
Volume control for ALSA
Query all volume controls:
amixer -D hw:DSC8 sget Volume
Query main controller:
amixer -D hw:DSC8 sget Volume,1
The volume can be set absolutely in the range 0-127, where 0 is inaudibly quiet and 127 represents the maximum volume:
amixer -D hw:DSC8 sset Volume,1 10
The volume can be set as an absolute percentage, whereby 0% is inaudibly quiet and 100% represents the maximum volume:
amixer -D hw:DSC8 sset Volume,1 15%
The volume can also be increased relatively with the command:
amixer -D hw:DSC8 sset Volume,1 3%+
or
amixer -D hw:DSC8 sset Volume,1 5+
Accordingly, the volume can also be relatively reduced with the command:
amixer -D hw:DSC8 sset Volume,1 3%-
or
amixer -D hw:DSC8 sset Volume,1 5-
The following command mutes the output:
amixer -D hw:DSC8 sset Volume,1 mute
The following command switches off the muting of the output:
amixer -D hw:DSC8 sset Volume,1 unmute
You can mute the output as follows:
amixer -D -D hw:DSC8 sset Volume,1 toggle
Volume control for the Sound Server via ALSA
The sound server PipeWire and PulseAudio only have one volume control. The commands are similar to ALSA. Only the device name hw:DSC8
is replaced with pulse
and the name of the controller is changed from Volume,1
to Master
. To query the volume, you must therefore execute the following command:
amixer -D pulse sget Master
The other commands are not documented here, as they can be rewritten in the same way.
There is another difference to ALSA. The value range for the sound server is from 0 to 65535.
Volume control for Pipewire
At Pipewire you can use the command line tool wpctrl
to view and change any setting of PipeWire. The value range of the volume at Pipewire is from 0 to 1, where 0 represents the minimum and 1 the maximum volume. Decimal places are also possible, e.g. 0.5
.
You can display the current volume as follows:
wpctl get-volume @DEFAULT_AUDIO_SINK@
For example, you can set the absolute volume to 0.75:
wpctl set-volume @DEFAULT_AUDIO_SINK@ 0.75
This corresponds to 75% of the maximum volume. Alternatively, you can also write the following:
wpctl set-volume @DEFAULT_AUDIO_SINK@ 75%
You can also reduce the volume relatively by 5% with :
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
You can increase the volume by 5% with the following command:
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
You can mute the output with the following command:
wpctl set-mute @DEFAULT_AUDIO_SINK@ 1
And with this command you can switch off the mute function:
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0
And with this command you switch the mute function, i.e. either on or off, depending on which state it was in before:
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
The current status of the mute function is displayed with the following command:
wpctl get-volume @DEFAULT_AUDIO_SINK@
A [MUTED]
is displayed after the volume. The tool does not have an explicit get-mute
command.
Switch inputs
If you have connected an input expansion card to the sound card, you can control the inputs with the following commands. The following command returns the current status of the inputs:
amixer -D hw:DSC8 sget 'Input Capture Source',0
All available inputs are listed in the line beginning with Items:
. The currently selected input is displayed in the line beginning with Item0:
.
In the following, we assume that the input ''Input 2: card = 1 (SPDIF), port = 2'' is displayed under 'Items:'. We can select this input as follows:
amixer -D hw:DSC8 sset 'Input Capture Source',0 'Input 2: card = 1 (SPDIF), port = 2'
Unfortunately, it is no longer possible to select the next or previous input with a simple command. A script is required for this. You can download this script here. After the download you only have to make the script executable with the following command:
chmod +x input.sh
Now you can select the next input with :
./input.sh next
You can select the previous input as follows:
./input.sh prev
The script can do even more. Simply call up the following to see all the options:
./input.sh
Display the status of the sound card
With the following command you can see, for example, whether the recording or playback function of the sound card is currently in use or not:
cat /proc/asound/DSC8/stream0
If the beginning of the line Status:
is followed by Stop
, then the respective function is not in use. Otherwise, the parameters with which playback or recording was started are displayed. You can use this status information, for example, to switch the active loudspeakers on or off with a time delay.
Redirect data stream from input to output
This section is only relevant if you have connected an input expansion card to the sound card. The data stream must be redirected from the input to the output using software. The tool alsaloop
from alsautils
can do this. Unfortunately, the tool can only process PCM signals and not compressed surround signals. The tool outputs compressed surround signals unchanged, which means that only an unpleasant noise can be heard.
However, it is possible to solve this problem with the ffmpeg
tool. If this has not already been done, it must first be installed on the system.
You can activate automatic decoding with the following command:
ffmpeg -hide_banner -loglevel panic -f alsa -ac 2 -ar 48000 -i plughw:CARD=DSC8,DEV=0 -c:a pcm_s16le -f wav - | ffplay -loglevel quiet -nodisp -fflags nobuffer -flags low_delay -framedrop -
Ok, the command is a bit unwieldy. Furthermore, the command must be adapted to the sample rate that is currently present at the input, otherwise the sound card will only record silence. The parameter -ar 48000
is responsible for this. We have written a script to automate the whole process for you. You can download it here. The script is not yet perfect. If you take the computer out of stand-by mode, you should definitely restart the script, as occasionally a process of the script gets stuck and this leads to unpleasant noises. However, we are working on fixing this.