r/linuxdev • • Sep 27 '13

How can the Linux audio infrastructure mess be fixed?

One complaint that has been leveled against Linux is that the audio infrastructure is messy and thusly has too many failure modes. I'm using Linux and enjoying it, but I think there may be a valid complaint here. I'm currently new to programming, and I still haven't learned digital audio signal processing, but I have plenty of free time. I could learn a great deal in a reasonable amount of time. I'd love to develop something that can replace parts of the infrastructure with a single framework. My question is: what are your thoughts on it? What would be the best route to clean up the infrastructure? Does it need to be cleaned up at all?

34 Upvotes

36 comments sorted by

View all comments

Show parent comment

103

u/wadcann Sep 27 '13 edited Sep 28 '13

[continued from parent]

Other sound systems

I'm not familiar with Bluetooth audio or Firewire, but apparently both have their own audio subsystems. I think that ALSA and Pulseaudio can both talk directly to at least Bluetooth.

Compatibility libraries

Obviously, application developers don't care about most of this. 95% of video game vendors want to play back a simple stereo audio stream and have it show up on the user's headphones.

The result was the development of compatibility libraries, so that instead of having to support all of these interfaces, applications could write to one compatibility library and have things work everywhere.

Major libraries to do this included SDL (which also handled other things, but did a good job of having multiple audio backends) and libao. OpenAL was also used by a number of ported games, though it has different goals (mostly providing 3d audio with Doppler effects). Applications would be written to these libraries. These all could route audio to different backends. They often had configuration (OpenAL had a text config file. SDL used environment variables, though out-of-box configuration was mostly sensible on most systems.)

This meant that switching applications to use a different audio system had another layer of indirection/complexity/place where things could go wrong. You've got some script that set SDL_AUDIODRIVER=alsa to stop using OSS back in the day? Great...until you're trying to get your program to use PulseAudio (via the native interface) and can't figure out why it's going through ALSA.

Audio patch panel, JACK

Often, people have different sound applications that they want to use, and want to hook up to each other. Maybe they've got a synthesizer and a visual effects program for DJing. Maybe they've got some program to pull in MIDI. Back in the day, this would have been done via physical boxes, with audio cables connecting one box to another called a patch panel.

In the computer world, it makes no sense to run audio out of a sound card just to let things be hooked up across programs. People developed systems for letting one program on a computer talk to another on a computer.

Windows has some expensive, proprietary program whose name I don't recall to be a virtual patch panel; as long as two audio programs support it, the user can use it to "connect" a virtual output in one program to a virtual input in another.

Linux has an open-source system called JACK. This does a good job of eliminating latency that prior audio servers had introduced, and pretty much serves the same role.

