# snd_hda, openal and 5.1 surround sound: No Sound on LFE / Subwoofer



## errorsmith (Jun 27, 2012)

Hi,

I managed to get 5.1 surround sound working on my FreeBSD 8.3 Box with PulseAudio. So when I watch a movie with VLC or Mplayer, I have sound on all speakers. Even stereo upmixing (for music and old movies without surround sounds) works fine. I tested this with several dolby trailers I found in the web [1] and a fiveptone.wav *i* also found somewhere online.

Unfortunately it doesn't work with openal. Most of the games I play utilize openal-soft from the ports to provide 3D sound. Whenever I launch a game I get sound on the front, rear and center speakers, but not on my subwoofer. The games I tested with include Alienarena, Warzone2100, Megaglest, 0ad, Unknown-horizons, Vdrift and Supertuxkart. All of them use openal and none of them is able to get sound onto the lfe channel. I also tested it with Mplayer, using the -ao openal switch and got the same results.

I tried to configure openal with 
	
	



```
drivers=pulse
```
 and with 
	
	



```
drivers=oss
```
 without success. I also tried the 
	
	



```
lfe remixing
```
 option in PulseAudio without success.

I would be happy if anyone can point me into the right direction here as my 5.1 surround system doesn't include full-range speakers and playing games without sound on the subwoofer sounds quite bad. 

*W*ith kind regards,
errorsmith

[1]http://www.demo-world.eu/trailers/dolby-trailers.php


----------



## mav@ (Jun 30, 2012)

For snd_hda(4) there is no difference between channels. LFE is the same channel as any other. It is not doing any channel mixing. Higher level of sound(4) can do some basic channel matrix conversion, and probably it could be hacked to make LFE channel to be sum of all others. But for proper result there should also some filtering be done to remove high frequencies from LFE and low from other channels. High-quality filtering is not cheap and not implemented for that purpose now, even though some equalizer code is present there. I've never used PulseAudio, so can't say whether it could be done there.


----------



## errorsmith (Jun 30, 2012)

Hi! Thanks for your reply.

I understand that snd_hda(4) doesn't do any channel conversion or similiar "magical" things. I can say that PulseAudio does upmixing if requested to do so. (e.g. from stereo to 5.1).

Indeed, if an audio source _has_ output on the lfe channel, PulseAudio transmits the audio properly to snd_hda(4) an*d* I can hear it on my subwoofer. If an audio source has less than 5.1 channels or no lfe channel, PulseAudio does some upmixing to put sound on the other speakers. I can listen to music with Clementine for example and have audio on all speakers, including the lfe. I think PulseAudio duplicates any missing surround channels and sums all audio onto the lfe channel. I can not say if it does any filtering. In the configuration files are two options, one to turn upmixing on and off in general, a second option to control if the upmixing should include the lfe channel.

My problem therefore seems to be related with openal only. It looks like openal opens 5.1 audio channels but never directs any sound onto the lfe channel. As the channel requested by openal was 5.1, PulseAudio doesn't upmix anything. As said before, the same problem exists when I use the OSS driver inside openal. As you already pointed out, snd_hda(4) doesn't do any upmixing either. (And even if it would do so, as openal requests 5.1 audio, even snd_hda(4) wouldn't do any upmixing.) When I configure openal to output only stereo sound, PulseAudio properly upmixes the audio to all six speakers. But only for stereo, 5.1 doesn't work for some reason.

So has anybody a hint for my what to do now to get 5.1 working with openal? I subs*c*ribed to the openal-soft mailing list but my post never appeared on the list, no idea why.

*W*ith kind regards,
errorsmith


----------



## mav@ (Jun 30, 2012)

I see two questions there: 1) why OpenAL doesn't use LFE? The answer is probably they just don't bother about it, as it is not mandatory. 2) Why PulseAudio can't do the same mixing for LFE even when original LFE is present. My external audio receiver perfectly does it for me after I've told it which speakers are small and set crossover frequency for filters.

Can't you configure OpenAL for 5.0 output to force PulseAudio to do 5.1 upmix? That would be correct solution IMO.


----------



## errorsmith (Jul 1, 2012)

Hi,

Why openal (I use audio/openal-soft wich is what most of my games require) doesn't use my lfe is my main question indeed  I'm not able to configure openal for 5.0 surround. My options are:

mono -> PulseAudio does upmixing
stereo -> PulseAudio does upmixing
quad -> weird speaker assignment, e.g. rear-left is routed to my subwoofer
5.1 -> as described above
5.1-side -> as described above
6.1 -> doesn't work
7.1 -> doesn't work
Additionally PulseAudio cannot be configured to set crossover frequencies or configure any filters here. I think if they make use of this stuff it*'*s hardcoded somewhere inside the code. (I will have a look at this later this day)*.*


----------



## mav@ (Jul 1, 2012)

I am not sure that OpenAL behavior is wrong about not using LFE. If compare it with 5.1 in movies, LFE channel is additional effect channel there. I don't think it should substitute other channels for low frequencies, but should extend them. It can't substitute them just because it doesn't know speakers configuration and capabilities and respectively can't have correct crossover frequency. So I still think it is PulseAudio or sound(4) duty to handle bass-redirection. From that point setting 5.0 audio stream configuration in OpenAL could hint them to do it.


----------



## errorsmith (Jul 1, 2012)

I think it IS openal's responsibility to direct sound to the lfe channel in the following scenarios:

