ALSA related stuffs

A small japanese page is here.


What's New?


What's ALSA?

See ALSA project home page.


Some Documents on ALSA

The following documents are found in alsa-kernel/Documentation/DocBook directory, too. The files below are generated from them.

The following one is converted from a plain-text file in alsa-kernel/Documentation directory.


New Sequencer API

The sequencer API has been totally rewritten based on the concept of encapsulation. This is a way to hide the structure members from user space and give access only via the defined functions. The advantage of this method is its extensibility. Since the structure is opaque and its size is defined dynamically, even if we change the internal structure members or its size, the previously compiled code can run without any changes. The disadvantage is, of course, that it's not nice to look at, and slight overhead via function calls instead of direct access. But this could be improved via C++ wrapper or something like that..

The change from the old API style to the encapsulated style is like following:

There are some functions changed from the older version:

I've ported some applications for the new api (see below section). Both aseqview and vkeybd support the new api as default now. Also patch for pmidi 1.5.1 is available.


Patches for ALSA 0.9.0

Here are some patches to support ALSA 0.9.0.


Latency Test Tools for ALSA

The newer version of latency-test tool is available. It's for 2.6 kernel only, and uses RTC as the interrupt source.

About the latency on linux, please refer to this page. I hacked Benno's latency measurement tools for ALSA. Here is the one.


AC3play

My colleague, Werner Fink, extended/fixed Andy's ac3play. You can find the latest version here.


ALSA Dummy Library

Here is the dummy library for ALSA 0.9.0. This library provides libasound.so.1 which returns simply errors on all ALSA 0.5.x API, so that the older programs can even run without complaining unresolved symbols. If you are using KDE, you'll need probably this stuff. The RPM packages below for ALSA 0.9 already includes this library.

IMPORTANT: Please install this library before installing the ALSA 0.9.x library. This will overwrite /usr/lib/libasound.la.



ALSA Sequencer Synchronization

[Updated!] See THIS PAGE.


ALSA RPM Packages for SuSE

I've made unofficial RPM packages of ALSA releated stuffs for the SuSE distribution. The packages had been put on this web page for a while but now they are on suse ftp server to avoid the version conflict. Please refer to ftp://ftp.suse.com/pub/people/tiwai or its mirrors.

Now there are also RPM packages for ALSA 0.9. The packages are built only for suse 7.2, since it takes fairly long time to compile all the stuff (and the ALSA is being changed everyday, as you know :) You can find them at ftp://ftp.suse.com/pub/people/tiwai/alsa9-packages .


TiMidity as ALSA sequencer client

[2000/07/14]
The ALSA sequencer patch was already merged to TiMidity++ main tree. Get the latest source from here.

The ALSA sequencer interface is the interface of timidity to create ALSA sequencer ports with real-time response. You may play MIDI upon ALSA sequencer system without wavetable like Emu8000/10k1.

For enabling this interface, configure TiMidity with --enable-alsaseq option. Of course, you need to enable ALSA audio :-) Thus the minimum configure example becomes:

	% ./configure --enable-audio=alsa --enable-alsaseq

The ALSA seq interface is invoked when -iA option is specified to timidity. Eventually the -Bx,y option is required for reduction of latency, where x is the fragments and y is the bits of audio buffer size. In both cases, smaller numbers result in faster real-time response. Typically, -B2,8 is enough. This specifies two fragments with 256 samples.

	% timidity -iA -B2,8 -Os -EFreverb=0
In this example, the reverb effect is disabled, because it eats lots of CPU power. You may also turn off chrous effect via -EFchorus=0 if less CPU usage is preferred.

Then you'll get an output like this:

	Timidity starting in ALSA server mode
	Opening sequencer port 128:0 128:1
This shows that timidity created ALSA sequencer ports 128:0 and 128:1.

For hearing MIDI music, run pmidi to send events to this port:

	% pmidi -p128:0 foo.mid
Yes, it's an overkill :-) (Originally, you can listen to MIDI music directly via timidity, of course.)

For connecting MIDI keyboard input to timidity,

	% aconnect 64:0 128:0

