Bug 189796

Summary: KMix doesn't remember master channel with multiple sound cards
Product: [Applications] kmix Reporter: Malte S. Stretz <mss>
Component: generalAssignee: Christian Esken <esken>
Status: RESOLVED FIXED    
Severity: normal CC: kde
Priority: NOR    
Version First Reported In: 4.3   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=332177
Latest Commit: Version Fixed/Implemented In: 4.13
Sentry Crash Report:
Attachments: A lot of output
kmixrc after chosing the USB device
More output

Description Malte S. Stretz 2009-04-16 13:54:39 UTC
Version:           3.5 (using 4.2.2 (KDE 4.2.2), Kubuntu packages)
Compiler:          cc
OS:                Linux (x86_64) release 2.6.28-11-generic

I've got two sound cards connected to my system:
 * The onboard "HDA ATI SB" (plus a "HDA ATI HDMI")
 * The "USB Playback and Recording Syst" (truncated like that), my screen with builtin sound card, connected (obviouskly) via USB

The screen also has a KVM built in, so the second sound card tends to come and go but I don't think that matters.

Nothing is connected to the onboard card and in Phonon, the USB device is set as the main one.

After each reboot, I've got to select the correct master channel, PCM on the USB device, for the tray icon again. After the next logon, it will be PCM on the onboard card again.
Comment 1 Christian Esken 2009-04-20 23:05:16 UTC
In general this works. So this must be something special about your soundcard(s) or other setup.

Lets try to find out what.

Please post the output of "amixer" (or "amixer -c 1" or any other number that corresponds to the affected soundcard).

Please also report if other mixers work (e.g. alsamixer).

Please also post the permissions of your sound card devices, using
 getfacl /dev/snd/controlC0  (or controlC1 or any other number that corresponds to the affected soundcard).

Please also post the KMix configuration. It is in below your home directory, either in ~/.kde4/share/config/kmixrc or ~/.kde/share/config/kmixrc

Should you happen to know the hal toolset (lshal, hal-find-by-*, hal-device), you might want to check wheter the card identification changes.
Comment 2 Malte S. Stretz 2009-04-21 00:24:46 UTC
Created attachment 32966 [details]
A lot of output

Ok, here you go:
* amixer output for all 3 cards ("HDA ATI SB", "HDA ATI HDMI" and finally the USB device)
* getfacl output for all three devices
* lsusb output for the USB device
* A grep over lshal for the USB device
* The dmesg output represents the point where I toggled the builtin KVM, ie. the USB sound device (plus my input devices, they are attached to the USB switch) disappear and appear again.
* And another lsghal grep

Observations:
* alsamixer doesn't seem to lose the master card
* KMix jumps back to the first device after the toggle
* In the kmixrc, DefaultCardOnStart is always ALSA::HDA_ATI_SB:1
* MasterMixer is properly set to ALSA::USB_Playback_and_Recording_Syst:1 when I chose it
* The value stays like this even when KMix jumps back to the first device
* When I quit KMix, the value is set to ALSA::HDA_ATI_SB:1 again
* (Why the hell do you use user visible strings as ids in the kmixrc?)
Comment 3 Malte S. Stretz 2009-04-21 00:25:31 UTC
Created attachment 32967 [details]
kmixrc after chosing the USB device
Comment 4 Malte S. Stretz 2009-04-21 00:28:09 UTC
Created attachment 32968 [details]
More output

Forgot to save the file before attaching. Here is the dmesg and the lshal afterwards.
Comment 5 Christian Esken 2009-04-22 21:59:04 UTC
Thanks for the feedback. This is very interesting. I see are actually 4 soundcards in the KMix configuration:

1) ALSA::HDA_ATI_SB:1
2) ALSA::HDA_ATI_SB:2
3) ALSA::USB_Playback_and_Recording_Syst:1
4) ALSA::USB_Playback_and_Recording_Syst:2

And you show getfacl for THREE devices (not 4), so it is one less. Quite mysterious. But this might be an indication that some bizarre hotplug sequence has occured at some point of time (e.g. a quick unplug/plug, where KMix has seen the new plug before the unplug). You might want to try to remove the kmixrc - I don't think it will really help solving the issue, but it would be intersting to see whether ALSA::USB_Playback_and_Recording_Syst:2 will show up again.

