OpenAL playing too fast.

Started by
1 comment, last by metsfan 11 years, 4 months ago
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.
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.
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

This topic is closed to new replies.

Advertisement