Solved Issues with mixer: pcm.pcm volume misbehavior

Hello,
When I type "mixer" in the terminal, I see this output:

sh:
$ mixer
cm0:mixer: <IDT 92HD87B2/4 (Analog 2.0+HP/2.0)> on hdaa0  (play/rec) (default)
    vol         = 0.90:0.90   pbk
    pcm         = 0.72:0.72   pbk

I think the pcm.vol value should change alongside the pcm.pcm value. What I mean is, when I adjust the volume control in Xfce (using xfce4-pulseaudio-plugin) to show a value like pcm.vol=50.00; pcm.pcm=50.00 or pcm.vol=85; pcm.pcm=85. However, sometimes the pcm.pcm stays fixed at a certain value like 0.75 and doesn't change anymore. This always happens without any apparent reason, sometimes it works, sometimes it doesn't. Bitperfect mode is disabled. In addition to the internal IDT 92HD87B2 sound card , I also have a Behringer UCA 202 USB sound adapter, and I'm experiencing the same issue.

I've searched through the entire forum and noticed that some people ask how to make mixer changes permanent. Someone suggested restarting with shutdown -r now, which usually works. However, even if the pcm.pcm remains at a value I set before restarting, it starts misbehaving later on as I continue to use the computer.

My /var/db contains these files:

sh:
$ cd /var/db/ ls -l | grep "mixer"

-rw-r--r--  1 root     wheel        249 May  1 13:52 mixer0-state
-rw-r--r--  1 root     wheel         89 May  1 13:52 mixer1-state
-rw-r--r--  1 root     wheel         64 May  1 13:52 mixer2-state
-rw-r--r--  1 root     wheel         64 May  1 03:04 mixer3-state

I tried adding a hint for pcm.pcm and set it to 100 in /boot/device.hints, but this causes pcm.pcm to be set to 100 every time I restart. While this does make the volume louder, it feels like a hardcoded fix, and I don't believe it's the proper solution. I would appreciate any suggestions.
 
Hi Mate, i think this is what you want

dont auto reset vol to default

Code:
/etc/sysctl.conf

Code:
# dont autoreset vol to default
hw.snd.vpc_autoreset=0
 
Hi! Thank you for your help. I appreciate it. I set it to zero. The problem is that when I adjust the volume, pcm.pcm doesn't change, especially when I'm listening to music in Firefox. But in Lollypop music player or VLC, both pcm.vol and pcm.pcm change together and work well. I installed Firefox using pkg, so it probably uses Alsa and not OSS by default. Compiling it from source could be tricky for me because of my older hardware, and I'd rather not mix the two, binary and compiled packages.
 
Hi Mate, you can set Firefox to use OSS instead of Pulseaudio

open firefox about:config

Code:
about:config

paste in

Code:
media.cubeb.backend

set the option to string and the value to

Code:
oss

restart Firefox and it will use OSS audio

By default Firefox uses Pulseaudio thats why your having issue with the volume level
switching to oss will fix the issue
 
I searched for media.cubeb.backend in Firefox 125.0.3 but it didn't exist. I created the property manually as a string and added the value OSS. Now it works and the sound quality seems better. Thank you for your help.
 
In Xfce, I use xfce4-pulseaudio-plugin to adjust the volume. The yellow zone is completely silent. The sound starts to be audible from where the red begins and gets to 100% volume where the red ends. I don't know if this is normal. It doesn't bother me, but I thought I'd ask if this is okay.
 

Attachments

  • sound.jpg
    sound.jpg
    18.1 KB · Views: 23
i havent used xfce for years so im not sure about that issue to be honest

Firefox is the only app i have come across on Freesbsd that use pulseaudio instead of oss
you probably wont come across many apps that use pulse on freebsd so may not be too much of an issue

main thing is you got the audio working with Firefox
 
