Archived

This topic is now archived and is closed to further replies.

A Problem with OpenAL and Ogg Vorbis

This topic is 5152 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have a pretty annoying problem. I used the tutorials at http://www.devmaster.net/articles.php?catID=6 to create an ogg vorbis class for my entry into the Creative comp. The problem is that in this function:
void COGG::EmptyQueue()
{
int queued;

alGetSourcei(source, AL_BUFFERS_QUEUED, &queued);

while(queued-- > 0)
{
ALuint buffer;

alSourceUnqueueBuffers(source, 1, &buffer);
if(alGetError() != AL_NO_ERROR)
MessageBox(hWnd, "Unqueue error", "Error", MB_OK);
}
}

queued seems to be always below 0 on all computers (three computers) I've tried, and gives an infinte loop without the queued-- > 0 there. This happens even with a sound blaster live in my computer. Without a SBLive in the others, the following function seems to stuff up as processed is always below 0:
bool COGG::Update()
{
int processed;
bool active = true;

alGetSourcei(source, AL_BUFFERS_PROCESSED, &processed);

while(processed-- > 0)
{
ALuint buffer;

alSourceUnqueueBuffers(source, 1, &buffer);
if(alGetError() != AL_NO_ERROR)
MessageBox(hWnd, "Buffer Unqueue Error", "Error", MB_OK);

active = Stream(buffer);

alSourceQueueBuffers(source, 1, &buffer);
if(alGetError() != AL_NO_ERROR)
MessageBox(hWnd, "Buffer Queue Error", "Error", MB_OK);
}

return active;
}

I changed while(processes--) to while(processes-- > 0) to avoid an infinite loop. I don't know what alGetSourcei() means really and I'm totally stuck! I'm basically horrifically nervous as the thing is due in two days, can anyone help me? Thanks [edited by - strider44 on January 16, 2004 1:04:32 AM]

Share on other sites
I''m actually going to attempt to add sound & music to one of my simple games tonight... I''m going to be reading through some of the openAL specifications & of course an online tut here & there. My AIM SN is: lukemiklos
if you want to keep current. I''ll look into that problem right now though. Usually whenever I have a problem that stumps like that, I check the function header first... to see what it assumes is done before you call it & I also cut & paste in these 4 lines & run it again to see what happened in case of error (pardon the old school C code):

  DWORD TEMP_ERROR = GetLastError();  FILE* FP = fopen("ERROR_LOG.txt","a");  fprintf(FP,"\nERROR CODE: %d",TEMP_ERROR);  fclose(FP);

Share on other sites
Verify that you are using an unsigned integer for your source variable & you might as well make the "returned" variable unsigned too (uint queued). Be sure of course that you are performing the buffer_queued & buffer_processed query on an actual source, use: bool IsSource(uint sourceName);
& the openAL specification uses slightly different constants so try: BUFFERS_QUEUED & BUFFERS_PROCESSED, unless of course you are certain your''s work or perhaps you defined some of your own to match those. I am gonna try a few sounds here in a minute, wish me luck : )

Share on other sites
I just read that if you only have 1 buffer queued for this source (or any source)... then your queries will return 0 by default, which stands for the index of the buffer for that source. Its like the source stores all the buffer''s you add to it in a "buffer array", so if you only have 1 buffer for this source, then the index will be 0. BUFFERS_QUEUED should return the index of the last buffer of that source, or a better way to say it would be, the total number of buffers for that source minus 1.

Share on other sites
thanks for your replies (though unfortunately it hasn''t helped). I have a feeling that the other computer''s sound card just isn''t compatible with OpenAL - it''s a generic one. Does the hardware matter, or does it just have to be any sound card?

Anyway, I must be getting a negative number back for alGetSourcei(source, AL_BUFFERS_QUEUED, &queued); as it was crashing into an infinite loop without the > 0, it should go through even if there were no queued buffers as it''s a post-increment shouldn''t it?

If I get OpenAL down to pat I''m definitely going to have to write a few tutorials about mixing OpenAL and OpenGL as there''s nothing on the internet at the moment!

Share on other sites
try thi site it my be useful.
For me it worked.

http://www.devmaster.net/articles.php?catID=6

Anyway, I gave a look at your code an there''s athing I can''t understand.
When you write:

while(queued-- > 0)

is the program supposed to do queued=-1 befor checking queued>0 ?
In this case the code is not correct because in C/C++ when you write -- after a variable, the value will be decreased after the instruction it''s written in.
I mean, first it will check if queued>0 and then it will do the --.
If you want it to do the opposite you have to write

