Inhaltsverzeichnis

Linux Sound and Audio

Overview

  compressed audio file: ogg, mp3
  ↓
CODEC library: Mplayer, Gstreamer, Xine
  ↓
  raw audio
  ↓
[optional mixer: Esound, Pulseaudio]
  ↓
  raw audio
  ↓
sound card driver: ALSA, OSS

Source: http://tuxradar.com/content/how-it-works-linux-audio-explained :

You have RAW audio data and sound card. For sound card you need driver, hence this is what ALSA and OSS do.
RAW»>ALSA(Sound card)

Now RAW can be compressed either lossy or lossless, so it eats much less space. So you have CODEC libraries. Either monolithic all-in-one like Mplayer, flexible like Gstreamer or some weird mix like Xine(which can only decode).
Compressed(like .ogg)»>Decoders(Mplayer, Xine, Gstreamer; sound now RAW)»>ALSA(Sound card).

Now imagine you have several applications, which try to output sound at once(two audio players). One of them can lock the card and prevent other to get it. This is only partially negliable with ALSA, as it has very basic mixing module - dmix, but its unable to mix audiostreams of different Hz and rates. Also with pure ALSA nothing prevents app to reserve audio card for itself(adobe flashplugin anyone?) So you need a sound server - PulseAudio. Even if you dont need networked sound server, Pulse mixes, sets volumes and prevents takeover. It is musthave unless you have only ONE audio application running. With pulse, audio streams are also easy to manipulate incl. channels, output to several cards etc. Pulse incorporates a lot of ways to capture audio output from applications. Libraries that allow applications to handle sounds, like OpenAL, SDL; decoders like Mplayer, Gstreamer and Xine should always be build with PulseAudio output, and HAVE ALSA OUTPUT REMOVED! Because Pulse also has possibility to capture someone trying to output to alsa directly, but this makes audio travel: App»Alsa»Pulse»Alsa, instead of App»Pulse»Alsa. Famous cracking is result of this missconfiguration. Build pulse with alsa support, remove alsa from everywhere else and add pulse sink instead. This is how pulse is set up.

Compressed(like .ogg)»>Decoders»»PulseAudio»>ALSA(one or many soundcards) or networking

ESD is not discussed, since it does what Pulse does - better mixing, but only for apps that support it (few) and thats it. Its being replaced by Pulse. Depricated.

Phonon is just a universal sound interface for Qt apps. Its nothing more than this. Set it to pulse audio as default sink or keep it alone if you use ONLY kde apps for sound output. Qt is not Linux or ALSA only, hence the need for Phonon as universal backend. It does for Qt, what SDL does for games.

JACK is nice thing that allows to route audio streams between applications in weirdest ways possible. Apps have to be JACK-enabled. Only musicians need this and you can combine JACK with Pulse; JACK handles routing between apps and drops final stream to Pulse.

Pretty much thats it.
Gstreamer is most advanced coder/decoder stack.
Pulseaudio is most advanced mixer and point-and-click sound manager.
ALSA is driver stack.

SDL, OpenAL are just sound playback libraries. Make sure they have ALSA or PulseAudio as output(depending on what you use) and forget them.
Phonon is Qt/KDE audio gateway, nothing more.

Alsa

Test sound

aplay -D hw:1 /usr/share/sounds/KDE_Logout_new.wav

Basic setup

  1. Start alsamixer as root; configure, quit with ESC
  2. alsactrl store

Source: /etc/rc.d/rc.alsa and Bootmessages; amarok home page has also infos about alsarc configuration

Multiple Sound Cards

List Sound Cards

aplay -l
alsamixer → F2 → /proc/asound/cards

Select Sound Card with aplay

Examples:

aplay -D hw:1 /usr/share/sounds/KDE_Logout_new.wav
aplay -D hw:PCH /usr/share/sounds/KDE_Logout_new.wav

Permanently select default Sound Card

FIXME A good place to start is probably at /etc/asound.state

Mplayer

Select output driver

As of Slack 14.4 Pulse is active, but mplayer still uses Alsa as output. In order to avoid detours (see above), change this permanently to pulse by editing /etc/mplayer/mplayer.conf :

ao=pulse

Older CLI examples for alsa (before pulseaudio)

mplayer -ao alsa:device=hw=1 or
mplayer -ao alsa:device=hw=1.0 or
mplayer -ao alsa:device=hw=PCH or
mplayer -ao alsa:device=hw=PCH.0 or
  1. /etc/mplayer/mplayer.conf:

ao=alsa:device=hw=1

Steaming throuh Socks Proxy

The following command line plays a radio stream through a local socks5 proxy listening on port 1080:

curl --socks5 localhost:1080 http://ibizaglobalradio.streaming-pro.com:8024 | mplayer -quiet -cache 1024 -

You might experiment a bit with the cache size or not need to use the cache at all.

Dump audio to wav file

mplayer -ao pcm <file>|<url>

Webcam viewing / testing

mplayer tv://

Source: http://www.linuxtv.org/wiki/index.php/MPlayer#Using_MPlayer_for_Webcam_Viewing

Slave mode

http://www.mplayerhq.hu/DOCS/tech/slave.txt

Mixer

As of Slack 14.2 Pulseaudio is included and activated by default.

CLI frontend: pamixer GUI fromtend: pavucontrol

It is not recommended to make /etc/rc.d/rc.pulseaudio runnable. Normally pulseaudio will start automatically as-needed with an instance per audio user.

Bluetooth

In order to channel audio from any source to an external speaker or headset via bluetooth, first make /etc/rc.d/rc.bluetooth runnable and start it as root.
Now start the blueman-manager GUI to connect to the remote device.

The pavucontrol GUI allows you to route the sound to the according remote device. You might need to check the button „Set as fallback“ for that output device.

Attic / obsolete

mixer: alsamixer (,rexima, amixer)
rec -V -c 2 -r 22050 spanisch2.wav
  -V fuer verbose, siehe man sox
  -c fuer 2 Kanaele,
  -r 22050 ist halbe Cd-Abtastrate, ausgetestet, dies führt zu einer nicht zu grossen wav-datei bei vernünftiger Qualitaet
  xmms blur scope hilft beim einstellen des Aufnahmelevels
  Die Aufnahme kommt über igain (rexima) rein (Slack9.0), dies auf 100% setzen und den Lautstärkelevel am Walkman einstellen
  rec verwendet offensichtlich standardmäßig /dev/dsp als device, das es dies bei master11 nicht öffnen kann (Permission denied)
  rec & play gehören zu sox
Aufnehmen mit alsa
  arecord ist wie rec von alsa
  alsamixer
        Die Aufnahme kommt über Line rein. Line auf 100% & Capture auf 40% setzen, beide unmuten & beide mit Spacetaste als Aufnahemquelle auswählen.
  arecord -v -f cd spanish3.wav
  Lautstärkelevel am Walkman voll aufdrehen.

Further Infos

Linux audio explained, Sound Howto