Sign in to follow this  
shadowcomplex

Minimum File Size in OpenAL?

Recommended Posts

shadowcomplex    445
Hey, Just yesterday I decided to implement OpenAL into my current game project and with the provided documentation it was virtually painless and seems to work fine with my full length tracks. The problem I have is that I can't seem to get very short wavs (3-6 second sound effects) to play. So I was wondering if there was a minimum file size for OpenAL to function properly. None of the code changes, just the file size. They are stored in the same directory and I used ::playsound() to make sure the files were valid. My idea was to load very common sound effects (player taking damage) into buffers in the beginning of the game and then generate sources later as needed associated with already initialized buffers. The full length tracks that work fine are between 2 and 4 minutes long. Do I need to post any code, or am I going at it the wrong way? Thanks a lot

Share this post


Link to post
Share on other sites
Xeee    144
I've used OpenAL before and I didn't face any problems with short wav files, I had alot of effects in the range 0.5 ~ 2.0 seconds.

Share this post


Link to post
Share on other sites
shadowcomplex    445
Hmmm...means I must be doing something wrong. Well, I'll go ahead and post some code if anyone feels like browsing through it.


//GameController.h
ALuint SoundBuffers[2]; //For majestic Tracks
ALuint SoundSources[2]; //For majestic Tracks
ALfloat ListenerPos[3];
ALfloat ListenerVel[3];
ALfloat ListenerOri[6];

void InitializeOpenAL();
void CreateSourceSound(CString,ALuint&,ALuint&,int,int);

//GameController.cpp

void GameController::InitializeOpenAL()
{
int argc; char *argv[5];
alutInit(&argc, argv);
alGetError();

ListenerPos[0]=Hero.X; ListenerPos[1]=Hero.Y; ListenerPos[2]=0.0;
ListenerVel[0]=0.0; ListenerVel[1]=0.0; ListenerVel[2]=0.0;
ListenerOri[0]=0.0; ListenerOri[1]=0.0; ListenerOri[2]=-1.0;
ListenerOri[3]=0.0; ListenerOri[4]=1.0; ListenerOri[5]=0.0;
}

void GameController::CreateSourceSound(CString track,ALuint &thisBuffer,ALuint &thisSource,int xpos, int ypos)
{
ALfloat SourcePos[]={float(xpos),float(ypos),0.0};
ALfloat SourceVel[]={0.0,0.0,0.0};

ALenum format;
ALsizei size;
ALvoid* data;
ALsizei freq;
ALboolean loop;

alGenBuffers(1,&thisBuffer);
if(alGetError()==AL_NO_ERROR)
{
alutLoadWAVFile(track,&format,&data,&size,&freq,&loop);
alBufferData(thisBuffer,format,data,size,freq);
alutUnloadWAV(format,data,size,freq);

alGenSources(1,&thisSource);
//Message("Generated Source");

if(alGetError()==AL_NO_ERROR)
{
alSourcei(thisSource,AL_BUFFER,thisBuffer);
alSourcef(thisSource,AL_PITCH,1.0f);
alSourcef(thisSource,AL_GAIN,1.0f);
alSourcefv(thisSource,AL_POSITION,SourcePos);
alSourcefv(thisSource,AL_VELOCITY,SourceVel);
alSourcei(thisSource,AL_LOOPING,true);

alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);

alSourcePlay(thisSource);
//Message("Playing Source!!");
}
}
}

//Relevant calls to CreateSourceSound
CreateSourceSound("Resources/Theme.wav",SoundBuffers[0],SoundSources[0],1500,1500); //This works

CreateSourceSound("Resources/Pain.wav",SoundBuffers[0],SoundSources[0],1500,1500); //This doesn't



I might be doing something terribly wrong. I have a days worth of experience with OpenAL so please point out any things that could/should be changed.

Thanks

Share this post


Link to post
Share on other sites
Demus79    362

I didn't have any problems with short sounds either. If I were you, I'd add error checking after every OpenAl command. It is just too easy to break the OpenAl api. Is the .Wav file correct ? does the order of loading have some effect ?

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