Sign in to follow this  
bencelot

OpenAL - no distance attenuation on Vista?

Recommended Posts

Hey all, For some unknown reason, when I play my game on my new computer (vista) there is no distance attentuation. By this I mean sounds SHOULD be quieter the further away they are from the listener object.. however, on my new computer they are not - they play at maximum volume no matter what the distance. I know this isn't a problem with my game logic, because when I play the game on my older computer (xp) there IS distance attenuation, which means that I've set up the listener and source objects correctly. So I don't know if it's a Vista thing.. or just this specific computer.. but something is going wrong. Because running the exact same executable on these 2 computers is producing different results. Furthermore, when I ran it on both computers, I was including these 3 necessary files in the same folder as the .exe: alut.dll OpenAL32.dll wrap_oal.dll So it should be using the same .dll files as well! I tested that it actually was using each of these files by removing each one of them separately and trying to the run the program, and it wouldn't work. So I know that it's not using some version in system32 or something. Anyway, same executable, same .dlls.. different computer, different result. It's weird I say.. DAMN WEIRD!! Any ideas? Thanks, Ben.

Share this post


Link to post
Share on other sites
What OpenAL device is it using? It's nice that manufacturers can write their own OpenAL drivers, but I've had some problems with buggy ones in the past. Try forcing DirectSound by renaming wrap_oal.dll to OpenAL32.dll, or do away with those DLLs and install the redist.

Share this post


Link to post
Share on other sites
What do you mean by OpenAL device?

I just got my friend who also has Vista to test this distance attenuation, and he had the same problem.

I went to the openAL website and found this link regarding Vista and OpenAL:

http://connect.creativelabs.com/openal/OpenAL%20Wiki/OpenAL%C2%AE%20and%20Windows%20Vista%E2%84%A2.aspx

It didn't really provide any solutions.. but had this to say:

"
OpenAL on Windows Vista
As already stated above, Microsoft® will be removing DirectSound 3D Hardware support from Direct X with the launch of Windows Vista. DirectSound and DirectSound3D will still function; however, they will no longer use hardware acceleration.

The native OpenAL devices on Sound Blaster Audigy and Sound Blaster X-Fi™ soundcards do not use DirectSound or DirectSound 3D and so they will be completely unaffected. For games that use these devices, nothing will change. The game will continue to enjoy hardware based 3D audio and effects.

The Generic Hardware device will no longer be available, as it requires the use of hardware DirectSound 3D Buffers. Instead, this device will gracefully, and automatically, fallback to using the Generic Software device, which will continue to work as before.
"


I'm not entirely sure what to make of this.. but would this suggest that I'm using "The Generic Hardware" device, which is why I'm not getting the nice 3D sound that I require?


Share this post


Link to post
Share on other sites
This page talks about the different OpenAL devices.

I must admit that I've never really played with "Generic Software" (aka DirectSound non-3D), so I don't know if OpenAL does implement positional audio with it. I may have to do some tests.

Share this post


Link to post
Share on other sites
I suggest to use OpenAL Soft implementation of OpenAL. It is pure software library, that does not depened on hardware features to caluclate how your sound should sound (it does not use DirectSound3D). If I remember correctly Creative OpenAL depends on DirectSound3D for 3D positional sound.

Share this post


Link to post
Share on other sites
Ok, cool.

I looked into that a bit but there were a few things I'm unsure about.

1) Is it portable (windows, unix, mac).

2) Does it have any annoying licensing issues (or at least.. more annoying than OpenAL)

3) How do I install it on windows? All I found were those tarball things..


Thanks,
Ben.

Share this post


Link to post
Share on other sites
1) I know that it can be build on Windows and Linux. MacOSX have their own standart OpenAL implementation (it is present in any MacOSX installation). And I think you should use that one.
2) It is LGPL licensed. So shared library is ok with whatever license you are using with your code. Static library will force LGPL (or GPL) on your code.
3) Just build dll using CMake & MSVC. Read Installing section on its page. And put OpenAL32.dll file beside your exe file. No need to install it.

Share this post


Link to post
Share on other sites
Ok, well I think I figured out how to build it with CMake and Visual C++.. I configured it to Release and it successfully compiled.

