# 5.1 Surround with ALSA and OpenAL. [ALSA VoIP added]

## floam

I've put up a how-to on getting 5.1 surround working with ALSA and games that use OpenAL. (read: UT2003, UT2004, ArmyOps, etc.) This works on my Sound Blaster Live 5.1, am not sure how ALSA handles other cards.

http://floam.ascorbic.com/how-to/alsa5.1

Comments / suggestions appreciated.

Note (2004/02/17): The openal-cvs noted in the artical has been updated with a VoIP patch for ALSA and UT2004.

Newest openal-cvs ebuild here: http://floam.ascorbic.com/gentoo/openal-cvs-20040314.tar.bz2

Also changed guide to include mixer settings and slightly different .openalrc for UT2004 Voice support.

----------

## floam

The guide had a bad link in there that was probably messing people up, fixed now.

----------

## ARC2300

Didn't work for me at all.

I'm on a CS46xx chipset with the 2.6 kernel.

----------

## Peaceable Frood

Your chipset mostlikely has to have 5.1 support on the chip and in the driver.

----------

## floam

Yeah, I was pretty sure this would only apply to the emu10k1.

----------

## Moofed

Works for me with my cmi8738!  The mixer part is emu10k1 specific, but the Openal part should be useful for anyone that can play dvds in 4.0 or 5.1 sound.  The mixer settings for other 8738 users are Exchange DAC ON, Four Channel Mode OFF.

edit:  It seems alsa has cleaned up multichannel support in the cmipci driver: the Exchange DAC option has been removed. 5.1 and 4.0 sound Just Works (for me).Last edited by Moofed on Sun Jan 04, 2004 4:43 pm; edited 1 time in total

----------

## OverrideX

Of course, openal-cvs is failing to compile for me now:

```

xp -Os -pipe -fforce-addr -fomit-frame-pointer -falign-functions=4 -mfpmath=sse  -I/usr/include/SDL -D_REENTRANT -I/usr/include/smpeg -I/usr/include/SDL -D_REENTRANT -fPIC -Wall -W -Wbad-function-cast -Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wimplicit-function-declaration -Waggregate-return -Winline -Wpointer-arith -fno-common -ansi -Wno-redundant-decls -c arch/esd/esd.c -o arch/esd/esd.o

arch/alsa/alsa.c: In function `set_write_alsa':

arch/alsa/alsa.c:218: error: too few arguments to function `snd_pcm_hw_params_get_channels'

arch/alsa/alsa.c:229: warning: passing arg 3 of `snd_pcm_hw_params_set_rate_near' makes pointer from integer without a cast

arch/alsa/alsa.c:257: error: too few arguments to function `snd_pcm_hw_params_get_buffer_size'

arch/alsa/alsa.c:260: warning: passing arg 2 of `snd_pcm_hw_params_get_period_size' from incompatible pointer type

arch/alsa/alsa.c:260: error: too few arguments to function `snd_pcm_hw_params_get_period_size'

gmake[1]: *** [arch/alsa/alsa.o] Error 1

gmake[1]: *** Waiting for unfinished jobs....

gmake[1]: Leaving directory `/var/tmp/portage/openal-cvs-3/work/openal/linux/src'

make: *** [all] Error 2

```

using gcc 3.3.2-r4 - anyone else having this problem? any fixes?  :Smile: 

----------

## floam

Update: ALSA 1.0 support is now in openal cvs, rejoice!

What version of alsa are you using? If you are using 1.0.0rc2 you will need to edit alsa.c a bit in the openal cvs tree.

Edit: Well this is kind of weird, I should have been able to put 

```
#define ALSA_PCM_OLD_HW_PARAMS_API

#define ALSA_PCM_OLD_SW_PARAMS_API
```

before

```
#include <alsa/asoundlib.h>
```

in alsa.c to make it work, but then it fails in alsa.c on /usr/include/alsa/pcm.h, which is weird. Maybe someone smarter than me can look into it?

----------

## Kirschsaft

 *floam wrote:*   

> What version of alsa are you using? If you are using 1.0.0rc2 you will need to edit alsa.c a bit in the openal cvs tree.
> 
> Edit: Well this is kind of weird, I should have been able to put 
> 
> ```
> ...

 

This seems to work again after the following steps.

1. Open your openal_dir/linux/src/Makefile

2. Search the CFLAGS

3. Remove "-ansi" from CFLAGS

4. Save the file and try to build OpenAL.

This seemed to work on my machine at least.

----------

## neenee

hm.. i can not find this Makefile you speak of.

*update* found it

/var/tmp/portage/openal-cvs-3/work/openal/linux/src/Makefile