I remember when mixer was really simple. You would just type mixer volume 90:90 or something similar.
Nowadays, I use mixertui, a fairly small program (21k) with only a few deps. It looks very much like alsamixer. (There's also a gui version, gtk-mixer, if you prefer). I've found that it simplifies volume for me. (As I often play videos with mpv, I also find that mpv's keyboard short cut of 9 and 0 to lower and raise volume is very useful).
 
I believed everything was working, but I noticed today that every time I reboot, the mixer value resets back to 50%. I checked the /var/db/mixer3-state file where the information is saved each time I restart the computer, and the information is saved correctly there. So, if I change the volume with mixertui the information gets saved there during reboot. The problem is that when FreeBSD boots, it doesn't pick up the data from that file. I don't think it's because of Xfce resetting things, as I tried booting in CLI mode and the same problem occurs.

My /etc/sysctl.conf:
sh:
hw.snd.default_unit=3
hw.snd.default_auto=0
hw.snd.vpc_autoreset=0

I tried this suggestion as well but it doesn't work.

The mixer seems to be enabled in /etc/defaults/rc.conf
sh:
mixer_enable="YES"

This command should run during FreeBSD boot but it doesn't:

sh:
$ mixer -f /dev/mixer3 `cat /var/db/mixer3-state`

I checked the /etc/rc.d/mixer and it should the job, though.

sh:
/etc/rc.d/mixer:

#
# Restore the state of an individual mixer specified as $1
#
mixer_restore()
{
    local file dev

    dev="/dev/${1}"
    file="/var/db/${1}-state"
    if [ -r ${dev} -a -r ${file} ]; then
        /usr/sbin/mixer -f ${dev} `cat ${file}` > /dev/null
    fi
}

I tried capturing the stuff to see what is happening during boot so I modified:

sh:
    if [ -r ${dev} -a -r ${file} ]; then
        /usr/sbin/mixer -f ${dev} `cat ${file}` > /dev/null
    fi

to

    if [ -r ${dev} -a -r ${file} ]; then
        /usr/sbin/mixer -f ${dev} `cat ${file}` > /tmp/mixerlog
    fi

cat /tmp/mixerlog shows that mixer is loading the settings for device 2. In other words, it loads the /var/db/mixer2-state instead of /var/db/mixer3-state.
I guess the mixer is applied before the USB sound card becomes available? I did more checking:

sh:
    if [ -r ${dev} -a -r ${file} ]; then
        /bin/cat /dev/sndstat > /tmp/sndstatlog  <--- added this
        /usr/sbin/mixer -f ${dev} `cat ${file}` > /tmp/mixerlog
    fi

Indeed, the information captured from /bin/cat /dev/sndstat shows that the USB sound card is not available when the mixer is loading the information during FreeBSD boot, so it doesn't load the mixer3-state (the USB sound card settings).

The way I fixed it is by creating a small shell script in my home folder.
sh:
/home/myuser/dosomething:

#!/bin/sh
sleep 4 && mixer -f /dev/mixer3 `cat /var/db/mixer3-state`

And I go to XFCE -> Settings -> Startup -> and add my script to run after XFCE login. This sets back the mixer correctly and sound works fine.

The point here is that I need a delay of 2-4 seconds before running the command, so there is something that is only available after the desktop environment starts. Also, my solution feels like a dirty hack. Is there a better folder to place these scripts? or a better way to deal with this?
 
I guess the mixer is applied before the USB sound card becomes available?
You can use rcorder(8) to see in which order the RC scripts are applied.
Checking on this machine, mixer is after FILESYSTEMS, but before devd, devmatch and devfs (which among other things configure usb stuff). devmatch loads kernel modules.
 
I don't think it's boot related. The mixer has to load the stuff a few seconds after the desktop environment starts and it doesn't happen. Please read the last part of my previous post.

The mixer settings are saved properly during reboot in /var/db/mixer3-state. The entire problem here is about reading those values back, which is not happening without an additional script. It should be happening a few seconds after the desktop environment start.

It's strange that this is not a more common problem among users because for me it looks more like a bug or something. The entire mixer got rewritten in FreeBSD 14. Maybe lack of testing on external sound cards.

I'm using a Behringer UCA 202 which is identified as device 3.

It's like: I log into Xfce, /dev/sndstat shows no USB sound card, three seconds later /dev/sndstat shows the USB sound card. Mixer couldn't read the data because the sound card information was not available at that moment.
 
I log into Xfce, /dev/sndstat shows no USB sound card, three seconds later /dev/sndstat shows the USB sound card.
So it takes three seconds for devd and devfs to create the device node (/dev/dspN) needed to adjust the volume settings. You can solve it by creating a file /usr/local/etc/devd/behringer.conf that runs your mixer command immediately after creation of that device node. See devd.conf() for details, it contains a few useful examples.
 
Thank you. I added the information:

sh:
# Behringer UCA 202
notify 100 {
    match "system"        "USB";
    match "subsystem"    "INTERFACE";
    match "type"        "ATTACH";

    match "vendor"        "0x08bb";
    match "product"        "0x0002";

    action "/home/myuser/dosomething";
};

The content of the "dosomething" script:

sh:
#!/bin/sh
mixer -f /dev/mixer3 `cat /var/db/mixer3-state` > /tmp/output

The output of the /tmp/output (what happened during boot):

sh:
vol.volume: 0.83:0.83 -> 0.83:0.83
vol.mute: off -> off
pcm.volume: 0.83:0.83 -> 0.83:0.83
pcm.mute: off -> off
pcm3:mixer: <Burr-Brown from TI USB Audio CODEC> on uaudio0 (play/rec) (default)
    vol       = 0.83:0.83     pbk
    pcm       = 0.83:0.83     pbk

volume 83 and pcm volume 83 matches the one from /var/db/mixer3-state so the reading happened during boot, but for some reason when I run "mixer" in the terminal it spits out the wrong values again, vol 50, pcm 50. Funny, if I run the "dosomething" script manually in the terminal it reads out /var/db/mixer3-state and the correct values are set in mixer, unlike during boot. In other words, the boot process dmesg shows that it happened, but when I check by actually running the mixer command, it did not.

Update 1: I stopped lightdm in /etc/rc.conf to prevent Xorg from starting. In pure CLI, things work fine. So, Xfce messes something up reading out a fake value for mixer, but it doesn't read the proper one from /var/db/mixer3-state which is what I want. I have no volume control plugin installed in Xfce or anything. It's a fresh FreeBSD install.

Update 2: I opened Xfce Settings -> Settings Manager -> Session and Startup -> Application autostart -> and I unchecked "PulseAudio Sound System". Now, Xfce doesn't mess with my mixer values. No need for devd rules. However, stupid PulseAudio won't start with Xfce anymore. I'm just wondering if I need the PulseAudio and if so, how to prevent it from messing with the mixer when enabled.

a.png
 
I unchecked "PulseAudio Sound System". Now, Xfce doesn't mess with my mixer values.
So in fact it was Pulseaudio messing things up. It's not the first time that it shows a somewhat stubborn behaviour. Whether you need PulseAudio or not depends on what you are using it for. Some applications may need PulseAudio. Fortunately, most applications don't.

I have been running an external DAC/ADC using base OSS and (later) audio/virtual_oss from good old @HPS. Pulseaudio, alsa and sndio are not installed on my system. The exception was audio/jack, I had to install that for audio/ardour to work. Just set all applications to use the /dev/dspN that you want them to use and things will usually work with base OSS.
However, keeping pulseaudio and friends out most likely means you will have to use ports instead of packages. It was in fact the reason I switched from packages to ports. First for audio related stuff, later for all ports.
 
It turns out the real problem was not adding snd_uaudio_load="YES" to /boot/loader.conf.
I initially didn't add it because FreeBSD recognized the USB sound card but probably loaded it later in the boot process. The /boot/loader.conf forces the kernel module to load earlier so mixer can see it during the boot process. That was the problem. There is no need for a separate devd rule. And now things seem to work with PulseAudio enabled as well.

If someone finds this thread and has the issue of their mixer resetting with a USB sound card, try these steps:

1. Install mixertui

sh:
$ doas pkg install mixertui

2. Run mixertui and set the volume:

sh:
$ mixertui

Press the ESC key to exit mixertui.

3. Reboot computer using this command (this will save the mixer values):

sh:
$ doas shutdown -r now

Note: Xfce does this automatially if you use the button in the Whisker menu so there is no need to type out the command every time you reboot.
Note: Just the simple "reboot" command doesn't save the mixer values.

4. Check the number of your USB sound card and go to /var/db to check if the mixer values were saved.

sh:
$ cat /dev/sndstat
$ cd /var/db
$ cat mixerX-state (X is the number obtained from sndstat)

If the values were saved, then mixer did its job fine.

5. Add to /etc/sysctl.conf

sh:
hw.snd.default_unit=X (the number of your USB sound card from sndstat)
hw.snd.default_auto=0
hw.snd.vpc_autoreset=0

6. Add to /boot/loader.conf:

sh:
snd_uaudio_load="YES"
 
Back
Top