while(--queued > 0)

OK, maybe I''m wrong and you already knew what I''ve written but I hope this can help.

Share on other sites
lol, yep that's where I got it from. I think it's just the OpenAL that's not working with the sound card as opposed to the code.

With the queued-- > 0 I just put the > 0 to get rid of the infinite loop. Don't know what's causing it!

[edited by - strider44 on January 15, 2004 10:06:15 AM]

Share on other sites
Sorry, I didn''t see the site on your first post.

I think that the problem is not with the sound card and maybe it''s not even with that function.
If I could see the whole code (just the section about COGG) I could give you some more help (not sure about this anyway).
Also, if you have to post some code use [source ][/source ] (without the spaces)
it will make it more readable(not sure this is the right spelling).

Anyway, just to give you a hint:
I think you should update the sound source only if it''s playing (maybe you already do this), because I''m not sure about what would happen otherwise.

Share on other sites
Strider,

I got some sound effects working with my game last night, I really like openAL so far, however... I have not implemented multiple buffers for the same source yet

Question:

what version of directx are you using? because that site orignally had me including: dinput8.lib in my project, but that is a lil old (I think, plus I didn''t have it) so I changed it to dinput.lib which is what I think directx 9 puts on your comp (or updates) if you run the installation, but I could be mistaken. I don''t know if the hardware matters or not, I''ll be sure to try something like that with my new comp & my wife''s old laptop to see what happens.

I also assume you have checked out openAL error handling:
http://www.devmaster.net/articles/openal-tutorials/lesson6.php

also strider... I don''t remember what happens when you decrement an unsigned integer below 0, perhaps it just wraps around back to its max number, so if you did use one, yes... that would be an infinite loop if thats the case.

Share on other sites
Basically on a SBLive card it plays but with queues always below 0, and on an old sound card it doesn''t play with processed always below 0. Since most people have old sound cards I don''t like that.

I think I might just give up openal and just do a normal decompression thing.

@Luke Miklos: I''m not using directx. And I don''t think the last comment is correct. Anyway there''s only an infinite loop if I remove the > 0. It wasn''t there in the original code.

Share on other sites
The last comment about the unsigned int looping back to its max when you decrement it below zero is correct. Try it, I did, & it went to:

4294967295

which is exactly what the max of an unsigned 32 bit variable is:

( 2 ^ 32 ) - 1

Share on other sites
The version of openAL that supports Ogg Vorbis is still a BETA version from what I''ve heard/read. You might give those guys some feedback about whats going on, maybe its related to Ogg Vorbis. Have you tried it with WAV files or some other format that is supported in a non-beta version of openAL???

Share on other sites
I used the code from that site and my app can play OGG files perfectly.
I had to do some changes but now it''s ok on different computers.
(if you use the exact code that tutorial gives you the sound has an odd error after about one second - anyway it works)
I don''t think the problem is about the directX version or the sound card (even if it could be).
he doesn''t use an unsigned value, so what''s wrog with that?

Anyway if you had to put the >0 it means it''s a negative value (not 0). Maybe (i''m just guessing), that the alGetAourcei() gives "processed" the value of -1 when something goes wrong (I know of other funcions doing that).
This would mean the error is somewhere else in your code.
Try compiling the code exactly as the tutorial gives it to you.
If it works (as I think) it means you''ve done something wrong sowhere else.

Let us know...

Share on other sites
I only said it would be an infinite "if he did use one" because it was suggested. Also, Lazork, did you do the same buffer_queued & buffer_processed queries? Those worked too? Or did you just load an ogg file & play it?

Just trying to examine all posibilities & then narrow things down. I will attempt some OGG crap tonight, hopefully.

Share on other sites
no the main code still doesn''t work on the old crap sound card, and I think that the queues thing isn''t serious, perhaps it''s because I''m using winAPI instead of consoles so the thing may be called at the start of the program where it''s not supposed to be or something. It doesn''t seem serious though - can''t detect any memory leaks or slowness of the program. I just hate it when the demo''s music won''t run on more than half of all computers!

Share on other sites
Here''s a question for you:
do you create a context and set up a device?
In this case (if you''re using winapi) you should do that on WM_INITDIALOG.

Recentlt I tried my program (wich works perfectly on most computers) on an old notebook; well, my program couldn''t even initialize OpenAL and I had to reboot the pc. It seemed like the pc had run into an endless loop...

There''s a thing I''ve not understood yet:
does your code work on any of the computers you''ve tried? I mean, can you hear the sound correctly?