*update* i tried editing both the Makefile and alsa.c,

but it fails to compile for me at pcm.h as well.

"/usr/include/alsa/pcm.h:655: error: syntax error before string constant"

(and on many other lines)

----------

## Kirschsaft

 *neenee wrote:*   

> 
> 
> *update* i tried editing both the Makefile and alsa.c,
> 
> but it fails to compile for me at pcm.h as well.
> ...

 

What did you do after editing the Makefile? "emerge openal-cvs"? Then you have to edit /var/tmp/portage/openal-cvs-3/work/openal/linux/configure.in as well, since configure will put the "-ansi" in place again otherwise. Open the configure.in and go to line 171. It should contain "WFLAGS="$WFLAGS -ansi"". Remove the -ansi and rerun the ebuild. 

I didn't had to do this step, because I built openal without portage.

----------

## neenee

i tried the following:

i edited:

/usr/portage/distfiles/cvs-src/openal/linux/src/arch/alsa/alsa.c

/var/tmp/portage/openal-cvs-3/work/openal/linux/src/arch/alsa/alsa.c

and added the two defines mentioned in a post above.

then, i edited both the Makefile and the configure.in.

but the error with pcm remains.

*update* now i compiled openal-cvs manually, using

info from the ebuild, and injected the stable openal,

so that it is no longer called.

i still would like to get this 'proper' way going though  :Wink: 

----------

## floam

Update: ALSA 1.0 support is now in openal cvs, rejoice!

You don't need to (and probably shouldn't) edit the files in /var/tmp. You can go to /usr/portage/distfiles/cvs-src/openal and edit the files there before you start the emerge, cvs will manage them being different and stuff. Also, jvalenzu in #openal says he's looking into finding a new maintainer of the alsa backend.

----------

## neenee

wow. it worked now i edited the

files in the proper location.

thanks floam  :Wink: 

----------

## Merlin-TC

I have the same error but it seems like I am too dump....

I downloaded the latest CVS and the the change in the makefile removing the -ansi from the cflags.

I also tried to edit the alsa.c but it still didn't work.

Am I missing something? :O

I really don't know what I am doing wrong.

I'd really appreciate your help.

----------

## floam

Update: ALSA 1.0 support is now in openal cvs, rejoice!

Merlin-TC: Use my openal-cvs ebuild and this patch: http://opensource.creative.com/pipermail/openal-devel/2004-January/000199.html

Emerge openal-cvs, wait for it to die, apply patch in /usr/portage/distfiles/cvs-src/openal/, and then emerge openal-cvs.

----------

## Merlin-TC

OK, I am editing this the third time now  :Wink: 

I got it to compile ok I think and just symlinked the libopenal.so to the ut2003/system directory as openal.so.

But now it segfaults  :Sad: 

```

bin: pcm.c:963: snd_pcm_writei: Assertion `pcm->setup' failed.

Backtrace:

[ 1]  ./Core.so [0x40a1071a]

[ 2]  [0xffffd420]

[ 3]  [0x6]

[ 4]  /lib/libc.so.6(abort+0x1d7) [0x40bcb3a7]

[ 5]  /lib/libc.so.6(__assert_fail+0x109) [0x40bc3289]

[ 6]  ./libSDL-1.2.so.0(snd_pcm_writei+0x74) [0x4007ff50]

[ 7]  ./openal.so(alsa_blitbuffer+0x56) [0x44c4bdb6]

[ 8]  ./openal.so(_alcDeviceWrite+0x52) [0x44c4e0e2]

[ 9]  ./openal.so(async_mixer_iterate+0x126) [0x44c381c6]

[10]  ./openal.so [0x44c4c85e]

[11]  /lib/libpthread.so.0 [0x40dd78ac]

[12]  /lib/libc.so.6(__clone+0x5a) [0x40c72efa]

Signal: SIGIOT [iot trap]

Aborting.

```

Any ideas?

----------

## floam

Update: ALSA 1.0 support is now in openal cvs, rejoice!

Merlin-TC. This is the same error I am getting. You will get this if you use a kernel patched to ALSA 1.01. If you want to try getting it fixed, go complain to the openal mailing list and hopefully something will happen soon. :-/

----------

## Merlin-TC

hey floam,

thanks for your reply.

I thought it's a mistake on my end.

Guess we will just have to wait then.

----------

## soroh6

Just a couple questions in regard to your ~/.openalrc --

```
(define speaker-num 4)

