Creating an asound.conf file

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Post Reply
User avatar
trawglodyte
Established Member
Posts: 16
Joined: Thu Jan 11, 2024 4:32 pm
Has thanked: 11 times
Been thanked: 2 times

Creating an asound.conf file

Post by trawglodyte »

There's a bunch of config files in folders /usr/share/alsa /etc/alsa/conf.d /usr/share/pipewire (this folder must be copied to /etc if it's not there already for best use of pipewire according to documentation), so also /etc/pipewire after you copy it there. And /usr/share/wireplumber. (you do not copy the wireplumber folder to /etc). If anyone knows other A/V config folders I should look through, please tell me.

I think this is important, your apps CAN over-ride defaults, but handing them the proper ones to begin with can only improve how they handle your audio. It will also prevent a lot of conversions from one format, rate, etc... to another. I don't care how good the tech is for converting, best quality is still no conversion needed. In other words, no program can take 16-bit audio change it into 24-bit or 32-bit float and make it better, nor can it take 24-bit and convert it to 16-bit and make it better. Same for changing it from 48000 to 44100 or 96000. There's always going to be something lost in the conversion IMO.

First I was going through every config file in all these folders, looking up every spec and trying to figure out what was optimal for my system. If you do it this way, make a backup first.

Now, I'm under the impression that both ALSA and pipewire will accept any specs I put in /etc/asound.conf (or ~/.asoundrc), and anything I spec there will over-ride system defaults. Is this correct?

What I can't find ANYWHERE is a list of ALL the specs I can put in /etc/asound.conf with clear explanation of what each does, so this is cobbled together with info I had to search distant crevices of the interwebs to find. This is what I have so far...

Code: Select all

## Linux usually defaults to "samplerate" but there are better converters
## put one of the following - samplerate samplerate_medium samplerate_best lavcrate 
## lavcrate_high lavcrate_higher speexrate speexrate_medium speexrate_best
## in between " " below to choose rate converter. 
## save file as /etc/asound.conf or copy/paste to existing
## /etc/asound.conf if you have that file already.
defaults.pcm.rate_converter = "lavcrate_higher"

## resample quality - Linux defaults to 4, this will be used by some apps to pick from the above mentioned converters.
resample.quality = 10

## audio channels, I only do stereo and don't want anything attempting surround
## if I can help it. So I put 2 channels.
audio.channels = 2

## below sets low and high frequency cutoff. Linux usually defaults to 150/15000
## uncomment "channelmix.lfe-cutoff" to extend low frequencies (more bass if your speakers are capable)
channelmix.lfe-cutoff = 60
## uncomment "channelmix.fc-cutoff" to extend high frequencies (you may notice a bit more "sparkle" on your audio)
channelmix.fc-cutoff = 22000

## audio rate, 44100 and 48000 are both good, but codec libopus always converts to 48000.
## IMO, libopus will replace AAC as predominent internet audio codec, so may as well do 48000
## In other words, if anything I produce is going to be converted to 48000 anyway, I might as well
## make it 48000 to begin with instead of hoping the converter various apps and servers use
## aren't sub-par, and knowing even the best ones can't do a perfect conversion.
audio.rate = 48000

## Set other allowed rates if you want. I don't for reasons specific to my audio card.
## But you could put something like "44100,32000,96000,192000" any one or combination.
# audio.allowed-rates = [ 44100 96000 ] # not sure about the formatting with brackets.

## very important setting depending on your hardware. Options include ALAW F32BE F32LE F64BE F64LE
## MULAW S16BE S16LE S24BE S24LE S32BE S32LE S8 U16BE U16LE U24BE U24LE U32BE U32LE U8
## a different format U8 S16_LE S16_BE S24_LE S24_BE S32_LE S32_BE FLOAT_LE FLOAT_BE MU_LAW A_LAW S24_3LE S24_3BE
## to be clear, these optionss are not "better" or "worse", you just want to match your hardware.
## Important for my card, newer cards probably adapt to different formats easier.
audio.format = S24_3LE
pulse.default.format = S24 

## video stuff - Linux defaults to 640x480 25fps
default.video.width = 1920
default.video.height = 1080
default.video.rate.num = 30
## I don't know what this next one is yet.
#default.video.rate.denom = 1

## The following are commented out, because I need to learn more.
## What you see right now is current defaults on my machine. 
#default.clock.rate = 48000
#default.clock.allowed-rates = [ 48000 ] # I'm unsure of the bracket formatting. It seems to me as if formatting changes whether it's ALSA, pipewire, LUA, etc... and not sure what format is right for this file.
#default.clock.quantum = 1024
#default.clock.min-quantum = 16
#default.clock.max-quantum = 2048
#default.clock.quantum-limit = 8192

