Need urgent help/pointers with ALSA programming

Discussion about everything. New games, 3d math, development tips...
Post Reply
eye776
Posts: 94
Joined: Sun Dec 28, 2008 11:07 pm

Need urgent help/pointers with ALSA programming

Post by eye776 »

First of all, sorry for asking this question here. I lurked around for a bit and saw that
the community is pretty knowledgeable, so here goes.

Oh crap, how do I even begin ?

I got employed not too long ago and my employer has currently (T)asked me to port an Android game to
a device running Linux (under NDA).

The device has a horrendous sound API and I had to fix this, and I did, after finding out the SDK has libasound (ALSA),
by dynamically linking Audiere with the project after fixing the ALSA device and it worked great.

My employer's lawyers problem is that Audiere is LGPL and they want to hear none of it.
And they already refused to let the devs use OpenAL for Android, but android has the AudioTrack class.

So I have to, pretty much write a minimal sound library using only ALSA (and whatever other non LGPL
or GPL libraries I can find, if any) and can do the following:
1) Mix up to 4 sounds
2) Supports panning
3) Supports streaming
4) Supports ogg files

I've read the tutorial that explains 16bit PCM 44.1 KHz playback with ALSA alone, and it's already a bit too much to take in.

Do you guys know of any BSD/MIT libraries that can do what I need ?
Or some ALSA documentation that's geared to someone who's NOT necessarily a sound engineer ?
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Need urgent help/pointers with ALSA programming

Post by hendu »

What a bunch of hypocrites, those lawyers. FYI, libasound is LGPL.
eye776
Posts: 94
Joined: Sun Dec 28, 2008 11:07 pm

Re: Need urgent help/pointers with ALSA programming

Post by eye776 »

Yes, well a lot of lawyers act like double-faced crooks (it's a job requirement for them :D).

Also, I know libasound is LGPL, but since "it comes with the SDK", in the lawyer's own words, and these guys have a private marketplace
that somehow makes it "only the distributor's concern and not ours" (it's not Google, nor Apple).

Anyway, does anyone know where I can find some info about hardware mixing in ALSA, or should I go the standard route and software
mix in a clamped buffer (-32768, 32767) and then use snd_pcm_writei().
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Need urgent help/pointers with ALSA programming

Post by hendu »

If your app links to a LGPL lib, it is your concern no matter where the lib comes from.

I have no alsa experience, but I think the lib should handle it for you, just send as many channels as you want. Perhaps a sw mixer mode needs to be specifically enabled when the hw does not do mixing.
eye776
Posts: 94
Joined: Sun Dec 28, 2008 11:07 pm

Re: Need urgent help/pointers with ALSA programming

Post by eye776 »

Okay hendu, please take no offense but, first of all this is what my employer needs of me, and under the current economy I can't really refuse.
IIRC it is legally my employer's concern, not mine, so if the lawyers want ALSA, they shall get ALSA.
A lot of sample code I found seemed to be released under the GPL and didn't take any chances with it; and since I can only use sample code
released under BSD/MIT/zlib or public domain, I didn't exactly find out a lot about actually programming with ALSA.
Now, can we please not discuss legalese anymore since IANAL; also I have nothing anything against LGPL or GPL and in my private
projects I always comply with LGPL or GPL if I happen to use one such library
.

Now, back to the topic, ALSA is NOT like OpenAL at all.
From what I found out until now, you can initialize a pcm_handle struct and write a buffer to it (that respects the initialization rules) so I did this, and can play one sound at a time.
Now, there are a lot of functions with the word "mixer" in their name, that are almost completely undocumented. Does anyone know how to use these ?

Right now I have a number of arrays of shorts, obtained by either stripping the RIFF header off a WAV file, or by decoding an OGG file through libtremor.
Now, should I 1) "software mix" them together into a single buffer (the hack job way) OR 2) if approach (1) is bad, how do I use ALSA mixers ?

EDIT: FINALLY, I COULD CRY TEARS OF JOY, I FOUND A SOUND LIBRARY THAT'S NOT LGPL (IT'S MIT) AND SUPPORTS DYNAMICALLY LINKING AGAINST ALSA!!!
GOING TO WORK TO TRY IT OUT!!! Hopefully I might just not have to learn more of ALSA than I need to anymore.
Post Reply