There is a kernel bug report on this (and a fix): https://bugzilla.kernel.org/show_bug.cgi?id=195457#c11
The trick is to copy sound card settings from Windows to Linux. Here is the content of the above bug report comment:
I also had the same problem with my ASROCK X370 Gaming K4 (ALC1220):
1st case: Booting FIRST Linux: Sound with noise/crackling.
2nd case: Booting FIRST Windows and SECOND Linux: Sound is perfect.
I succeed in solving the problem by comparing the Coeff values in both cases and assign the values of the second case in a script at boot time. How to:
- Install alsa-tools.
- In both cases, you have to run:
echo 1 > /sys/module/snd_hda_codec/parameters/dump_coefs
- Then, in the first case,
alsa-info --no-upload --output infos_bad
- Then, in the second case,
alsa-info --no-upload --output infos_good
- Finally, you compare the coef values:
diff infos_bad infos_good | grep Coeff
For changing the value of each different Coeff, you need to proceed as follows: for example, changing Coeff 0x67 to value 0x3000
hda-verb /dev/snd/hwC0D0 0x20 SET_COEF_INDEX 0x67
hda-verb /dev/snd/hwC0D0 0x20 SET_PROC_COEF 0x3000
You have to do this in the growing order of Coeff. Remark that hwC0D0 refers to your sound card. In case of HDMI output like me, my sound card if hwC1D0.
Here is a quick script:
#!/bin/bash
coeffs=($(echo 0x{16,43,44,5d,5e,63,67}))
values=($(echo 0x{8020,3405,fa10,0606,0000,e430,3000}))
for i in `seq 0 $(( ${#coeffs[@]} - 1 ))`
do
hda-verb /dev/snd/hwC1D0 0x20 SET_COEF_INDEX ${coeffs[$i]} && hda-verb /dev/snd/hwC1D0 0x20 SET_PROC_COEF ${values[$i]}
done
Just change the coeffs to change in the array 'coeffs' and the new values in array 'values' and exec this script. A remark, while I do not shutdown the power supply, my audio chipset keeps the values. This is why you need to do the FIRST case (first...) and then the second. Then, you could test if it works only when you shutdown the power supply of your mobo and then booting into Linux directly.
I'm preparing a patch for the kernel but for those who have the problem, could you post your coeff/values which need to be change please.
Hope this helps.