You can see I am trying to add useful notes as I go, so that in the end someone can paste this into their own /etc/asound.conf and use as a template. But it's a WIP, so do that at your own risk and comment out anything you aren't sure of, many fo these are specific to my setup and are not optimal for yours.

Please tell me if anyone knows what other important things do I need to add here so this template can be useful to others (and help me get my defaults optimized)?? I should also say that I do not multi-track much these days and am not that concerned with latency but I will try to add the relevant settings for that. If someone knows them well and can give me something to paste in, that would be great because it's outside of my wheelhouse.

User avatar
Impostor
Established Member
Posts: 1392
Joined: Wed Aug 17, 2022 1:55 pm
Has thanked: 148 times
Been thanked: 366 times

Re: Creating an asound.conf file

Post by Impostor »

below sets low and high frequency cutoff. Linux usually defaults to 150/15000

uncomment "channelmix.lfe-cutoff" to extend low frequencies (more bass if your speakers are capable)

channelmix.lfe-cutoff = 60

uncomment "channelmix.fc-cutoff" to extend high frequencies (you may notice a bit more "sparkle" on your audio)

channelmix.fc-cutoff = 22000

I suspect these settings are for surround profiles only. For stereo they don't make sense.

User avatar
trawglodyte
Established Member
Posts: 16
Joined: Thu Jan 11, 2024 4:32 pm
Has thanked: 11 times
Been thanked: 2 times

Re: Creating an asound.conf file

Post by trawglodyte »

Impostor wrote: Wed Jan 24, 2024 2:31 pm

I suspect these settings are for surround profiles only. For stereo they don't make sense.

It's so difficult to find good info on this that I don't want to say I'm 100% confident of anything. However, it makes total sense that there is a setting for low-frequency cutoff and high-frequency cutoff, and in all the config files I look at it is channelmix.lfe-cutoff and channelmix.fc-cutoff. Please understand these are system defaults. This does not mean you can't open an audio editor which will immediately over-ride those settings. What it does mean is that at some point you may click a track on a website or an app or something that DOES use your system default and it won't sound as good as it could.

Another example is default for video is 640x480 25fps, so if you click a video someday and are annoyed because it defaults to that when what you want is 1920x1080 60fps, it could be because you told it to with your default settings! I think that I can also say that if you do get all your defaults to your liking there's a much better chance when you install a new app that less settings will require changing before you use it. I know that for a fact.

I did a 3-part video series related to this. This isn't for everybody and I'm only learning as I go. This is 1/2 as much in hopes someone comes along that can explain it to me as it is thinking anyone should listen to me about it. That said, I think if you listen to the first 5 seconds of video 1 vs video 2 you will HEAR the difference, and that's proof of concept.

vid1 - https://odysee.com/@trawg:3/pipewire:d
vid2 - https://odysee.com/@trawg:3/pipewire2:1
vid3 - https://odysee.com/@trawg:3/pipewire3:e

merlyn
Established Member
Posts: 1392
Joined: Thu Oct 11, 2018 4:13 pm
Has thanked: 168 times
Been thanked: 247 times

Re: Creating an asound.conf file

Post by merlyn »

My understanding is that .asoundrc only applies when using what I'll call 'bare ALSA' which isn't common these days. I've looked at /etc/alsa/conf.d/ and it's not something I would edit myself. I use JACK and JACK sets up its own ALSA driver, so .asoundrc and what's in /etc/alsa/conf.d/ is overridden.

I do actually use bare ALSA, even in this day and age. I have a separate soundcard for my browser and desktop audio, so I set that card as the default, with this .asoundrc

Code: Select all

defaults.pcm.!card "DSP24";
defaults.ctl.!card "DSP24";

DSP24 is the name of the card I want as the default, and the exclamation mark overrides the default. Other than that, I leave the config as is.

User avatar
trawglodyte
Established Member
Posts: 16
Joined: Thu Jan 11, 2024 4:32 pm
Has thanked: 11 times
Been thanked: 2 times

Re: Creating an asound.conf file

Post by trawglodyte »

merlyn wrote: Mon Jan 29, 2024 5:28 pm

My understanding is that .asoundrc only applies when using what I'll call 'bare ALSA' which isn't common these days.