However, it means yet another audio server and incompatible audio sound server API for applications to support. Generally-speaking, pro audio will use this (i.e. if you want to use serious Linux pro audio stuff like ardour, you're going to be hooking up to JACK. Then "consumer" audio today, simple playback and recording from a mic, mostly goes through PulseAudio.

Summary of issues

  • Often, a lot of complexity was exposed without providing a simple interface for users who didn't want all of the extra controls (e.g. ALSA's settings).
  • Sometimes a lack of Linux support from vendors meant that a piece of hardware wasn't supported (though this has been solved for a long time, and in fact, Linux's support for older audio cards tends to mean that it significantly beats Windows on hardware audio support).
  • People developing new systems often placed very little weight on providing hard backwards compatibility, or saw backwards compatibility as a short-term bridge to get people onto their new system. They were willing to break apps from people after a couple of years; there's no commitment to keep software working for ten years, say. This is a major concern I have with Wayland/Mir, which are demonstrating exactly the same sorts of positions ("oh, once you switch to my Wayland system, you can kinda/sorta use XWayland to kinda-sorta make X apps work...mostly...well, window managers won't work...and some utility programs might not work quite right...but my system is new and clever") that caused years of Linux audio compatibility breakages and frustrated users and looks to me to be heading straight down the same path.
  • Often, it was hard for users to diagnose problems, because the different audio systems never had a single UI. As a user, I want to deal with "sound", and so I go look at my sound control panel or want to run a "mixer" control panel or something. To this day, I cannot name a single mixer (volume control/sound control panel/etc) program that worked with all the various Linux audio systems or would let someone get an idea of how the audio on their system was being routed or play test audio out each. All it took was one output being muted or one program using a different backend to cause trouble. A new user would need to use "aumixer" (OSS), "alsamixer" (ALSA), "pavucontrol" (PulseAudio), and so forth, with nothing even telling them that these different systems existed.
  • A number of systems were included before they were really ready, probably because distros wanted to encourage their use. This is a very expensive practice in terms of user time sunk on fixing things.
  • There is some split between the traditional command-line Unix guys (people like me who want config files) and the I-came-from-Windows crowd (people who do not want config files and do want interactive sliders and don't care about command-line tools or mixers). PulseAudio tended strongly towards the Windows crowd, and ALSA the Unix crowd, and both tended to annoy people in the other crowd.
  • Many of the attempts to mitigate situations with incompatible interfaces involved introducing more incompatible interfaces.

Today, I'm not sure how much there is to fix. Most people are using PulseAudio for consumer stuff and JACK for pro stuff and simply time and maturity has meant that a lot of the wrinkles have been smoothed out, handled by the distro maintainers. I think that a single app that shows a diagram of where sound is "going" would be nice, and understands the various sound systems, but I don't think that re-engineering chunks of the system would solve much (and would make things worse). What Linux really needs is (a) more weight given to backwards-compatibility and using mature systems and making sure that things are done before they go in and (b) giving app vendors time to adapt to a given system.

7

u/[deleted] Sep 28 '13

Whoa, thanks. Audio was one of the reasons I gave up on Linux back in 2009 and haven't revisited it since (outside of using it for dev work and hosting). I'm happy to give Ubuntu 13.10 a try, though.

+/u/altcointip $3

5

u/ALTcointip Sep 28 '13

[Verified]: /u/im14 -> /u/wadcann, 0.0225782 ^Bitcoin(s) __($3)__ [help] **[tipping_stats]**

-4

u/[deleted] Sep 28 '13

[removed] — view removed comment

1

u/[deleted] Sep 28 '13 edited Sep 28 '13

[removed] — view removed comment

-2

u/[deleted] Sep 28 '13

[removed] — view removed comment

1

u/[deleted] Sep 28 '13

[removed] — view removed comment

1

u/[deleted] Sep 28 '13

I will not tolerate behavior like this from either of you. Be constructive and civil or don't come here.

2

u/[deleted] Sep 28 '13

Sorry, it was just such an opinionated hateful generalizing post, without any facts or reasoning whatsoever. Which I pointed out by writing the exact opposite opinion.

(He) never did make any point, but was just spurting opinions mixed with condescending language.

I'm perfectly fine with moderators not wanting this, it's just noise of zero value, and I'll delete these 3 posts if you want.

1

u/[deleted] Sep 28 '13

Just make sure not to let it happen on this subreddit again. I want this to be a good place for people who devleop on Linux. Flamewars over operating systems are not good. Thank you for promising to follow that guideline. And I believe I've removed the posts you made, unless they're still showing up.

2

u/[deleted] Sep 28 '13

Just make sure not to let it happen on this subreddit again.

Sure thing. ;)

→ More replies

4

u/kzr_pzr Sep 27 '13

Great explanation and a window to the history. I have to work with Linux audio at work (building HA clusters with "uninterruptible" audio output). It just causes me huge headache. Now I know a bit why it is so. Thank you.

BTW, we do stuff in old Java 1.5 which has its own oddities. Actually, you mentioned the worst one from my POV: while all 'standard' desktop apps use PulseAudio to interface the sound card, Java uses ALSA's device directly. There is no way to play sound from our Java app while a stream is playing in background. At one point, we had to use additional USB sound card with additional speakers to meet the project's specification.

2

u/wadcann Sep 28 '13

Actually, you mentioned the worst one from my POV: while all 'standard' desktop apps use PulseAudio to interface the sound card, Java uses ALSA's device directly.

In a distro with the virtual ALSA sound card set as default, the thing that routes back up to PulseAudio, you may be okay.

1

u/[deleted] Sep 28 '13

Today, I'm not sure how much there is to fix.

According to some game developers a lot. For instance the World of Goo Linux port, it was mentioned that audio timing was by far their biggest issue. That is some time ago now, but just a couple of days ago Valve also named audio as the biggest problem for developing Linux games.

Audio works fine for me, but I have an extremely simple audio setup, exactly because I can't configure it properly anyway, so I don't even use my M-Audio anymore, although it is superior to the Realtek HD I use now.

1

u/uep Nov 14 '13 edited Nov 14 '13

Honestly, from the perspective inside the kernel, I think ALSA is amazing. Its modular framework is impressive. It's crazy complicated, but it manages a ton of possible different combinations of hardware. If you hook things up in the right way, it handles a lot of redundant work for a driver automatically.

edit: grammatical sanity.

-3

u/caspy7 Sep 28 '13

If I'd gotten through all of this I'm confident I'd be telling you how good of an explanation this was.