Linux sound
This page is about Linux sound system, including device, peripherals, hardware support. For information regarding audio applications, file formats, see Linux audio.
References
- http://insanecoding.blogspot.com/2007/05/sorry-state-of-sound-in-linux.html
A summary of the situation back in the year 2007. - http://insanecoding.blogspot.com/2009/06/state-of-sound-in-linux-not-so-sorry.html
Same but updated to situation in 2009. A well of information! - http://4front-tech.com/hannublog/?p=5
Blog post explaining why closed source OSS is better than Alsa (back in 2007). - http://blogs.adobe.com/penguinswf/2007/05/welcome_to_the_jungle.html
A dependency graph between all sound systems, frameworks, libraries, etc in Linux (direct link) - http://www.linux-sound.org/midi.html
List of MIDI related softwares. Link seems dead, so here the Google cache link - http://alsa.opensrc.org/Main_Page
Unofficial wiki on ALSA. Lots of information. - http://www.alsa-project.org/main/index.php/Main_Page
Official ALSA wiki.- snd-hda-intel module (used by Intel/nVidia)
- Using the ALSA Sound System
Interesting post on using ALSA on Debian system, with lots of overview information. - LinuxQuestions.Org also has many interesting reference information on Linux sound system
Guides
To summarize:
Landscape
Here a summary of usual names we find in the Linux sound jungle along with their meaning/roles.
The sound systems (the real stuff that interface with the sound card. Today no apps should use these API directly but instead use one of the simple wrapper instead):
- OSS v3 — Open Sound System
- The original sound system on Linux, derived from the Sound Blaster driver API.
- The main limitation of OSS is that there was no software mixer (mixing was done by the soundcard) and so if your sound card did not support mixing in HW, then only one application could generate sounds.
- Closed Source
- OSS v4
- Open source again
- Full support of mixing
- Better latency (done in kernel)
- ALSA — Advanced Linux Sound Architecture
- A new sound system for Linux, including new set of API, kernel modules, etc.
- Support SW mixing
- Created after OSS went closed source
- Provide an OSS emulation layer for applications that still requires OSS
- Many advantages but many drawback as well (like OSS emulation does not support mixing, requires many additional lib like alsa-lib or jack)
The wrapper libraries (to support any sound back-end API, i.e. OSS/ALSA):
- SDL — Simple DirectMedia Layer
- Wrapper around OSS, aRTS and ESD.
- To allow running at the same applications that uses OSS, aRTS or ESD.
- OpenAL
- libao
The sound servers (Add mixing, considered useless today and adds lot of latency on top of the OSS/ALSA back-end):
- aRTS — Analog Real Time Synthesizer
- Old sound system for KDE environment
- Main goal was to cope with lack of SW mixing layer in OSS.
- ESD — Enlightened Sound Daemon
- Old sound system For Gnome/GTK environment
- Main goal was to cope with lack of SW mixing layer in OSS.
Pulseaudio
See Pulseaudio.
ALSA / OSS
ALSA
3 components:
- Drivers in the kernel
- Sound developer API
- Sound mixing component
Pros:
- Optional sound mixing outside the kernel
- Alsa support OSS v3 emulation
Cons:
- OSS v3 emulation has no mixing outside kernel (i.e. no mixing for old or other Unix'es apps when HW does not support mixing)
- Linux only (i.e. SW written to support other Unix'es will likely be written for OSS
- API too hard to work with
OSS
Now at version 4.
Pros:
- Sound mixing always supported
- Mixing in the kernel (so no latency issues)
Cons:
- Very bad ALSA emulation (but ALSA sound developer API can output to OSS directly, hence providing perfect ALSA compatibility).
Summary
- Both sound systems can output to either ALSA / OSS kernel back-ends.
- OSS back-end always has good sound, except when using OpenAL->ALSA to output to it.
- ALSA generally sounds better when using the OSS API, and has lower latency (generally because that avoids any sound mixing as per an earlier diagram).
- OSS related technology is generally the way to go for best sound.
- No application should use these APIs directly, but should use one of the light library wrapper instead.
Music Score Editors
Applications
Some music score editors in Linux:
- Frescobaldi
- Frescobaldi is a LilyPond sheet music text editor for KDE4. It aims to be powerful, yet lightweight and easy to use.
- Canorus
- Canorus is a free extensible music score editor. It supports note writing, import/export of various file formats, MIDI input and output, scripting and more! Using a Qt4 framework Canorus offers a fast and modern GUI and cross-platformability. Canorus runs on Linux, Windows and MacOSX.
- NoteEdit
- NoteEdit is a free music score editor for Linux. It supports an unlimited number and length of staffs, polyphony, a MIDI playback of written notes, chord markings, lyrics, a number of import and export filters to many formats like MIDI, MusicXML, ABC Music, MUP, PMX, MusiXTeX and LilyPond and more!
- MusE
- MusE is a MIDI/Audio sequencer with recording and editing capabilities written originally by Werner Schweer now developed and maintained by the MusE development team. MusE aims to be a complete multitrack virtual studio for Linux, it is published under the GNU General Public License.
- Rosegarden
- Rosegarden is a well-rounded audio and MIDI sequencer, score editor, and general-purpose music composition and editing environment. Rosegarden is an easy-to-learn, attractive application that runs on Linux, ideal for composers, musicians, music students, and small studio or home recording environments.
- MuseScore
- MuseScore is a free cross-platform WYSIWYG music notation program, that offers a cost-effective alternative to professional programs such as Sibelius and Finale. You can print beautifully engraved sheet music or save it as PDF or MIDI file.
- NtEd]
- NtEd is a GTK+ score editor. It intends to be really WYSIWYG: what you see on the screen is exactly what you get on printer output. It supports up to 4 voices per staff, drum notes, 5 lyrics lines, N-Tuplets, context changes, repeats with alternatives, configurable music instruments per staff, MIDI / MusicXML import, PS / PDF / SVG / PNG / Lilypond / MIDI export. Scores can be played through the ALSA sequencer.
Playing Midi
Information:
- Check NtEd FAQ for some links on how to play MIDI in score editors.
- PulseAudio interfers with TiMIDity
- Try to play MIDI with kmid first (not kmidi !!!). If it plays, then it should play fine in NtEd as well.
On ALSA:
- Check ALSA page dedicated to playing MIDI
- In particular, to play using a software synthesizer, use either TiMIDity or FluidSynth.
- One can also use gt utility to play MIDI files in surround sound.
On gStreamer:
- http://linuxtechie.wordpress.com/2008/02/29/gstreamer-plugins-bad-now-offers-midi-plugin/
- http://linuxtechie.wordpress.com/2008/01/22/how-to-ubuntu-midi-playback-with-audacious/ (related post)
Some software:
- TiMIDity++
- TiMidity++ is a software synthesizer. It can play MIDI files by converting them into PCM waveform data; give it a MIDI data along with digital instrument data files, then it synthesizes them in real-time, and plays. It can not only play sounds, but also can save the generated waveforms into hard disks as various audio file formats.
- Note that according to NtEd FAQ, PulseAudio creates bad interference with TiMIDity.
sudo apt-get install timidity
timidity /home/data/d/documents/desktop/_tidymeuprestricted/Ghostbusters.mid # Play a MIDI file
timidity -iA -B2,8 -Os1l -s 44100 # Run as MIDI server
- KMid
- Mid is a X11 / KDE based midi player for Linux and FreeBSD. KMid displays the text of karaoke files and change its colour as it is being played so that the tune can be easily followed ! It uses /dev/sequencer as output device supporting external synths, AWE , GUS and now also FM cards (such as sb16 or sbpro).
- WildMidi
- A GStreamer plugin to play MIDI files. Works fine along with RhythmBox for instance.
- Musica MIDI player
- Play MIDI on system with OSS sound card interface
- FluidSynth
- FluidSynth is a real-time software synthesizer based on the SoundFont 2 specifications.
Typesetting software
- LilyPond
- LilyPond is a music engraving program, devoted to producing the highest-quality sheet music possible. It brings the aesthetics of traditionally engraved music to computer printouts. LilyPond is free software and part of the GNU Project.
Devices
- /dev/snd
- /dev/snd is the audio device when using ALSA
- /dev/dsp
- /dev/dsp is the audio device when using OSS
lsof +D /dev/snd # Show which processes are using the device
Metronomes
Gtick
Gnome application. Easy to setup, but not very synchronous.
Kmetronome
Advanced MIDI based metronome. Requires a MIDI server.
First launch the server, for instance:
timidity -iA -B2,8 -Os1l -s 44100
Then start kmetronome
.
- Go into settings and select a MIDI server (Output port connection → TiMidity:0).
- Select a MIDI bank (Output instrument → General MIDI or anything else).
To play a standard metronome click, select Roland GS. Then in the pattern editor, select Metronome Click as Drum Key.
Tips
ALSA in multi-user, multi-card
See this excellent post: [1] Also: [2]
ALSA through HDMI
See XBMC.
Troubleshoot
References
Sound Issues in Linux
reference: SoundTroubleshooting on ubuntu.com.
Troubleshooting Alsa:
sudo aplay /usr/share/sounds/alsa/Front_Center.wav # Play a file as root
aplay /usr/share/sounds/alsa/Front_Center.wav # If it works, try as yourself
sudo addgroup <username> audio # ... add yourself to 'audio' group if you can't play the file
# But DON'T ADD TO 'audio' group if you are using PulseAudio!
sudo aplay -l # List all possible HW devices
sudo aplay -L # List all possible PCM devices (software devices)
lspci -v | grep -A7 -i "audio" # List all devices recognized as audio devices
aplay -D "plughw:0,7" /usr/share/sounds/alsa/Front_Center.wav # Play on a specific device (HW or PCM)
mplayer -ao alsa:device=hw=0 /usr/share/sounds/alsa/Front_Center.wav # Other way to play on a specific HW device (bypassing Alsa)
- audio group
- On Debian and Ubuntu systems, there should be no users in the audio group [3]
Top Five Wrong Ways to Fix Your Audio
See http://voices.canonical.com/david.henningsson/2012/07/13/top-five-wrong-ways-to-fix-your-audio/
Install jackd
See http://doc.ubuntu-fr.org/jackd. Nice advice on setting up audio, detecting audio issues.
Under-run when using play command
Trying to play a (small) sound file, we get no sound but a warning play WARN alsa: under-run
. Add option --single-threaded
does not help.
play --single-threaded /usr/share/games/xboard/sounds/woodthunk.wav
# /usr/share/games/xboard/sounds/woodthunk.wav:
#
# File Size: 1.89k Bit Rate: 182k
# Encoding: Unsigned PCM
# Channels: 1 @ 8-bit
# Samplerate: 22255Hz
# Replaygain: off
# Duration: 00:00:00.08
#
# In:100% 00:00:00.08 [00:00:00.00] Out:1.84k [!=====|=====!] Clip:0
# Done.
# play WARN alsa: under-run
The solution is to use paplay
!
paplay /usr/share/games/xboard/sounds/woodthunk.wav