Illegitimi non carborundum


Slide around the Sound

Just a quick update on various KDE+PulseAudio changes I've made recently. This is more of an update from previous articles than anything ground breaking in it's own right although there is a nifty (IMO) new feature now available.

Firstly, it was pointed out to me that the use of a QEventLoop was not the best approach when connecting to PulseAudio from a KDE app. I used this technique in Phonon and while it seemed to work fine in testing it did trigger some problems in some unlikely places: namely this bug as reported against Okular! So I changed how the connection test to PulseAudio is run to make it blocking. This has so far appeared to fix the problems \o/

Now on to something interesting 🙂 I've recently added support in Phonon for "hijacking" the volume change requests to allow them to be pushed directly to PulseAudio, totally avoiding the backend itself. In additional it is possible to listen to changes from PulseAudio and then emit the relevant Phonon signal to let applications know the volume has changed. This allows volumes changed in a PulseAudio mixer (pavucontrol and now KMix too!) to be reflected in the Application GUI (should it present it to the user).

Phonon provides it's own VolumeSlider widget that applications can use. I had to make some changes to this to avoid some complicated race conditions. As volume changes in PulseAudio are asynchronous, the change request may be followed some time later by the actual update notification. For this reason the it was not possible to use the "traditional" blockSignals(true) approach. I settled on two flags to achieve the necessary protection and it seems to be working well so far in my testing.