(define devices '(alsa))

(define alsa-device "surround40:0,0")
```

Now, I've never used OpenAL but I figured I'd install this anyways 'just in case' one day.  :Smile: 

First, the define speaker-num -- I have 5.1 speakers (fronts, rears, center + sub [as I'm sure you already knew this]) .. should I set speaker-num to 5?

Second is the (define devices '(alsa)) .. is that a parse error with the apostrophe?

Thanks.

----------

## floam

soroh6: That's not a parse error, and while you can set it to surround51 and set speaker number to 6, you wont notice a difference, since no games make special use of the center channel.

----------

## gebner

 *floam wrote:*   

> soroh6: That's not a parse error

 

It's actually meant to prevent the lisp interpreter to execute the "alsa" function and to get a list containg only the element alsa instead.

----------

## soroh6

Thanks for the replies.

----------

## floam

Looks like ALSA 1.0 support was added yesterday to cvs, yay :) Everyone is going to want to delete their alsa.c (and makefiles if one chose that route to fix it) and refetch. Maybe wipe out the entire directory if not sure what exactly's been tampered with.

----------

## Moled

heh

i'm not sure if this was the lastest aa patch, or swapping the openal.so over, but in americas army, the last special forces training mission, the person that gives you your briefing in the helecopter sounds as if hes taken a bit too much helium? :p

----------

## floam

Moled: others are getting stuff like that in Unreal Engine games with ALSA 1.0. It's an OpenAL issue if I recall, you may want to post something to the OpenAL mailing list.

Information here: https://forums.gentoo.org/viewtopic.php?p=813198&highlight=#813198

----------

## Moled

no, I swapped it back and it wasn't ok

i've not played the game in quite a while tho

I don't have access to my 5.1 speakers atm, so can't really test it

where did you get the info of the contents of the .openalrc from?

i'm interested in this now, see what it can do  :Razz: 

----------

## floam

Moled: Got openalrc info off google and people on irc. Also, ut2003 seems to be working with latest openal from cvs and 2.6.2-rc1-mm1

----------

## iDeJ

hi

i think i'm to stupid to emerge openal-cvs-3  :Sad: 

after reading some portage relatet how-to's

i've copied the ebuild into /usr/portage/openal-cvs-3 and if i type

emerge openal-cvs-3 i get

root@matrix idej # emerge openal-cvs-3

Calculating dependencies

!!! Problem in openal-cvs-3/openal-cvs-3 dependencies.

!!! "Specific key requires an operator (openal-cvs-3/openal-cvs-3) (try adding an '=')"

----------

## floam

 *iDeJ wrote:*   

> hi
> 
> i think i'm to stupid to emerge openal-cvs-3 :(
> 
> after reading some portage relatet how-to's
> ...

 You need to uncomment the PORTDIR_OVERLAY line in your make.conf, and put it in /usr/local/portage/media-libs/openal-cvs/. Though maybe if you can't figure it out you shouldn't use it.

----------

## iDeJ

thx for helpe, openal emerged just fine (after i have unmerged my old openal installation)

but the only difference is that i have no sound in ut2k3-demo

also if i mute Audigy Analog/Digital Output Jack i get no sound at all  :Sad: 

just a hint, an

ln -s /opt/ut2003-demo/System/openal.so /usr/lib/libopenal.so will not work, cuz libopenal.so itself is a symlink to /usr/lib/libopenal.so.0.0.6 (in my case)

but i've still a problem, in ut i get only sound out of the 2 boxes behind me  :Sad: 

the other ones are quiet  :Sad: 

and if i disable the Audigy Analog/Digital Audio Jack i have no sound (nowhere in my system)

i've an Audigy2 Card and the build-in Alsa Driver in my 2.6 Kernel

what could be wrong?

----------

## floam

 *iDeJ wrote:*   

> just a hint, an
> 
> ln -s /opt/ut2003-demo/System/openal.so /usr/lib/libopenal.so will not work, cuz libopenal.so itself is a symlink to /usr/lib/libopenal.so.0.0.6

 Just a hint, we are making a symlink from /usr/lib/libopenal.so to /opt/ut2003/System/openal.so, not from it. You messed up your sound and will need to do it the way I explain in the howto and reemerge openal-cvs.

----------

## iDeJ

hi,

no soory, just mixed it up in this thread  :Smile: 

after reemergin openal "libopenal.so" is a symlink to "libopenal.so."

 *Quote:*   

> 
> 
> root@matrix idej # ls -l /usr/lib/ | grep openal
> 
> -rwxr-xr-x    1 root     root       418378 Jan 30 11:26 libopenal.a
> ...

 

 *Quote:*   

> 
> 
> root@matrix idej # ls -l /opt/ut2003-demo/System/ | grep openal
> 
> lrwxrwxrwx    1 root     root           27 Jan 30 11:28 openal.so -> /usr/lib/libopenal.so.0.0.7
> ...

 

if i make a symlink to openal.so or openal.so. i get no sound at all, with libopenal.so.0.0.0.7 i get only sound out of the two boxes behind me

----------

## floam

Do you have your mixer settings set properly, turned up? (Specifically Wave and PCM.)

----------

## iDeJ

i think, yes

but i don't know what all this EMU10k1 PCM/EMU10k! PCM Send/EMU10K1 PCM Send Routing means, so it could be that there is one mistake  :Sad: 

a snapshot of my mixer settings  :Smile: 

[url]

http://www.badsooden.de/bilder/mixer.jpeg

[/url]

----------

## floam

IDeJ: Try muting the "Audigy Analo... Output Jack" in your second mixer window. Also unrelated you have Tone muted, if you unmute that the Bass/Treble sliders you have next to it will work.

----------

## iDeJ

if i do so i have no sound at all

XMMS(Alsa Plugin)/KDE/UT2k3, nowhere, even with aplay  :Sad: 

----------

## floam

IDeJ: Are you attempting to get your sound via digital out or something?

----------

## iDeJ

nope, normal Ananlog connection  :Smile: 

could it be that i have to use other settings with an Auduigy2?

or that i have mutet something wrong?

i mean, all 6 boxes are working just fine, only with the 4.0 settings in ut and ArmyOps i getting problems

----------

## floam

So if you mute the digital/analog toggle (which tells it to do analog) , you can get normal sounds outside of ut2003?

----------

## iDeJ

if i haven't got it mutet and i haven't got a .openalrc in my home dir, then i have normal sound, if i have it mutet i have no sound at all

----------

## Angrybob

what do i stick in my .openalrc file if I want to use my 7.1 analog speakers, or is that not supported...?

----------

## floam

Check to see if surround71 is available. 

```
ls /usr/share/alsa/pcm/
```

Edit: Even if it were available, you'll need to keep speakers at four and use surround40. I found out today that OpenAL can't handle any more than that.

----------

## floam

I've updated the ebuild to apply Mercury's ALSA capture patch, it should allow voice to work with alsa in ut2004. Be sure to read the entire page noted in the postinst, and note the patch is very new and probably wont work for you.

----------

## eNTi

i have a sblive! and i tried the openal thingy, but i'm stuck. i've made a link from /usr/lib/libopenal.so to <UTDIR>/System/openal.so and my sound was gone. completely. is there a way to check, if one's setup is working?

----------

## Moled

shouldn't the link be the other way around?

----------

## eNTi

i did ln -s /usr/lib/libopenal.so <utdir>/System/openal.so. is this correct? it should be.

----------

## floam

Not sure what your problem is. Do you have alsa in your USE, setup the .openalrc? In other news, wolf31o2 is replacing the openal ebuild in portage with mine (including voip stuff), but making it a snapshot and hardmasking it, so soon it'll be even easier for people to get this stuff working (hopefully)

----------

## Moled

have you read this?: http://icculus.org/~warp/ut2004/

----------

## floam

I'm about to update the ebuild again. Warp (Mercury) has released a new patch, this one fixes all the choppiness issues with voip (finally, people can hear me perfectly with ALSA!) and gets rid of the slow downs while holding F (VoiceTalk). Also going to include fixes that wolf31o2 made to the ebuild (Snapshot version in portage and hardmasked now)

----------

## floam

Okay the new ebuild is up, but note, when I released the one on the 17th, I screwed up and named it 20040317, instead of 20040217. If you used the ebuild from two days ago when you update to todays it'll think it's downgrading, don't worry, it's not.

http://floam.ascorbic.com/gentoo/openal-cvs-20040219.tar.bz2

----------

## Merc248

hmm... latest ebuild doesn't seem to work.  here's what i get:

Calculating dependencies ...done!

>>> emerge (1 of 1) media-libs/openal-cvs-20040219 to /

>>> Unpacking source...

 * Fetching CVS module openal into /usr/portage/distfiles/cvs-src...

 * Running  cvs -q -f -z4 -d ":pserver:guest:guest@opensource.creative.com:/usr/local/cvs-repository" login

Logging in to :pserver:guest@opensource.creative.com:2401/usr/local/cvs-repository

 * Running  cvs -q -f -z4 -d ":pserver:guest@opensource.creative.com:/usr/local/cvs-repository" update -dP openal

 * Copying openal from /usr/portage/distfiles/cvs-src...

 * CVS module openal is now in /var/tmp/portage/openal-cvs-20040219/work

>>> Source unpacked.

esd

sdl

alsa

mpeg

oggvorbis

alsa

RUNNING FROM extra_functions.sh

 * Applying full.diff...

 * Failed Patch: full.diff!

 *

 * Include in your bugreport the contents of:

 *

 *   /var/tmp/portage/openal-cvs-20040219/temp/full.diff-26605.out

!!! ERROR: media-libs/openal-cvs-20040219 failed.

!!! Function epatch, Line 360, Exitcode 0

!!! Failed Patch: full.diff!

----------

## eNTi

 *floam wrote:*   

> Not sure what your problem is. Do you have alsa in your USE, setup the .openalrc? In other news, wolf31o2 is replacing the openal ebuild in portage with mine (including voip stuff), but making it a snapshot and hardmasking it, so soon it'll be even easier for people to get this stuff working (hopefully)

 

what do i have to link to what?

edit: tried the new ebuild and got the same error as merc248.

----------

## floam

Okay guys, Warp/Mercury got cvs access and merged some of his changes into cvs, so patch no longer applies. I'll update the ebuild right now.

Edit: http://floam.ascorbic.com/gentoo/openal-cvs-20040221.tar.bz2

Also, Mercury has confirmed that the ALSA VoIP now performs better than OSS! (as far as choppiness and how it scales at low fps)

----------

## Merc248

for some reason, the sounds in UT2004 now sound extremely sped up. ;\

i've set my .openalrc file exactly the way you have it in the guide (i have a 5.1 surround sound set), plus i soft linked the libopenal.so file from /usr/lib to the system directory of ut2004.

----------

## eNTi

maybe my problem is, that i only have 4.1 and no surround?

----------

## eNTi

it's working now... strange, must have been wrong alsamixer settings. sound's great. good job floam.

----------

## floam

Merc: I'd reccomend you to read http://icculus.org/~warp/ut2004 and try a few of the things it wants you to do, notably the libsdl stuff.

----------

## Merc248

sweet... it works perfectly now.  thanks  :Smile: 

oh yeah...  how did you have the sound coming from all 5 satellite speakers?  im wondering how to get that to work as well...  only works out of 4 for me (which i assumed is the correct way for it to be since .openalrc defines it as so, but it seems like you got it working out of all 5).

i only have mic boost and audigy analog/digital output jack on.  when i turn off the digital/analog output jack, there's absolutely no sound.

----------

## floam

OpenAL doesn't support more than four speakers, but ALSA should make Center and LFE get sound. Turning off the Digital/Analog output jack causes the rear speaker jack to output in analog. I wonder, are you getting discrete sound out of your rear speakers with it on? (Test by shooting a rocket at a wall, and turning around really quick, you should hear it from rear speakers since the explosion is behind you)

----------

## Merc248

yeah... each channel sounds seperate from each other.  :Smile: 

only problem is that the sound doesn't output to my center speaker, nor does it output to my headphones connected to my audigy 2 frontplate.

----------

## eNTi

with a sound blaster live! (4.1, non-surround) you can't get surround sound. maybe there IS a way to emulate it for games. i think it works in windows, but i've never really tried that. altough there are is a "surround" lever in alsamixer, it really only mirrors the front speakers. i've tried all kind of possible settings without luck. without the "surround" lever you won't get anything out of your rear speakers. the "wave surround" does virtually nothing to games, but enhances my rear sound, if i'm listening to music. 

maybe it's time to get another soundcard. i had a audigy 2 a few weeks ago, but it made only problems (more so in windows, than in linux) and before i sent it back it crashed my pc, before i could even get to my bootloader. audigy 2 is by far the worst sound card i've ever had. i'm very disappointed with creative.

----------

## floam

Updated ebuild with a new patch from Mercury. (Supposed to make velocity and pitch work, might raise sound quality.)

http://floam.ascorbic.com/gentoo/openal-cvs-20040304.tar.bz2

Also updated the guide a bit to mention replacing libsdl.

----------

## floam

Okay, updated again, there were some changes in cvs so a new patch was required. http://floam.ascorbic.com/gentoo/openal-cvs-20040314.tar.bz2

----------

## TazG

I want to read your howto but ascorbic.com redirects me to Google!

?

----------

## weichafe

 *TazG wrote:*   

> I want to read your howto but ascorbic.com redirects me to Google!
> 
> ?

 

Idem for me. 

Can you fix it?

----------

## TazG

 *TazG wrote:*   

> I want to read your howto but ascorbic.com redirects me to Google!
> 
> ?

 Please, can this be fixed??

----------

## floam

This guide is pretty much obsolete. People with Creative cards should go read the Hardware Accelerated OpenAL post.

----------

