Sound output to headphones

freebsd 13.2 system

If you connect headphones, the sound continues to go to the laptop's speakers.
At random, I realized that if you stop the sound and write
Code:
#sysctl hw.snd.default_unit=2
then headphones will work, if 1 - speakers. Can I make it switch automatically?


Code:
# cat /dev/sndstat

Installed devices:

pcm0: <ATI R6xx (HDMI)> (play)

pcm1: <Realtek ALC236 (Analog)> (play/rec) default

pcm2: <Realtek ALC236 (Right Analog Headphones)> (play)

No devices installed from userspace.


Code:
Apr  2 17:12:43 F3ja kernel: hdacc0: <ATI R6xx HDA CODEC> at cad 0 on hdac0
Apr  2 17:12:43 F3ja kernel: hdaa0: <ATI R6xx Audio Function Group> at nid 1 on hdacc0
Apr  2 17:12:43 F3ja kernel: pcm0: <ATI R6xx (HDMI)> at nid 3 on hdaa0
Apr  2 17:12:43 F3ja kernel: hdacc1: <Realtek ALC236 HDA CODEC> at cad 0 on hdac1
Apr  2 17:12:43 F3ja kernel: hdaa1: <Realtek ALC236 Audio Function Group> at nid 1 on hdacc1
Apr  2 17:12:43 F3ja kernel: pcm1: <Realtek ALC236 (Analog)> at nid 20 and 25 on hdaa1
Apr  2 17:12:43 F3ja kernel: pcm2: <Realtek ALC236 (Right Analog Headphones)> at nid 33 on hdaa1
 
From what I read and understand, which I admit is not much, the 3 line should read:

hint.hdaa.0.nid33.config="as=1 seq=15 device=Headphones"
 
find the one that does not say Disabled, then use the line that says config to pull out the information for device.hints
Code:
sysctl -a | grep Headphones
dev.hdaa.1.nid33_original: 0x04211020 as=2 seq=0 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0
dev.hdaa.1.nid33_config: 0x0421102f as=2 seq=15 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0
dev.hdaa.1.nid33: pin: Headphones (Black Jack)
     Pin config: 0x0421102f as=2 seq=15 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0


sysctl -a | grep Speaker
....
ev.hdaa.1.nid24_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid24_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid24: pin: Speaker (None) [DISABLED]
     Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid20_original: 0x90170110 as=1 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1
dev.hdaa.1.nid20_config: 0x90170120 as=2 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1
dev.hdaa.1.nid20: pin: Speaker (Fixed)
     Pin config: 0x90170120 as=2 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1

added to /boot/device.hints

Code:
#headphones
hint.hdaa.1.nid33.config="as=2 seq=15"
#Speaker
hint.hdaa.1.nid20.config="as=2 seq=0"
 
Yes they should be in the same association (as=1). Then you have to fiddle with the "nid"s.
On my old Thinkpad I have this in my /boot/device.hints:
Code:
hint.hdaa.0.nid31.config="as=1 seq=0 device=Speaker"
hint.hdaa.0.nid25.config="as=1 seq=15 device=Headphones"
 
I have this in my device.hints
hint.hdaa.0.nid31.config="as=1 seq=0 device=Speaker"
hint.hdaa.0.nid25.config="as=1 seq=15 device=Headphones"
which looks just the same as twiinbrck.

That's on a thinkpad X201. Works perfectly, switches over on plug in/out.
 
Or something to block KDE5? Since in the audio device settings themselves, sound cards are not switched in manual mode. Why?
 
Code:
root@F3ja:/usr/home/luba # sysctl -a | grep Headphones 
pcm2: <Realtek ALC236 (Right Analog Headphones)> at nid 33 on hdaa1 
pcm2: <Realtek ALC236 (Right Analog Headphones)> at nid 33 on hdaa1 
dev.pcm.2.%desc: Realtek ALC236 (Right Analog Headphones) 
dev.hdaa.1.nid33_original: 0x04211040 as=4 seq=0 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0 
dev.hdaa.1.nid33_config: 0x04211040 as=4 seq=0 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0 
dev.hdaa.1.nid33: pin: Headphones (Black Jack) 
    Pin config: 0x04211040 as=4 seq=0 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0 
