Linux Audio Programming

Status
Not open for further replies.

Sbodd

Ars Tribunus Militum
1,847
Hi all, lurker coming out to ask a question :)

At my job, we're working on porting a massive system from HP-UX 10.20 to Red Hat Linux (I believe we're using Red Hat 7.2, kernel version 2.4.2). I've been tasked with porting the audio portion of our code. I initially tried to use the OSS library, but it doesn't appear to meet our needs very well.

The existing code is designed to receive audio data over a socket (in approximately 1/2 second units), place it into a circular queue in shared memory, and have a second process read from that queue and pass the data to the sound card.

The problem I'm running into is that, when the source of the audio data changes, the time it takes for the actual audio output to change can be as much as 15 seconds. At least some of that delay occurs after I attempt to clear the data that's already been written to /dev/dsp. OSS doesn't appear to have an effective way to cancel buffered data (I've tried SNDCTL_DSP_RESET - it simply doesn't work on our system, from what I can tell), or to query the amount of data remaining in the buffer.

On the HP platform, we're using HP's Aserver, and waiting for an AETDataNeeded event before passing the next half-second of data. This provides acceptable latency.

So, what I'm looking for is an audio library for Linux that meets the following requirements:
-Low latency
-Ability to clear out buffered data
-Ability to query the state of the buffer -OR- something similar to an AETDataNeeded event.
-Has drivers for the Creative SB Live! card.
-Has at least decent documentation - this is the first time I've ever done any audio coding.

If anyone has any suggestions (pref. with URLs), please reply :)

Thanks!

-Sbod
 

Prototyped

Ars Legatus Legionis
11,126
You know, libao would have been perfect for this, since it deals with the OSS, ALSA (to become the dominant API in the next major Linux release, replacing OSS), aRts, ESounD, etc. and abstracts away the specifics. Unfortunately, it's GPLed, so you probably cannot legally use it in software whose source you intend not to release to the public at large.

There's KDE's CSL, that supports just OSS (which ALSA can emulate — ALSA is by far the more advanced architecture) and the aRts multiplexing daemon, but the issue is that it has no support for ALSA's native API or ESounD (another multiplexing daemon, not quite as advanced as aRts, but older and more widely supported), but it's better than having to deal with specifics yourself. And tools like <tt>esddsp</tt> will allow basic OSS-style sound output to be channelled through ESounD anyway.

_tiny_,

ALSA is the future dominant sound API. Currently, OSS dominates, since the sound drivers that come with the kernel follow that API. There are plans, however, to incorporate the ALSA drivers instead into Linux 2.6.

(The reason aRts and ESounD are significant, despite being user-space processes themselves, is that most drivers are currently not written to enable multiple channels at once, so these daemons will multiplex sound streams in software into a single PCM audio channel. This also means that once one of these daemons is running, it will usually have exclusive access to the audio device, so that ideally, sound applications will be aware of the possibility of either of these daemons running, and automatically connect to them, instead of trying to just access /dev/dsp or /dev/audio and giving up when an EBUSY is received. aRts is automatically started with the popular desktop environment KDE, and ESounD is automatically started with the other popular desktop environment GNOME, so they are significant.)

<hr />

Since you do have control over the drivers you can use, go with ALSA, but try to find a library that can abstract away details of the sound layer you use — it might hurt latency ever so slightly, but if you discover, for some reason down the road, that you cannot feasibly use ALSA, your software isn't tied to it.

[This message was edited by Prototyped on May 02, 2002 at 16:15.]
 

Tegid

Ars Legatus Legionis
12,810
Subscriptor
Do you have a link referencing libao? I work with Sbodd (though I'm not on his task) and the GPL only requires that we give source to our customers, which we do anyhow, so that isn't a problem. (I'm writing this since I'm at a computer with net access and he isn't) I've found it's freshmeat entry so I have access to it, but docs and general information doesn't seem to be available on the listed homepage.

We are not running either KDE or GNOME, do aRts or ESounD require them, or are they just defaulted to run with them?
 

Prototyped

Ars Legatus Legionis
11,126
http://www.polarhome.com/service/manual/libao-devel-0.8.0/

I'd be very wary of the GPL requirement. IIRC, it states or implies that you'd have to agree to release your software under the GPL if you were to link against a GPLed component (libao), and that implies that, while you need not offer the software or its source to the public at large, your customers may offer at least the source freely, since the GPL requires free redistribution.

You might still be able to work out alternative licensing terms with the author(s).

wrt aRts and ESounD, they're included as part of GNOME and KDE respectively, but do not require GNOME or KDE to run. (I happen to run aRts and ESounD standalone on my systems, with ESounD started by <tt>artsdsp</tt>, so ESounD output channels through aRts.)

[This message was edited by Prototyped on May 02, 2002 at 19:04.]
 

Prototyped

Ars Legatus Legionis
11,126
/me slaps own head for not having remembered this earlier

There's an arguably better library available known as SDL, or Simple DirectMedia Layer. While it handles both video and audio, it allows for fine control of the audio subsystem, and abstracts away the specifics. Even better, it's licensed under the LGPL, so there's much less risk.

It can wrap OSS, ALSA, aRts and ESounD, along with sound systems on other platforms.

http://www.libsdl.org/
 

Tegid

Ars Legatus Legionis
12,810
Subscriptor
We are having a bit of trouble getting our soundcard configured for ALSA. We are running a vanilla SBLive! When we try and follow through the installation instructions and get to the part where we are supposed to a)set up the modules.conf and then b)run modprobe snd-emu10k1 we get errors saying there is no such device. (And a tag saying that such errors may be caused by incorrect module paramaters for IO or IRQ values. (The SB doesn't seem to accept IRQ or IO values in it's modules.conf entry)

There don't seem to be examples for this fairly common card. I will look around, but I figured if you knew, it would be a hell of a lot faster.

Thanks.
 
Status
Not open for further replies.