I replaced the existing openal32.lib in C:\Program Files\Microsoft Visual Studio 9.0\VC\lib with the new openal32.lib. I also replaced the existing openal32.dll with the new one, and have it sitting next to my exe.

I recompiled my game with the new lib, and that worked. I double clicked on the game with the new dll, and that worked too. Everything was going fine until I started playing and there was no sound.. and now I don't know what to do.

I still have wrap_oal.dll and alut.dll sitting alongside my exe and openal32.dll, and I haven't changed any of my code. Could these be the problems? Do I have to change any of my code, or remove/updated either of the other 2 dlls?

Thx,
Ben.

Share this post


Link to post
Share on other sites
You don't need wrap_oal.dll anymore. OpenAL32.dll build from OpenAL-Soft is all you need.
alut.dll will probably work with it (but I don't know, I have never used alut).
What are you using from alut? Device opening or context creation? Maybe try to get rid of it and open device/create context directly with alc functions.

Also try checking alGetError() result after some functions (after creating source/buffer objects, after starting playback).

Share this post


Link to post
Share on other sites
Don't need wrap_oal.dll.. that's a relief. That thing took up too much space.. I like my games nice and compact. :)


As for alut, it is causing an error..

alutInit(0,NULL);
cout << alGetError() << endl;

displays:

40964

It should display 0.. I couldn't find what that error means, but there's something wrong because it used to display 0 before I switched to OpenAL soft.

As for alut.. I'm only actually using these 4 lines throughout the entire program:

alutInit(0,NULL);

alutLoadWAVFile((ALbyte*)filename, &format, &data, &size, &freq, &loop);
alutUnloadWAV(format,data,size,freq);

alutExit();

So maybe I can just ditch it. Do you know how I'd go about replacing these 4 lines?



Thanks a lot, by the way, you've been very helpful.

Ben.


Share this post


Link to post
Share on other sites
40964 means AL_INVALID_OPERATION. Look up error codes in al.h header. This means alut can not initialize OpenAL properly.

Try to replace alutInit(0,NULL) with:

ALCdevice* al_device = alcOpenDevice(NULL);
ALCcontext al_context = alcCreateContext(al_device, NULL);
alcMakeContextCurrent(al_context);



and alutExit() with:


alcMakeContextCurrent(NULL);
alcDestroyContext(al_ontext);
alcCloseDevice(al_device);



As for WAV loading - there is no replacement in OpenAL core library. That is why there exists alut library. But if everything works with changes above then leave wav loading as is. If not - you can try to load wav file manually (or find another library on net).

Share this post


Link to post
Share on other sites
Hmm, well I tried that but it didn't compile.


ALCcontext al_context = alcCreateContext(al_device, NULL);

gives this error:
error C2079: 'al_context' uses undefined struct 'ALCcontext_struct'

seems very strange.. I have no idea where ALCcontext_struct came from.



I did some research and alut is meant to work with openal soft.. yet for some reason I'm always getting that error, when I try to use alutInit(NULL, NULL):

"There was an error opening the ALC device"


I'm including these 3:

#include <al/al.h>
#include <al/alc.h>
#include <al/alut.h>

I think perhaps I just compiled it wrong? I don't know where though. After compiling, all I need to do is replace the library and the dll files, right? There's no headers that I need to include?


Share this post


Link to post
Share on other sites
Ahh, that was it. It compiled.. but still no sound.


I don't think it's an alut problem, either. Because I'm getting an error here:

ALuint soundID;
alGenBuffers(1, &soundID);
if (alGetError() != AL_NO_ERROR)
{
cout << "ERROR: " << alGetError() << endl;
return 0;
}

outputs:

ERROR: 40964 (AL_INVALID_OPERATION)

Which has nothing to do with alut. So I must have done something else wrong.. I tried building the libraries again though, but no change.

Is there anywhere I can get the latest binaries from?




Share this post


Link to post
Share on other sites
From the main OpenAL Soft webpage:

Installing
To install OpenAL Soft, first extract it. It will automatically extract itself into the openal-soft-<version>/ directory. Using your favorite shell, go into the CMakeConf/ directory, and run:
cmake ..
Assuming configuration went well, you can then build it, typically using GNU Make (KDevelop, MSVC, and others are possible depending on your system setup and CMake configuration).