5.1 test file fiveptone.wav with sound on the .1 lfe channel
a videofile with 5.1 surround sound
inside games: I think at least when something explodes like rockets in a shooter or artillery inside an rts game there shuld be sound on the lfe channel
In none of these cases openal does anything with the lfe channel. You're right about the lfe channel as extra effect channel. But especially in cases a and b I _should_ get sound on my lfe, shouldn't I? So in that case its openal's fault, isn't it? 

PulseAudio can't do anything about it because it is told by openal there would be 5.1 sound, so there isn't any need to do re/upmix the sound but openal just sends no data onto the lfe. Maybe it is the task of the sounddriver, sound(4) or snd_hda(1) to do this. 

I think this was called "bass redirection", at least "creative" called it so in the controls of its "soundblaster audigy 2 card". Rereading the manpages both of sound and snd_hda there seems no way to set any crossover frequencies or any other way to configure this. 

So I have two problems:

openal doesn't put sound on my lfe when it should (scenario a and b above)
the audio subsystem of FreeBSD is (not yet) able to do "bass redirection"
*R*ight? Any *i*deas? So far I think it would be the best to find a solution for the latter problem first, maybe there is no need to solve the second one  

regards, 
errorsmith


----------



## satsun (Aug 19, 2012)

Hello, one of the few to care about proper use of the LFE channel.  I found this on my endless search to find out why OpenAL *NEVER* uses the LFE channel [in games].  I believe I have determined that this is primarily an OpenAL issue and that for some reason PulseAudio doesn't do bass redirection with OpenAL games.

So I first came across this issue when I was playing Amnesia in Ubuntu.  I had played Amnesia in Windows and had LFE but why not in Ubuntu?  Come to find out that I was using bass redirection in Windows so I disabled that feature and went on an LFE testing rampage in Windows-based games.  No OpenAL games used the LFE channel while DirectSound, XAudio2, and FMOD games used the LFE channel; some games using those APIs didn't use the LFE but some did which leads me to believe that it's up to the programmer(s) to enable that feature.  Perhaps OpenAL outright lacks the ability to route low-frequency audio to the LFE or perhaps it would require a lot of additional programming to implement and no one cares enough to do it in their game.

I went back to Ubuntu to figure out how to do bass redirection and what I found was that, even though I successfully had bass redirection working in music by enabling LFE-remixing in the Pulse config file, it wouldn't redirect bass in Amnesia (with default PulseAudio as the device in Amnesia's settings).  Pulse should be able to redirect the bass if the audio is being routed through it but maybe it's not entirely understanding OpenAL and dropping the ball.

We know that the LFE is available in OpenAL because it plays that channel when you test a 5.1 wave file through it (I've at least done that in Windows with the dev software) but utilization of the LFE seems totally absent in games so it seems the only way to get any subwoofer activity from these games would be for the OS's audio system to do bass redirection.


----------



## satsun (Aug 19, 2012)

Also, I think the reason that OpenAL can properly process a 5.1 test wave file is because that file is BUILT AS a multi-channel wave file so OpenAL is just playing back what it's receiving in a very simple form.  Game audio effects are typically mono or stereo files that the audio API then chooses what to do with based on instructions given by the programmer.  If there is no way to tell OpenAL to route low frequencies in a one or two-channel sound effect to the LFE channel then the only other way to accomplish this effect would be to make a multi-channel audio file with the LFE specified in the audio file to which OpenAL would look at, say "hey, that's supposed to be routed to the LFE" and then route it.

I'm gonna go dig around in some games and see what format their sound effects are in.


----------



## errorsmith (Aug 20, 2012)

Hi

I successfully managed to get bass redirection by 

- splitting audio-input into 2 independent streams and
- combining all input on the first satream to mono
- applying filterplugins to the first stream to filter out freqs >= 150Hz
- applying more filterplugins to prevent clipping
- routing the output of this filterchain to lfe
- removing the lfe channel from the second stream
- applying filterplugins to filter out freqs my satellites can't handle 
- routing this 5.0 stream to the appropriate speakers

I switched off pulses internal bassredirection and tested this with several audio / video players and many different files and it worked much better as I thought it would. As a sideeffect I got a bit more "boom" on my lfe channel and as a bonus I had a configurable crossfrequency, wich I didn't had with the original redirection algorithm used by pulse.

Unfortunately openal refused to use my virtual sink but instead continued to use my soundcard directly, so I haven't got any further than this and deactivated the configuration mentioned above. 

As far as I see it, the problem is a two layer one: 

1. OpenAL soley depends on the audio streams it gets fed by the program and uses lfe *only* as the *effect-*channel but not as the general channel for lower frequencies as it is found in most of the consumergrade sound systems (no bass redirection at all). So if the programmer does not abuse the _effect_ channel for the general lower frequencies, OpenAL only does positional audio. 

2. OpenAL registers as a 5.1 sound-source with pulse. As it is registered as a multichannel sound-source, pulse doesn't do any sound-redirection by itself

As a result, the user doesn't get any sound on his lfe. D'Oh

As for sound in games, I can tell you that all the games rely on some softwareinterface to route sound correctly. This is much easier to implement as you can just feed mono-audio into the audio-api and leave it to the api to take care of: 
- the speakers the user has cofigured, 
- the postional audio / listener correlation and 
- any effects wich should be applied.



with kind regards,
errorsmith


----------