root@F3ja:/usr/home/luba # sysctl -a | grep Speaker 
         + [DISABLED] <- nid=18 [pin: Speaker (None)] [DISABLED] (selected) 
         + [DISABLED] <- nid=24 [pin: Speaker (None)] [DISABLED] 
         + [DISABLED] <- nid=26 [pin: Speaker (None)] [DISABLED] 
         + [DISABLED] <- nid=27 [pin: Speaker (None)] [DISABLED] 
         + [DISABLED] <- nid=18 [pin: Speaker (None)] [DISABLED] 
         + [DISABLED] <- nid=24 [pin: Speaker (None)] [DISABLED] 
         + [DISABLED] <- nid=26 [pin: Speaker (None)] [DISABLED] 
         + [DISABLED] <- nid=27 [pin: Speaker (None)] [DISABLED] 
dev.hdaa.1.nid30_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid30_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid30: pin: Speaker (None) [DISABLED] 
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid27_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid27_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid27: pin: Speaker (None) [DISABLED] 
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid26_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid26_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid26: pin: Speaker (None) [DISABLED] 
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid24_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid24_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid24: pin: Speaker (None) [DISABLED] 
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid20_original: 0x90170110 as=1 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1 
dev.hdaa.1.nid20_config: 0x90170110 as=1 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1 
dev.hdaa.1.nid20: pin: Speaker (Fixed) 
    Pin config: 0x90170110 as=1 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1 
dev.hdaa.1.nid18_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid18_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
dev.hdaa.1.nid18: pin: Speaker (None) [DISABLED] 
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1 
root@F3ja:/usr/home/luba #



Code:
hint.hdac.0.cad0.nid20.config="as=1 seq=0 device=speakers"
hint.hdac.0.cad0.nid33.config="as=4 seq=0 device=Headphones"
But with these settings it doesn't work either. :(
 
I got the same settings as twllnbrck on my thinkpad X201.

To figure out the nid's, dmesg | grep pcm gives the following two lines:-

pcm0: <Conexant CX20585 (Right Analog)> at nid 25 and 27 on hdaa0
pcm1: <Conexant CX20585 (Internal Analog)> at nid 31 and 35 on hdaa0

where "right analog" is the headphones (socket is on the right hand side of the box) and
"internal analog" is the internal speakers. Associating the two first nid values (ie 31 and 25) in the device hints forms the association. The two pairs of nids appear to map to the two stereo pairs, associating just the first channel of each pair is sufficient to get full stereo switchover, at least on this system.

So in /boot/device.hints we have:-

hint.hdaa.0.nid31.config="as=1 seq=0 device=Speaker"
hint.hdaa.0.nid25.config="as=1 seq=15 device=Headphones"

There is another detailed explanation here for a machine with a rtl sound chip:-
 
Code:
root@F3ja:/usr/home/luba # dmesg | grep pcm

pcm0: <ATI R6xx (HDMI)> at nid 3 on hdaa0

pcm1: <Realtek ALC236 (Analog)> at nid 20 and 25 on hdaa1

pcm2: <Realtek ALC236 (Right Analog Headphones)> at nid 33 on hdaa1

pcm0: <ATI R6xx (HDMI)> at nid 3 on hdaa0

pcm1: <Realtek ALC236 (Analog)> at nid 20 and 25 on hdaa1

pcm2: <Realtek ALC236 (Right Analog Headphones)> at nid 33 on hdaa1

