# Distorced audio if using device.hints, perfect audio if switching via sysctl hw.snd.default_unit. What is happening?



## srlemke (Apr 20, 2019)

So I decided to post here before opening a bug report, after attempting almost all ways to fix this.

Status is: If I don't touch /boot/device.hints:
onboard audio works perfect;
Headphone audio: plugin/plug-out makes no difference(audio always plays fine onboard), but, if I assign the device manually with:
sysctl hw.snd.default_unit=1; #(changing HP device): Then audio works fine, crystal clear and beautiful 

Original /dev/sndstat (no /boot/device.hint change):

```
slemke@besta:/home/slemke 196 $ -> cat /dev/sndstat
Installed devices:
pcm0: <Realtek ALC298 (Internal Analog)> (play/rec) default
pcm1: <Realtek ALC298 (Left Analog Headphones)> (play)
pcm2: <Intel Skylake (HDMI/DP 8ch)> (play)
No devices installed from userspace.
slemke@besta:/home/slemke 197 $ ->
```

Buuuut, I don't want always run sysctl hw.snd.default_unit=1; and hw.snd.default_unit=0; to switch between onboard/HP, so I decided to play with the /boot/device.hints:

I got my nid list booting freebsd with verbose(selected on boot menu keys 6 then 5):

```
#hdaa0: Original pins configuration:
#hdaa0: nid   0x    as seq device       conn  jack    loc        color   misc
#hdaa0: 23 90170110 1  0  Speaker       Fixed Analog  Internal   Unknown 1
#hdaa0: 33 03211020 2  0  Headphones    Jack  1/8     Left       Black   0
#hdaa0: 18 90a60130 3  0  Mic           Fixed Digital Internal   Unknown 1
```

Added bellow line to /boot/device.hints so onboard and HP are on the same audioset(as) and correct sequence:

```
hint.hdaa.0.nid33.config="as=1 seq=15" # HP
```

After reboot I see the audio is associated correctly:

```
root@besta:/home/ # cat  /dev/sndstat
Installed devices:
pcm0: <Realtek ALC298 (Analog 2.0+HP/2.0)> (play/rec) default
pcm1: <Intel Skylake (HDMI/DP 8ch)> (play)
No devices installed from userspace.
root@besta:/home/ #
```

dmesg after some plugin/out tests:

```
root@besta:/home/ # dmesg |grep hdaa
hdaa0: Pin sense: nid=33 sense=0x80000000 (connected)
hdaa0: Pin sense: nid=33 sense=0x00000000 (disconnected)
hdaa0: Pin sense: nid=33 sense=0x80000000 (connected)
hdaa0: Pin sense: nid=33 sense=0x00000000 (disconnected)
hdaa0: Pin sense: nid=33 sense=0x80000000 (connected)
hdaa0: Pin sense: nid=33 sense=0x00000000 (disconnected)
hdaa0: Pin sense: nid=33 sense=0x80000000 (connected)
hdaa0: Pin sense: nid=33 sense=0x00000000 (disconnected)
root@besta:/home/#
```

Well, that works!
Now when I plugin the HP the onboard audio mutes and audio starts playing on the HP as expected.

The problem: distorted audio barely can recognize what music is playing.

Mixer is healthy:

```
root@besta:/home/ # mixer
Mixer vol      is currently set to  59:59
Mixer pcm      is currently set to 100:100
Mixer speaker  is currently set to  74:74
Mixer rec      is currently set to  53:53
Mixer igain    is currently set to   0:0
Mixer ogain    is currently set to   0:0
Mixer monitor  is currently set to  0:0
Recording source: monitor
root@besta:/home/ #
```

Any clue? Resuming: Bad audio only if using device.hint, if I dont use a hint and change via sysctl hw.snd.default_unit then the audio sounds totally fine(but dont automatically switches between HP and onboard).


----------

