Jump to content
  • Advertisement
Sign in to follow this  
metsfan

OpenAL playing too fast.

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

If you intended to correct an error in the post then please contact us.

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:


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);



Does anyone see anything wrong? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
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 smile.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!