This interface tries to reset process priority as SCHED_FIFO and as high as possible. This is allowed only for root.
Thus you need to invoke timidity as root or install the timidity binary with setuid root.
The SCHED_FIFO'd program shows much better real-time response.

Timidity loads instruments dynamically at each time a PRM_CHANGE event is received. This causes sometimes pauses during playback. It occurs often in the playback via pmidi. Furthermore, timidity resets the loaded instruments when the all subscriptions are disconnected. Thus for keeping all loaded instruments also after playback is finished, you need to connect a dummy port (e.g. midi input port) to timidity port via aconnect:

	% aconnect 64:0 128:0

If you prefer a bit more fancy visual output, use my tiny program, aseqview (see below).

	% aseqview -p2 &
Then connect two ports to timidity ports:
	% aconnect 129:0 128:0
	% aconnect 129:1 128:1
The outputs ought to be redirected to 129:0,1 instead of 128:0,1.

THE LATEST PATCH

Here is the latest patch to 2.10.4. It includes the support of ALSA 0.9.0 with the new sequencer API.


RTC High Frequency Timer Patch

RTC has a nice high-frequent interrupt capability up to 8192 Hz. Although this can be used (on the recent kernel) even from userspace via fasync signals, it is not allowed to use the interrupt from kernel. This is the very reason of this patch.

This tiny patch adds a hook to the RTC driver in linux kernel. A callback function is called at each interrupt. For changing frequency, starting and stopping interrupts, use rtc_control function.

The older version of this patch had more functionalities than the current version, for example, multiple callbacks with different frequencies are allowed. From this patch, however, I intensionally removed these things, because of simplicity. Only one callback can be used exclusively (even to user-space). That is, if a kernel driver (e.g. ALSA RTC timer) registers the callback, no other threads can use RTC interrupt. /dev/rtc cannot be opened during it.

The patches are prepared for 2.2.16 and 2.4.0 kernels. Since SuSE-7.0 distribution includes its own patch to RTC already, further patch is prepared separately. Please note that these patches are already included in the latest ALSA CVS (0.6.0) under alsa-drivers/utils/patches.


Old Patches

The following patches have been already included in the ALSA CVS main stream.

Patch to CVS-1999-01-20:

The patch enables us to use wavetable synth on Emu10k1 (SB Live!) chip. It works just like Emu8000 (SB AWE 32/64) cards but with more voices (64 maximum). As well as Emu8000 chip, you'll need to load SoundFont files via OSS emulation using sfxload program. The sfxload can be obtained from my page.

The known bugs are as follows:

Please note that this patch may cause problems to Emu8k driver, because many parts were rewritten to share the common routines.

Patch to CVS-1999-12-16:

Patch to CVS-1999-09-20:

Patch to CVS-1999-09-17:

Patch to CVS-19999-09-08:


Programs

ASeqView - ALSA Sequencer Event Viewer

ASeqView is an ALSA sequencer user-client which works as event viewr. It visualizes received events, e.g. note-on/off, controls, pitch wheels, using bar graphs, as often seen in many sequencer programs. Using this viewer, even a simple command line sequencer like pmidi or playmidi1 becomes a cool one with graphical interface :-)

Another feature of ASeqView is redirection of events. ASeqView can output the received events to subscription ports with some modification like channel mute or pitch change. Since this works as a real-time filter client, such modifications can be applied also in real-time without complexity.

The latest version (0.2.3) includes the piano view support (thanks to Patrick Horn). See the screenshot below.


Virtual Keyboard

This program is originally for AWE32/64 driver on OSS/Free, but it works now on ALSA, too. Start the program with --device alsa option. Then, connect this client to any ALSA port by aconnect utility, for example,

% aconnect 128:0 65:0
Alternatively, you can use --addr 65:0 option to connect directly from vkeybd.


Test / demo programs

Some demo programs for ALSA sequencer. Most of the part has been impelemented in aseqview. I just show this for test only.


Brief Notes about ALSA Sequencer


Some Old Documents




Links


Takashi Iwai tiwai@suse.de; Go to My Home Page