I find this very confusing. Why is it necessary to have to go through these steps anyway? There must be a reason.. it just seems like it'd be so much simpler if a few simple binaries were created to choose from.

Anyway.. after doing what I THINK these instructions are telling me (although how I'm meant to know what CMake configuration I'm meant to use I don't know), I end up with and opengl32.dll of size 80kb, and an openal32.lib of size 27 kb.

Does this sound right? I'm using the latest version of openal soft: 1.5.304.

Share this post


Link to post
Share on other sites
Actually it is very simple. It is made so that author need to maintain only one file (CMake build file) instead of many different compiler projects for different operating system variants. Different project files (MSVC project, GCC makefile, ...) can be generated from CMake build file. And from these project files you can simply build program/library. It would be just more work for author to maintain, build and publish many different binaries and project files.

80kb size is ok, if you are building with shared C++ runtime (linking to msvcrXX.dll file).
Have you tried to build & run openal-info project which is also generated? Does it work?

One more thing - you can not call alGetError() like you are calling it. First call will reset internally stored error code and next call will not report actual error. It is similar to how glGetError() works.

You should call it only once when you want to check & display it:
int error = alGetError();
if (error != AL_NO_ERROR)
{
cout << "ERROR: " <<error << endl;
return 0;
}


Are you sure you are calling alGenBuffers function after alcOpenDevice/alcCreateContext/alcMakeContextCurrent functions? Also check al_device and al_context variables - they should not be NULL.

Share this post


Link to post
Share on other sites
Ahh, ok.. that makes sense.


No improvements though.. using the proper debug shows the same result:


/** MAIN **/
int main(int argc, char **argv) {

//alutInit(0, NULL);
ALCdevice* al_device = alcOpenDevice(NULL);
ALCcontext* al_context = alcCreateContext(al_device, NULL);
alcMakeContextCurrent(al_context);

if(al_device == NULL) cout << "AL_DEVICE DOWN!!!!" << endl;
if(al_context == NULL) cout << "AL_CONTEXT DEMOLISHED!!" << endl;

int error = alGetError();
if (error != AL_NO_ERROR)
{
cout << "ERROR: " <<error << endl;
}


shows:
AL_DEVICE DOWN!!!!
AL_CONTEXT DEMOLISHED!!
ERROR: 40964


whereas if I simply replaced the openal soft 80kb openal32.dll with the old one, it works perfectly (except on Vista, of course). So it must be the dll, right?



Now.. perhaps a bit of a clue.. I built openal-info.. but when I double click the exe a console window opens and closes instantly, and nothing is displayed. I'm guessing that's not meant to happen?

Furthermore, where is msvcrXX.dll meant to be located? I checked system32 and it wasn't there.. then I scanned my entire computer for it and it didn't show up either.. could this be the problem? If so, how would I build it without this?


Thx, Ben.

Share this post


Link to post
Share on other sites
Ah, now I probably know problem - do you have DirectX SDK installed? Because OpenAL Soft needs DirectSound headers and lib from DXSDK to compile. It is its default sound output under Windows. alcOpenDevice probably fails because there is no devices available (openal-info.exe should show that).

Quote:
Now.. perhaps a bit of a clue.. I built openal-info.. but when I double click the exe a console window opens and closes instantly, and nothing is displayed. I'm guessing that's not meant to happen?

You should run it from command line. It is command line application - it displays some info, and then terminates.

With msvcrXX.dll I meant msvcr90.dll or msvcr80.dll depending which Visual Studio you use (9 for 2008, and 8 for 2005).

Share this post


Link to post
Share on other sites
Ahh, I see. Silly me :)
Using cmd.. openal-info.exe displays:

ALC error Invalid Context occured



As for DirectX SDK being installed.. I don't know. Probably not, as I haven't done any work with direct x. I suppose I should install that. Will installing this affect the openal32.dll build? Or will it be required to run my game?

When I distribute my game, I don't want users to have to install all these extra dependancies.. how does it work, anyway? Is all the necessary code from directX SDK and msvcr90.dll built into the openal32.dll which can then be distributed with the game? All I want to distribute is my exe, openal32.dll, and alut.dll (and of course a data folder with all my textures, etc..).

Anyway, I'm going to install DirectX SDK now.. I'll let you know how it goes.. but if you could clear up the dependancies issue that'd be great.. I've always been confused about that.

Share this post


Link to post
Share on other sites
hmm.. well something happened! But it's not pretty :p


I downloaded the 463MB SDK from here, and installed it:

http://www.freewarefiles.com/downloads_counter.php?programid=14055

I then deleted everything.. went back into CMake 2.6, and repeated the entire process again.

I don't know if this means anything do you but I used these (default) Cache Values:

ALSA: ON
CMAKE_BACKWARDS_COMPATIBILITY: 2.4
CMAKE_BUILD_TYPE: RelWithDebInfo
CMAKE_INSTALL_PREFIX: C:/Program Files/OpenAL
DLLOPEN: ON
DSOUND: ON
EXAMPLES: ON

OSS: ON
WERROR: OFF
WINMM: ON


Anyway.. it created an openal32.dll of size 83kb! Which means something happened, no doubt because of the directX install.

HOWEVER... things are now worse. On this computer (XP, with the directX SDK installed), I was able to run my game with sound, using the new openal32.dll. The problem is.. I now have the exact same original problem happening on this computer - there is no distance attenuation!

And even worse.. when I copied my exe, alut.dll, and the new openal32.dll across to my newer computer with Vista on it.. the program didn't even run!

I got an error saying:
"The application failed to initialize properly (0xc0150002)"


I then tried to run the openal-info.exe on my Vista computer.. and that didn't work either.. I got:
"The application has failed because it's side-by-side configuration is incorrect."

Which from memory has something to do with dependancies or something..

oh how confusing.

Btw, openal-info.exe seems to work fine on this computer now.



Share this post


Link to post
Share on other sites
Those errors which you got on Vista computer probably is because there is no C runtime library installed (msvcr.. dll file).

Quote:
Original post by bencelotWill installing this affect the openal32.dll build? Or will it be required to run my game?

Yes, and yes. But DirectSound is included in Windows by default, at lest starting with Windows XP.

If you want for OpenAL32.dll file to not depend on shared C runtime library, then you can build it with static C runtime library. Change Runtime Libary option in Visual Studio when you are building OpenAL. It can be found in Project -> Properties -> C/C++ -> Runtime Library. Set it to "Multi-threaded". With this option OpenAL will not depened on msvcr..dll file.

Share this post


Link to post
Share on other sites
Yes that's right.. Multi-threaded did the trick. It now runs on the vista computer, as does openal-info.exe.

So progress has been made.. I'm now using openal soft, without wrap_oal.dll on both computers.

The problem now.. is that BOTH computers have no distance attenuation.. whereas originally it was only the Vista computer. But because we're using openal soft.. this can't be a hardware issue, right?

Would I be required to change any of the actual code? Perhaps the default distance attenuation model of openal soft is different from normal openal?

On both computers, openal-info.exe displays the same thing. Here are a few that might be relevant?

Default device: DirectSound Software
ALC version: 1.1
OpenAL extensions:
AL_EXT_EXPONENT_DISTANCE, AL_EXT_FLOAT32, AL_EXT_IMA4, AL_EXT_LINEAR_DISTANCE, AL_EXT_MCFORMATS, AL_EXT_OFFSET, AL_LOKI_quadriphonic


It seems that AL_EXT_EXPONENT_DISTANCE and AL_EXT_LINEAR_DISTANCE are extensions? Perhaps I have to call one of them differently to how I was previously.. I'll experiment a bit.


Btw, just a few questions about dependencies:

1) You say that Direct Sound is required to run the game.. and that it's on all windows computers (or at least XP). And yet I had to download and install a 400+MB DirectX SDK. So this means that the dll's are on all windows computers.. but the headers aren't? So to compile the program I need DirectX SDK.. but to run the program, all I need is the default dlls?

2) When it comes time to port the game to linux and mac, openal soft will simply ignore directX and use whatever those operating systems use, right? Does this mean I'll eventually have to download other header files for the other operating systems and recompile again?

Thx,
Ben.

Share this post


Link to post
Share on other sites
1) yes, DXSDK is needed only for compiling OpenAL Soft.
2) for linux - yes you will need to recompile it. DSound will not be used. As for MacOSX, I already told previously - it has good OpenAL implementation from Apple itself. So no need for OpenAL Soft there. Just use default headers and libs on macosx.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this