1
votes

I'm trying to play sound in c++ project using OpenAl. I want to play a music track that will loop. When the file is a .wav or .mp3 at 320 kbps this works just fine. But when trying with a .mp3 at 32 kbps it shall not loop.

Another thing is that, if I set the AL_LOOPING flag to true when using the .mp3 it will start for 1 second and then restart the track. The flag works just fine when playing a .wav

My code is

alGenSources(1, &__alSource);
openAlResult = alGetError();
if (openAlResult != AL_NO_ERROR)
{
    return ConvertError(openAlResult);
}

alSourcef (__alSource, AL_PITCH, 1.0);
alSourcef (__alSource, AL_GAIN, 1.0);
alSource3f(__alSource, AL_POSITION, 0.0, 0.0, 0.0);
alSource3f(__alSource, AL_VELOCITY, 0.0, 0.0, 0.0);
alSource3f(__alSource, AL_DIRECTION, 0.0, 0.0, 0.0);
alSourcef(__alSource, AL_ROLLOFF_FACTOR, 0.0);
alSourcei(__alSource, AL_SOURCE_RELATIVE, AL_TRUE);
// only works for WAV
alSourcei(__alSource, AL_LOOPING, AL_TRUE);

openAlResult = alGetError();

if (openAlResult != AL_NO_ERROR)
{
    return ConvertError(openAlResult);
}

Any ideas regarding the .mp3 at 32 kbps format or way it will not loop ?

Thanks

1

1 Answers

0
votes

Maybe you have to call the alSourcePlay(__alSource); after you set the loop.

alGenSources(1, &__alSource);

alGenSources(1, &__alSource);
openAlResult = alGetError();

if (openAlResult != AL_NO_ERROR) {
    return ConvertError(openAlResult);
}

alSourcef (__alSource, AL_PITCH, 1.0);
alSourcef (__alSource, AL_GAIN, 1.0);
alSource3f(__alSource, AL_POSITION, 0.0, 0.0, 0.0);
alSource3f(__alSource, AL_VELOCITY, 0.0, 0.0, 0.0);
alSource3f(__alSource, AL_DIRECTION, 0.0, 0.0, 0.0);
alSourcef(__alSource, AL_ROLLOFF_FACTOR, 0.0);
alSourcei(__alSource, AL_SOURCE_RELATIVE, AL_TRUE);
// only works for WAV
alSourcei(__alSource, AL_LOOPING, AL_TRUE);
alSourcePlay(__alSource);

openAlResult = alGetError();

if (openAlResult != AL_NO_ERROR) {
    return ConvertError(openAlResult);
}