Sign in to follow this  
metsfan

OpenAL playing too fast.

Recommended Posts

Hello all. I am having an issue with a basic OpenAL implementation. I am loading in a WAV file, which loads in just fine. However when I try to play it, it plays at about 10x its normal speed. I tried loading it in other media players and it loads just fine. Here is my code:

[code]
ALenum format;
ALsizei size;
ALsizei freq;
ALboolean loop;
void *data;
alutLoadWAVFile((ALbyte *)mFilepath.c_str(), &format, &data, &size, &freq, &loop);
alGetError();
glm::vec3 velocity(0, 0, 0);
alListenerfv(AL_POSITION, &position[0]);
alListenerfv(AL_VELOCITY, &velocity[0]);
alListener3f(AL_ORIENTATION, 0, 0, -1);
error = alGetError();
if (error != AL_NO_ERROR) {
Logger::log(LogError, "Failed to init OpenAL listener.");
}
alGenBuffers(1, &mBufferId);
error = alGetError();
if (error != AL_NO_ERROR) {
Logger::log(LogError, "Failed to init OpenAL buffer.");
}
alBufferData(mBufferId, format, data, size, freq);
error = alGetError();
if (error != AL_NO_ERROR) {
Logger::log(LogError, "OpenAL buffer error: %d", error);
}

alGenSources(1, &mSourceId);
alSourcef(mSourceId, AL_PITCH, 1.0);
alSourcef(mSourceId, AL_GAIN, 1.0);
alSourcefv(mSourceId, AL_VELOCITY, &velocity[0]);
alSourcefv(mSourceId, AL_POSITION, &position[0]);
alSourcei(mSourceId, AL_BUFFER, mBufferId);
alSourcei(mSourceId, AL_LOOPING, AL_FALSE);

[/code]

Does anyone see anything wrong? Thank you.

Share this post


Link to post
Share on other sites
Solved it. The issue was that I was using ALUT to load in the WAV files, but I was initializing the OpenAL context manually, so ALUT didn't have certain properties set which I guess make it work. By calling alutInit, the issue was solved. I'm looking to ditch ALUT asap, if anyone has any recommendations for audio libraries that can read WAV and OGG files into a structure with the basic information (buffer size, format, byte rate) I would be most appreciative (something simliar to assimp or FreeImage but for audio files). Thanks. Edited by metsfan

Share this post


Link to post
Share on other sites
Just wanted to reply and say that I settled on FMOD for my audio system. I promise I won't bump this thread anymore, just wanted to provide answers in case anyone comes by in the future [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

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