Then I tested Amarok and found it didn't work at all 🙁 This is because Amarok has it's own volume slider widget and does not listen for any volume changes from the Phonon layer. I was able to make the necessary changes to support this without too much trouble, but in doing so I had to change the mute behaviour slightly. Due to (I'm told) legacy reasons, when the volume is muted, Amarok would also set the volume to 0. This was reflected in the GUI by the slider showing 0. While it would be possible to keep this behaviour it's not really desirable these days (the OSD always said "Volume: 0% (muted)" when muted which made it rather redundant to show the %age!) when mute is supported properly. If GUI feedback of mute status on the slider itself is desired (the image does change to a mute symbol already) then it would likely be more appropriate to change the slider colour to grey or similar (which is also how other media players - e.g. VLC represent things).

Anyway, with these issues fixed and suitable support for the feedback race conditions added to the Amarok slider code too, I've now got a rather nicely integrated solution 🙂

Here is a quick screencast I recorded to show you how all these changes: Phonon, KMix & Amarok all work together 🙂

(direct link)

As always, these latest changes are in Mandriva Cooker. The Amarok changes are not in the 2010.1 Beta 1 just recently released, but they will be part of Beta 2 🙂

Share and Enjoy:
  • Digg
  • StumbleUpon
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Slashdot
  • Markus

    PulseAudio is a disease that should be wiped out and not bolstered.

    • Colin

      Do you care to explain why this is?

      People are all too willing to throw around claims without giving any point of reference or any kind of evidence as to why they think that their argument is valid.

      In the medical field, it is very much frowned upon if people offer baseless claims that do not include proper placebo controlled double blind trials, and those who try to promote material in other ways are generally pulled up by their failure to include their research in peer reviewed publications.

      Unscrupulous people, like the BCA do not like to engage in debate over technical merits, they instead try (and fail) to use for example Libel Law to try and prevent comment rather than engage in proper debate and evaluation of the evidence etc.

      I’m afraid that by that comment, without any kind of reasoning or evidence puts you squarely in the same category with such unscrupulous people such as the BCA or other pedallers of pseudo science and mumbo jumbo. You may very well have a point, but without any kind of evidence or a properly constructed argument, you end up looking the fool.

      I’d be happy to debate with you the pros and cons of PulseAudio, and I’ve a wealth of information and details as to why I think it’s the right approach on this site.

      If you would like to debate like a grown up, I’d welcome it, but in future, please only post constructive comments and back up any claims you make with reasoning and trial data.

      • Goop

        I can elaborate a bit for him:

        On my hardware PulseAudio, when and if it worked, would cause intense crackling, randomly sound would drop out if you didn’t change the volume every few seconds and it crashed _a lot_.

        What I’ve noticed about PulseAudio is that on some computers it will work wonders, on others ( such as mine with some Intel sound card ) it will cause many headaches and it’s simply not the case with just ‘plain’ ALSA ( well, less so anyway – there’s always the one or two obscure sound cards/chips that never play nice ).

        Personally I use ‘plain’ ALSA or JACK using ALSA ( when using programs such as Rosegarden that require JACK ) and I have never had any issue with it that wasn’t the fault of PulseAudio forcing itself as the default.

        That said, keep going with PulseAudio development and integration, eventually it will hopefully get to the stage where the compatibility problems are all gone but until then I’m very content with my current setup.

        • Colin

          Yeah this sounds like one of two issues: there was a time when MMX volume scaling stuff was broken in PA and could cause such crackling. It worked fine with SSE so only some H/W was affected. It was fixed a good while ago. The other issue that’s more likely is that because PA is a pretty advanced ALSA client, it make use of some very new parts of the API. It exposed a number of problems in both the library and some of the drivers. This is of course not indicative of a bug in PA itself but of one in ALSA. Although many people still consider this a “PA” bug anyway seeing as most, if not all, other ALSA clients would not trigger it.

          As with all software a PA enabled system will have some bugs for some people, but as you hinted at, fixes and stabilisation come with time 🙂

          • Ema

            Me too I’ve a intel card (dell laptop).
            My biggest complaint ( besides it doesn’t work well on my system ), is that is not easy to remove/disable. At least when you are not using kde/gnome.
            I understand the benefits of integrating everything, and using all the silly buttons you can find on a laptop.
            But, since I’m a dinosaur, I use mplayer and alsamixer to modify the volume.. 🙂
            I would like to know where, using the universal tool (VI), I can disable something I don’t need, and don’t want to run on my system.
            Maybe when PA will work flawlessy I’ll care less about it, but right now I remove it from the system, usually screaming and cursing while looking in the rube goldberg machine the sound system has become. 🙂 🙂

          • Colin

            Well disabling PA is non-trivial as generally speaking a distribution will configure things by default to work with PA OOTB, which means configuring various applications individually to fit in. That said, most of these changes are of a “try PA if it’s running or spawns, and then fall back to alsa if not” style approach and are generally applicable to PA and non-PA setups (tho’ there are no doubt some applications which don’t work this way and will trip you up!).

            But in short the approach is:
            1. Disable PA from starting at X11 login by disabling the start-pulseaudio-x11 script which is run via the pulseaudio.desktop file.
            2. Prevent PA from autospawning by editing the /etc/pulse/client.conf file and putting “autospawn = no” in there.
            3. Prevent ALSA redirecting the “default” device to the PA plugin for ALSA and instead let it default to “dmix”
            4. If your system uses osspd, then disable that.

            Or if you use Mandriva simply fire up draksound and untick “Use PulseAudio” which basically does all that for you :p

            Of course I’d much rather you help locate and eradicate the reasons why you can’t use PA reliably or efficiently on your system as that will generally help everyone. 🙂

          • Ema

            Thanks for the 1). I was going mad in finding why the PA was spawning! I’ve resolved the issue using rpm -e –nodeps 🙂 and changing the /etc/alternatives.

            Probably my system has some issues with heavy vmware & crypted disk.

            3. Doh.. I’m not used to graphical mng tools.. 🙂 My desktop system is wmx 🙂

  • senkal

    These changes look really interesting, but for me, from a year or more, pulseaudio simply doesn’t work. I tried it many times but nothing. Alsa works really well for me, i don’t need to change anything. Of course i can’t even test pulseaudio, because it doesn’t work but i hope your work will help many people who use it.

    • Colin

      It’s quite difficult to “try” PulseAudio without doing rather a lot of integration work. This is a job best left to your distro. So feel free to try the latest version of your distro via a live cd or similar and see how it goes. If they’ve done their job right it should be seamlessly integrated. You say you don’t need PA, but I’d say that kind of setup only applies to desktop users who only have one user account and one sound card and never use webcams or any other USB sound devices. If you have any kind of portable machine or use any kind of extra sound devices (via USB, Bluetooth or the network) then PA is likely the way forward 🙂

      • senkal

        Yes I am the “one type user” 😀 . Maybe you’re right that sooner or later i will need PA. I use Kubuntu , maybe it’s the reason why PA doesn’t work out of the box. I tried to reinstall, install, purge 3-4 times but always got error like “device .. PA..doesn’t work switch to intel …”
        I use some standard Intel card and basic/default settings, nothing fancy. I remember that when PA worked i had some problem with wine, but as far as i know wine now doesn’t support PA.
        So about pulseaudio time will tell.

        • Colin

          Yeah this sounds like the classic problems that result from a poorly intergated system. I’ve make quite a lot of changes in both PA and phonon to ensure that these types of problems are no longer plaguing people 🙂 If you’re interested in the gory details, check out some of my previous posts.

  • Volker

    when will your kmix changes land in svn trunk? will it be in time for kde 4.5? as I see in your screencast, I should fix some vertical-height problem for the slider labels, which seem not to be right calculated. and long labels are also not optimal. what may be the best? cut long ones with “…”?

    • Colin

      I only just rebased them today and wasn’t sure whether the issues caused by the UI changes needed a bit of further attention on my part or not before landing in trunk. I’ll probably just push it in tomorrow so you can help fix :p

  • Asweek

    Hi Colin! Thank you for your greate work integrating PA and KDE!

    I’m using normaly PA with KDE, but without your changes, I’m waiting for KDE 4.5 and this cool stuff. 🙂

  • kriko

    Interresting, will this work without pulseaudio? I seriously hate it. My sound lags when I close e.g. mplayer – it keeps playing for a second or so…
    There is always a noticable delay in any audio application.

    • Colin

      That doesn’t sound ideal. I certainly don’t get any problems with mplayer in that regard. I’m afraid all this stuff will only work with PulseAudio. AFAIK, there is no way to do this using just Phonon alone right now – it would need some kind of additional central daemon to listen for all Phonon streams via DBUS and provide the GUI required. Even then it would only work for Phonon apps (which account for a statistically small number of sound producing applications on Linux but still may count for a large proportion of applications a given user actually uses) rather than all applications which is how PulseAudio operates.

      • kriko

        I hope newer pulseaudio is better. Maybe an athlon 64 3000+ is not adequate for smooth audio playback with pulseaudio. :/

  • Per

    I noticed that Mandriva says phonon 4.3.80 (git). Shouldn’t that be 4.4.80 git as 4.4.0 is released?

    These changes will be in phonon 4.5.0 and not in 4.4.1 meaning Mandriva will ship 4.5.0 (or git)?

    • Colin

      The phonon version is still 4.3.80:

      I’m not super familiar with the versioning scheme here but I guess it’s only loosely related to the Qt version.

      I believe these changes will be upstreamed to the Qt version in due course.

      With regards to Mandriva, we’ve been shipping the “kdesupport” version of Phonon for a few releases. This is now in git rather than under the kdesupport svn branch but the principle is the same. I think we’ll probably continue shipping the version from git for the foreseeable future.

  • Colin, you really need to provide a way to expose the raw alsa mixers. cf

    • Colin

      That’s more of a justification for fixing a broken alsa driver….. There are sometimes reasons to expose a select few alsa mixer elements but this should be kept to an absolute minimum or we’ll end up back at 🙂 We have discussed supporting some degree of pass through of some alsa mixers tho’, but no specific work in this area has been started yet.

      • Whereas I do agree that the alsa needs to be fixed. This is still not the case.
        Moreover, just at the beginning of the week, i had to help my girlfriend solve a sound issue ( no sound after a reboot ). The only way to fix it was to make her open a terminal and start aumix-text ! All of this by phone !

        What I’m saying is the fact to allow to show raw ALSA mixers elements by just doing : kmix -> Configure -> show hardware mixers.

  • Are you sending these patches upstream?

    • Colin

      Yeah all of them are for upstream. The kmix changes landed in trunk this morning and the others have been committed as and when they were ready 🙂

      • Then great 🙂 .

        I’m looking forward to controlling per-app volume from KMix tray icon (if it’s not yet possible – I have to test Mandriva again) :] .

  • Asweek

    Did you saw this Plasma widget to control PulseAudio?

    • Colin

      Ahh nice. That looks promising too 🙂 I’m sure the PA nay-sayers would rather this just worked on top of KMix rather than talking directly to PA but I know that once you get your head into the PA API it’s actually quite easy to work out 🙂 Well done that guy!

  • jospoortvliet

    I would still really apreciate a good write-up somewhere about the need for Pulse Audio. Given Phonon and what it is supposed to do I don’t really get what PA should be solving…. I’ve just been googling but most sources write about how it sucks to have several audio systems (xine, gstreamer etc) and that’s an issue KDE users don’t have thanks to phonon… So is it only good for Gnome and do we, as in KDE users, now suffer because PA, unstable as it still is, is being pushed to fix the gnome audio stack?

  • Ravi Pinjala

    @ other commenters: What kind of a jerk do you have to be to attack somebody’s work on their blog like that? :/

    @ Colin: This sounds like really cool stuff, dealing with layers of volume sliders has always been a pet peeve of mine. Keep up the good work!