The truncatated name in the KMix Config is "correct", as it is truncated by the driver/kernel already:
  alsa.card_id = 'Philips Electronics USB Playback and Recording Syst'  


kmixrc looks fine. It uses ALSA ("ALSA::"), the card is named "USB_Playback_and_Recording_Syst", and the first (":1") card of that name is used:
MasterMixer=ALSA::USB_Playback_and_Recording_Syst:1
MasterMixerDevice=PCM:0

---------------
So probably this is not the issue. Is the USB soundcard connected at all times? 

Because KMix will autmatically move the Master away when a card is unplugged or not found. This could happen in various situations (guessing):
Either the card is not immediately available after logging into KMix, or when logging out/shutting down the computer, the driver gets unloaded (which is about the same as an unplug). Well, these are wild guesses.

I'll try to reproduce it at my box (need to upgrade my OS, and find the old USB soundstick first).
Comment 6 Malte S. Stretz 2009-04-27 15:38:06 UTC
I completely removed my kmixrc now, will see if the second USB device will reappear.

And yes, my USB sound device comes and goes all the time (as you can see in the dmesg output). The sound device is integrated into my screen so every time I switch it off (like when I leave my place), the sound device goes away and KMix falls back to the onboard one. I guess thats fine so far, but it should select my preferred again once it reappears.

Can't KMix just rely on the primary device selected in Phonon (which gets things right even with the disappearing sound device) instead of carrying its own device information?

And about the truncated description: I don't know where it gets truncated, I guess by HAL; lsusb (and some other tools) show the correct description. That's why I think its very dangerous to rely on a user visible string maintained by a database not under KDE's control as a device id.
Comment 7 Malte S. Stretz 2009-05-03 16:02:01 UTC
Guess bug 181652 would fix this ;-)
Comment 8 Christian Esken 2011-01-02 22:30:21 UTC
Currently I am working on moving back the master control to the preferred one.
Target Milestone: KDE 4.7
Status: 75%. Implement "Preferred master" (done), Hotplug (pending)
Comment 9 Christian Esken 2012-10-03 23:49:40 UTC
Internal work hint: In the development version, the fallback doesn't work. So I must look into this issue anyhow. Assigning ticket.
Also the switch back is not there. It might in fact be worthwhile to evaluate whether following Phonon changes might be somehow possible.
Comment 10 Kai Uwe Broulik 2013-01-23 02:13:43 UTC
Imho it should automatically switch master channels based on the Phonon settings (if user did not choose to override that, ie. on a fresh install) without prior user action. I plugged in my headset, nothing happened, KMix still set volume on the speakers. I manually changed it to the headset, now everything works as expected (unplug headset, speakers are master, plug in headset, headset is master) but this should've worked right away because the headset has higher prio in Phonon settings.
Comment 11 Christian Esken 2014-06-24 00:45:20 UTC
Git commit 14ff188c38819446c07a4b3eee3faafaec487bf5 by Christian Esken.
Committed on 24/06/2014 at 00:41.
Pushed by esken into branch 'master'.

Remove superfluous soundcard numbers in tabs
Fix card instance ids, for systes with two identically named sound cards
(like "USB" and "USB")
Implement recommendedMaster for the Pulse backend
Related: bug 332177
REVIEW: 116850

M  +6    -3    CMakeLists.txt
M  +3    -1    backends/mixer_alsa9.cpp
M  +2    -1    backends/mixer_backend.cpp
M  +55   -1    backends/mixer_backend.h
M  +1    -1    backends/mixer_mpris2.cpp
M  +4    -3    backends/mixer_oss.cpp
M  +1    -1    backends/mixer_oss4.cpp
M  +61   -22   backends/mixer_pulse.cpp
M  +4    -1    backends/mixer_pulse.h
M  +1    -1    backends/mixer_sun.cpp
M  +2    -4    core/mixer.cpp
M  +2    -3    core/mixer.h
M  +3    -15   core/mixertoolbox.cpp
M  +0    -1    core/mixertoolbox.h

http://commits.kde.org/kmix/14ff188c38819446c07a4b3eee3faafaec487bf5
Comment 12 Christian Esken 2014-06-24 00:47:46 UTC
This ticket might also need changes from review 116851 before everything is fixed.
Comment 13 Christian Esken 2014-08-12 09:17:20 UTC
I have dons some tests with artificial soundcards, and it works for me with the change noted in the last comment. Should thus be fixed in KDE 4.13.