I 100% agree that ALSA reads /etc/asound.conf and ~/.asoundrc. I read the script that shows when it does that, very early on at startup (with priority of /etc/asound.conf but I'm not sure if it matters much which place a person with one computer uses, /etc/asound.conf or ~/.asoundrc). However, I disagree that it only applies to bare ALSA. I'm just not sure when and how much of this info gets passed on to pipewire. I do see in /etc/pipewire/cliet-rt.conf that at one point pipewire loads format, rate, channels, period-bytes, buffer-bytes, and volume-method from ALSA.

But, I mean, this is part of the reason why I'm going through all the pipewire configs and changing them too. Just to be sure. lol.

I also see pipewire give you an option of placing a custom config in /etc/pipewire/clint-rt.conf.d/ or ~/.config/pipewire/clint-rt.conf.d/. If that works similarly to asound.conf and .asoundrc then that would probably be a smarter way to do it than manually changing every config file.

IDK, I'm enjoying learning this stuff. But I guess if something useful comes from it I should make template user config with instructions commented out, so people who want to set their defaults can follow it like a guide, setting the values important to them.

For someone, like yourself, who only wants to specify one or two defaults, there's nothing wrong with that. If you want to specify more later or tweak around and experiment you know where to do it.

merlyn
Established Member
Posts: 1392
Joined: Thu Oct 11, 2018 4:13 pm
Has thanked: 168 times
Been thanked: 247 times

Re: Creating an asound.conf file

Post by merlyn »

This is a Linux thing, and if anyone has different ideas please jump in ...

Config files in /etc/ are system wide. The idea with this is that all users have these configs. It dates from a time when a multi-user setup was common. For your user, I think it's better to edit configs in your home folder. Why? If the system configs are working, then you have those as a fallback. If you bugger up the config in your home folder, then you can rename that, and use the system configs to have a working system.

Here this means edit .asoundrc, not the stuff in /etc/.

.asoundrc overrides what's in /etc/.

User avatar
trawglodyte
Established Member
Posts: 16
Joined: Thu Jan 11, 2024 4:32 pm
Has thanked: 11 times
Been thanked: 2 times

Re: Creating an asound.conf file

Post by trawglodyte »

merlyn wrote: Tue Jan 30, 2024 4:03 pm

This is a Linux thing, and if anyone has different ideas please jump in ...

Config files in /etc/ are system wide. The idea with this is that all users have these configs. It dates from a time when a multi-user setup was common. For your user, I think it's better to edit configs in your home folder. Why? If the system configs are working, then you have those as a fallback. If you bugger up the config in your home folder, then you can rename that, and use the system configs to have a working system.

Here this means edit .asoundrc, not the stuff in /etc/.

.asoundrc overrides what's in /etc/.

You're right. I had it backwards at first, thinking /etc/ "takes precedence" or whatnot. But, yah, the ~/.asoundrc would actually overwrite /etc/asound.conf if you had both. I think pipewire has a similar concept, with a couple locations a user can put default preferences. I just need to do a little more homework on it. Not sure if there's any reason someone would use that vs. ~/.asoundrc I have to read the scripts and figure out what order and where those come in.

merlyn
Established Member
Posts: 1392
Joined: Thu Oct 11, 2018 4:13 pm
Has thanked: 168 times
Been thanked: 247 times

Re: Creating an asound.conf file

Post by merlyn »

A fully commented .asoundrc seems a worthwhile thing to do.

trawglodyte wrote: Wed Jan 24, 2024 8:02 am

... In other words, no program can take 16-bit audio change it into 24-bit or 32-bit float and make it better, nor can it take 24-bit and convert it to 16-bit and make it better. Same for changing it from 48000 to 44100 or 96000. There's always going to be something lost in the conversion IMO. ...

Digital audio is not the easiest or most intuitive thing in the world. I have read Principles Of Digital Audio by Ken Pohlmann, and I have some idea of how it works.

Sample rate -- I doubt you could hear the difference, unless the resampling is garbage. Once you start the hardware it's working at a fixed sample rate, lets say 44100 samples per second. Now play back a 48000 samples per second file without resampling and the pitch goes down. It's about a semitone. So you want to resample to 44100 to have the correct pitch.

Bit depth -- You have to realise that there is a big difference between listening to the end product and the process of creating the end product. For listening, 16 bit is good enough. This is not an intuitive concept, but the bit depth doesn't make any difference to the 'quality' or the 'resolution'. The only difference the bit depth makes is in the level of quantisation distortion, which determines the signal to noise ratio. It is difficult, because you would think more quantisation steps would lead to better quality, but it doesn't. It only affects the quantisation error, which results in distortion which we get rid of with dither.

We process audio at a higher bit depth to reduce the calculation errors.

A 24 bit integer file maps exactly onto a 32 bit float file with absolutely zero error. As x42 says " 32 bit float is used for convenience, not fidelity".

Post Reply