Probably prevents switching kde5 or its pulseaudio.
Automatic sound switching does not work. :(
.
 
Did you try working through the stackexchange guide? Answer number 1 looks a good fit to your realtek audio chipset. Another thing to note, after you make entries in device.hints, you will see different output in dmesg than when there is no association defined. But I suggest have try at following the explanation in the stackexchange link.

The examples section of "man snd_hda" also has a detailed explanation of how the driver works. It's a real shame there isn't a way to auto-configure a sensible default so that the headphones / speakers switchover just works without the user having to figure this stuff out.
 
Code:
root@F3ja:/usr/home/luba # sysctl -a | grep Headphones
pcm2: <Realtek ALC236 (Right Analog Headphones)> at nid 33 on hdaa1
pcm2: <Realtek ALC236 (Right Analog Headphones)> at nid 33 on hdaa1
dev.pcm.2.%desc: Realtek ALC236 (Right Analog Headphones)
dev.hdaa.1.nid33_original: 0x04211040 as=4 seq=0 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0
dev.hdaa.1.nid33_config: 0x04211040 as=4 seq=0 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0
dev.hdaa.1.nid33: pin: Headphones (Black Jack)
    Pin config: 0x04211040 as=4 seq=0 device=Headphones conn=Jack ctype=1/8 loc=Right color=Black misc=0
root@F3ja:/usr/home/luba # sysctl -a | grep Speaker
         + [DISABLED] <- nid=18 [pin: Speaker (None)] [DISABLED] (selected)
         + [DISABLED] <- nid=24 [pin: Speaker (None)] [DISABLED]
         + [DISABLED] <- nid=26 [pin: Speaker (None)] [DISABLED]
         + [DISABLED] <- nid=27 [pin: Speaker (None)] [DISABLED]
         + [DISABLED] <- nid=18 [pin: Speaker (None)] [DISABLED]
         + [DISABLED] <- nid=24 [pin: Speaker (None)] [DISABLED]
         + [DISABLED] <- nid=26 [pin: Speaker (None)] [DISABLED]
         + [DISABLED] <- nid=27 [pin: Speaker (None)] [DISABLED]
dev.hdaa.1.nid30_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid30_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid30: pin: Speaker (None) [DISABLED]
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid27_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid27_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid27: pin: Speaker (None) [DISABLED]
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid26_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid26_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid26: pin: Speaker (None) [DISABLED]
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid24_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid24_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid24: pin: Speaker (None) [DISABLED]
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid20_original: 0x90170110 as=1 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1
dev.hdaa.1.nid20_config: 0x90170110 as=1 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1
dev.hdaa.1.nid20: pin: Speaker (Fixed)
    Pin config: 0x90170110 as=1 seq=0 device=Speaker conn=Fixed ctype=Analog loc=Internal color=Unknown misc=1
dev.hdaa.1.nid18_original: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid18_config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
dev.hdaa.1.nid18: pin: Speaker (None) [DISABLED]
    Pin config: 0x411111f0 as=15 seq=0 device=Speaker conn=None ctype=1/8 loc=Rear color=Black misc=1
root@F3ja:/usr/home/luba #



Code:
hint.hdac.0.cad0.nid20.config="as=1 seq=0 device=speakers"
hint.hdac.0.cad0.nid33.config="as=4 seq=0 device=Headphones"
But with these settings it doesn't work either. :(
try switching it to seq=15 on headphones as I seen that once between my two systems where one showed seq=0 but when I changed it to 15 it worked, its a try not a fix unless that works.
 
Did you try working through the stackexchange guide? Answer number 1 looks a good fit to your realtek audio chipset. Another thing to note, after you make entries in device.hints, you will see different output in dmesg than when there is no association defined. But I suggest have try at following the explanation in the stackexchange link.
Yes, I read carefully. That only I did not change, does not want to work!

but that's interesting when i turn off the second sound card hint.hdaa.0.disabled=1
then in manual mode
Code:
#sysctl hw.snd.default_unit=2
does not want to switch from headphones to speakers. When the card is turned on in manual mode, switching occurs. Paradox!
 
Probably, but exactly how to do it will depend on your specific hardware. The 'EXAMPLES' section in snd_hda(4) describes how to do this for a Realtek ALC888; those instructions can likely be adapted to work for your card with a bit of experimentation.
I need this card Realtek ALC236 to work when switching headphones to a speaker and back.
 
Probably, but exactly how to do it will depend on your specific hardware. The 'EXAMPLES' section in snd_hda(4) describes how to do this for a Realtek ALC888; those instructions can likely be adapted to work for your card with a bit of experimentation.
I need this card Realtek ALC236 to work when switching headphones to a speaker and back.
 
Thanks for the help!
The following settings helped:

ee /boot/device.hints

Code:
hint.hdac.1.cad0.nid33.config="as=1 seq=15 device=Headphones"
hint.hdac.1.cad0.nid25.config="as=2 seq=0 device=speakers"


ee /etc/sysctl.conf
Code:
hw.snd.default_auto=1
hw.snd.default_unit=1


ee /boot/loader.conf

Code:
# Enable automatic audio jack sensing
hint.hdaa.0.cad0.nid=1
snd_hda_load="YES"
#hint.hdaa.0.cad0.nid25.config="as=1 seq=0 device=speakers"
#hint.hdaa.0.cad0.nid33.config="as=2 seq=0 device=Headphones"
#hint.hdaa.0.disabled=1
 
but now the message about sound recording is gone, microphone (rec):

Code:
root@F3ja:/usr/ports # cat /dev/sndstat

Installed devices:

pcm0: <ATI R6xx (HDMI)> (play)

pcm1: <Realtek ALC236 (Analog 2.0+HP)> (play) default

No devices installed from userspace.


Here's what it looked like before the settings were applied:

Code:
# cat /dev/sndstat

Installed devices:

pcm0: <ATI R6xx (HDMI)> (play)

pcm1: <Realtek ALC236 (Analog)> (play/rec) default

pcm2: <Realtek ALC236 (Right Analog Headphones)> (play)

No devices installed from userspace.
 
Back
Top