Skip to main content
gamedev.net
🔒 Locked

Open AL buffer binding

Started by Bouga Jul 4, 2004 at 4:33 PM 7 replies 1.6k views
Original Post
Bouga
Bouga
Hi, I just wanted to know if this was the right way to play another buffer on a source that is already playing a buffer in OpenAL: alSourceStop(Source); alSourcei (Source, AL_BUFFER, Buffer ); alSourcePlay(Source); Or does it leave something in the OpenAL's memory that will effect my applications performance? The reason I'm asking is that in my soon-to-be-game, after some playing my performance decreases from ~90 to ~60 fps in the EXACT SAME SITUATION in the level. And I havent had the problem once with sound disabled. I know this hasnt anything to do with my engine since the mem usage doesnt change and the decrease in the performance stays even after reloading the level, and all my in-game stuff happens in a class, that gets deleted and created again on level restart.
"A screen buffer is worth a thousand char's" - me
Enokh
Enokh
Interesting question, however why do you need to do that in the first place? Why not use a new source to play the 2nd buffer, and erase the 1st source when the 1st buffer is finished playing?
Bouga
Bouga
Well if this truns out to be the problem, I will definatelly try that - but if not? Would it be good to do that? Isnt that using some CPU needlessly.

P.S. This problem is really starting to freak me out - I added the ability to delete and create all the sources on command, and tried recreating them when the performance decrease began and it didnt solve the problem. So it may be something else, but then I dont know what, becouse the problem remains after reseting everything (restarting the level). :(
"A screen buffer is worth a thousand char's" - me
Bruno
Bruno
When you play a sound he uses a source, and even when the sound is done playing, the source will be in memory., so when the sound is over, delete the source, allways delete them, and only create a new source when you need to play a sound again.
Soundcards have a limited number or sources, in mine when i don't have more it just won't play sounds anymore, in yours maybe it has some kind of software emulation, and maybe that is what is slowing you down.., pure guessing here.,

anyways, this works 100% in my engine, with no performance loss.

void V_Sound::Play()
{
if(Loaded)
{
ALint play;
paused = 0;
if(Playing == 1)
{
if(g_Loop == 1)
{
alGetSourcei(g_Source, AL_SOURCE_STATE, &play);
if(play == AL_STOPPED)
{
Delete();
}
}
}

if(Playing == 0)
{


alGenSources(1, &g_Source);
alSourcefv(g_Source,AL_POSITION,sourceP);
alSourcefv(g_Source,AL_VELOCITY,Vel);
alSourcei(g_Source, AL_BUFFER, g_SampleSet);
alSourcef(g_Source,AL_PITCH,1.0f);
alSourcef(g_Source,AL_GAIN,gain);
alSourcei(g_Source,AL_LOOPING,g_Loop);
alSourcef(g_Source,AL_MAX_DISTANCE,20.0f);
Vel.Set(0,0,0);
alSourcePlay(g_Source);
Playing = 1;
}
else
if(Playing == 1)
{
alGetSourcei(g_Source, AL_SOURCE_STATE, &play);
alDeleteSources(1, &g_Source);
alGenSources(1, &g_Source);
alSourcefv(g_Source,AL_POSITION,sourceP);
alSourcefv(g_Source,AL_VELOCITY,Vel);
alSourcei(g_Source, AL_BUFFER, g_SampleSet);
alSourcef(g_Source,AL_PITCH,1.0f);
alSourcef(g_Source,AL_GAIN,gain);
alSourcei(g_Source,AL_LOOPING,g_Loop);
alSourcef(g_Source,AL_MAX_DISTANCE,20.0f);
Vel.Set(0,0,0);
alSourcePlay(g_Source);
Playing = 1;

}
}
}
Bouga
Bouga
Well, yeah, my computer doesnt create more than 32 sources too, on some the number is 16 as i've seen. But i create all my 32 (i check if the computer can handle 16 or 32 sources and create them accordingly) sources at the beggining of the program, and then dont create any more during play time, so this shouldnt be the problem.
"A screen buffer is worth a thousand char's" - me
Bouga
Bouga
Ok, so after some rewriting to actauly delete and recreate the sources on every buffer bind, the problem seems to have dissapeared + the overall fps has increased by about 4-5% :)
So thanks, Bruno and Enokh :) i guess that just binding another buffer to the same source isnt the right method to use, atleast on some computers.
"A screen buffer is worth a thousand char's" - me
Bouga
Bouga
I just try to create 16 sources, if it can be done delete them and try to create 32, and see if that can be done. Then delete all sources and create new none/16/32 sources depending on which tests succeeded.
"A screen buffer is worth a thousand char's" - me

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.