View previous topic :: View next topic |
Author |
Message |
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Sun Mar 05, 2006 11:42 pm Post subject: OpenAL Trouble |
|
|
I'm having trouble getting OpenAL to play anything. I'll return to work on Ogg Vorbis support sooner or later, but I have a physics of sound project due in about a month and I want to make sure that I can at least have something to present. So at this point I'm loading a WAV file (seems to work flawlessly) and then trying to get it to play back through OpenAL.
In C++, it's as simple as this...
Code: | #include "al.h"
#include "alc.h"
#include "alut.h"
#include "stdio.h"
int main(void)
{
ALint error;
ALsizei size, freq;
ALenum format;
ALvoid *data;
ALboolean loop;
ALuint iBuffer;
ALuint iSource;
ALint state;
ALCdevice *g_currentDevice = alcOpenDevice(NULL);
ALCcontext *g_currentContext = alcCreateContext(g_currentDevice, NULL);
alcMakeContextCurrent(g_currentContext);
alGenBuffers(1, &iBuffer);
alutLoadWAVFile("action.wav", &format, &data, &size, &freq, &loop);
alBufferData(iBuffer, format, data, size, freq);
alutUnloadWAV(format, data, size, freq);
alGenSources(1, &iSource);
alSourcei(iSource, AL_BUFFER, iBuffer);
alSourcePlay(iSource);
alGetSourcei(iSource, AL_SOURCE_STATE, &state);
while(state == AL_PLAYING)
{ alGetSourcei(iSource, AL_SOURCE_STATE, &state);
}
alDeleteSources(1, &iSource);
alcDestroyContext(g_currentContext);
alcCloseDevice(g_currentDevice);
return 0;
}
|
However, derelict doesn't have bindings to alc.h and behaves exactly as if a context wasn't ever created. I looked through the D bindings in /trunk and I didn't find anywhere that a context was created. I'll gladly translate alc.h to D if it's what's needed to make this work (always wanting to help). If not, does anyone have a working OpenAL example with D?
Here's a link to my test project
And in an attempt to make myself useful, here are some bugs and bugfixes I found:
Line 194 of almanual.d should be "typedef bool function(ALuint) pfalIsSource;" and likewise, line 49 of alstatic.d should be
"bool alIsSource(ALuint);" I believe the current return types are void.
There's a documentation bug on line ~48 on all of the example.d files. "Using DMD on Windows..."
Also, on Linux (Mandriva 2006), my OpenAL library is named libopenal.so.0 and libal.so doesn't seem to exist. I've had similar naming glitches with OpenGL and SDL also. Copying and renaming seems to fix the problem in most cases. |
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Thu Mar 09, 2006 7:09 pm Post subject: |
|
|
I've added ALC support to almanual.d and updated alctypes.d with some minor changes to get everything to work. As with ALU, you can initialize ALC with a call to DerelictAL_LoadALC(). I've added comments highlighting everything I've changed; these can be removed if you want to add these to the trunk, aldacron. I haven't touched alstatic.d since it's newer and I haven't spent the time to see what's going on with it.
And I haven't tested most of the functions and I haven't tested it at all on Linux (I probably will eventually), but
Code: | ALCdevice *g_currentDevice = alcOpenDevice(null);
ALCcontext *g_currentContext = alcCreateContext(g_currentDevice, null);
alcMakeContextCurrent(g_currentContext);
// Regular OpenAL calls
alcDestroyContext(g_currentContext);
alcCloseDevice(g_currentDevice);
|
works with no errors and I'm now that I can create a context I can play sound data that I load. And to me, this makes all the difference. I may work on Ogg Vorbis support next.
Oh, and you can download my changes here. Just replace the existing files in the OpenAL directory and run the buildme script to create the import library.
Edit: I've noticed a bug with the loop below. I get a Stack Overflow error when it gets to about the 86000th iteration. Could the call be corrupting the stack somehow?
Code: | do
{ alGetSourcei(iSource, AL_SOURCE_STATE, &state);
}while(state == AL_PLAYING)
|
|
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Tue Mar 14, 2006 11:33 pm Post subject: |
|
|
Ok, this is weird.
Any time that I compile with the optimize flag set, if I make a call to an OpenAL function, I get an access violation; but everything works beautifully non-optimized. In addition, I've noticed before that enabling optimization sometimes removes some of my loops as if they weren't there at all, but if I put them inside a try-catch block, everything is normal. I just now put my openAL inside a try-catch (empty catch) and now it runs normally and plays sound. Weird.
I've also noticed that the latest version of dmd has trouble with delete a, b, c; and forces three separate deletes. I really need to make my way over to digitalmars and submit some bug reports. |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Wed Mar 15, 2006 11:10 am Post subject: |
|
|
JoeCoder wrote: | Any time that I compile with the optimize flag set, if I make a call to an OpenAL function, I get an access violation; but everything works beautifully non-optimized. In addition, I've noticed before that enabling optimization sometimes removes some of my loops as if they weren't there at all, but if I put them inside a try-catch block, everything is normal. I just now put my openAL inside a try-catch (empty catch) and now it runs normally and plays sound. Weird.
|
The optimize flag does seem to have unusual side effects. I've seen similar trouble reported before in other projects. Optimize is just not reliable at this stage of the game.
JoeCoder wrote: | I've also noticed that the latest version of dmd has trouble with delete a, b, c; and forces three separate deletes. I really need to make my way over to digitalmars and submit some bug reports. |
I don't understand. Aren't three separate deletes what should be expected?
-JJR |
|
Back to top |
|
|
h3r3tic
Joined: 30 Mar 2004 Posts: 261 Location: Torun, Poland
|
Posted: Wed Mar 15, 2006 1:03 pm Post subject: |
|
|
JJR wrote: | The optimize flag does seem to have unusual side effects. I've seen similar trouble reported before in other projects. Optimize is just not reliable at this stage of the game. |
Very true !
-O == undefined behavior |
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Thu Mar 16, 2006 10:38 am Post subject: |
|
|
Yeah, in previous versions of DMD, I could allocate several classes / arrays and delete them all with a single line, as above. Perhaps before it was only really deleting the first one and ignoring the others--I didn't actually check for memory leaks, but trusted it implicitly. |
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Tue Apr 04, 2006 10:34 pm Post subject: |
|
|
Things had been working great in OpenAL for the last couple of weeks. I was able to get positional audio and nice Doppler effects working in my engine. However, I'm beginning to notice some instabillity with the OpenAL functions. For example, the constructor for the class I use for instances of 3D models fails (even when completely empty) when I call alGenBuffers() in code that's not even related to it. But if I put it inside of a single-iteration loop, it works again. (I'm compiling in default mode, with no flags set).
And I haven't been able to isolate it down to any particular error (I'm usually pretty good at that), since the errors seem to come and go as I comment out completely unrelated code. My guess is that perhaps there's stack corrupt or something else bad going on. Any suggestions? |
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Wed Apr 05, 2006 7:04 pm Post subject: |
|
|
Ok, I've reduced it down to a minimal problem (just a few lines of code); you can download it here.
Of particular interest is this block of code:
Code: | DerelictAL_LoadALC();
/* // uncomment and no Access Violation
FILE *fp;
char[] filename = "anything.wav";
fp = fopen(filename, "rb"); */
ALCdevice *device;
device = alcOpenDevice(null);
|
As you can see, there's an access violation when the code is run, but if I uncomment the completely unrelated file access code, it works fine. In fact, I have quite a few calls to OpenAL in my game engine and have produced some awesome effects, but I only recently moved some things around and found just how transient it is. If I were to guess, it might be a problem with how I added ALC functionality to my version of Derelict, but at this point I really don't know.
Edit: Ok, I think it migh be fixed; changed an extern(Windows) to Extern(C) in almanual.d. It was originally extern(Windows) before my modifications. I still need to do more testing. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|