#### Archived

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

# A Problem with OpenAL and Ogg Vorbis

This topic is 5421 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.

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011702
• ### Who's Online (See full list)

There are no registered users currently online

×