Jump to content
  • Advertisement
Sign in to follow this  

openAL not looping source

This topic is 2557 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

I recently set up openAL to add sound to my game and everything is going fairly well except for the fact that I can't loop my .wav file.

I am aware that I don't need to use a loop to get multiple sources, and that I should probably do some error checking in my sound loading method, I will fix that soon. However, do I need to explicitly create a device and context or not? When I do create the device and context, the sound plays very slow and choppy.

Anyway, does my code look right or do you guys see a misconception somewhere?


ALboolean InitAL()

//device = alcOpenDevice(NULL);
//context = alcCreateContext(device, NULL);

alutInit(NULL, 0);

if(alGetError() != AL_NO_ERROR)
return false;
return true;

vector<ALuint> FileManager::loadSound(int num, bool l, string id)

//Get Full Path
std::stringstream ss;
ss << soundPath << id;

vector<ALuint> sources;

ALuint buffer(alutCreateBufferFromFile(ss.str().c_str()));

for(int i = 0; i < num; i++){

ALuint tempSource;
alGenSources(1, &tempSource);

alSourcei(tempSource, AL_BUFFER, buffer);
alSourcef(tempSource, AL_PITCH, 1.0);
alSourcef(tempSource, AL_GAIN, 1.0);
if(l) alSourcef(tempSource, AL_LOOPING, AL_TRUE);

return sources;

bool Game::start()

userShip = shared_ptr<Actor>(new Ship());
shared_ptr<class Ship> tempShip(dynamic_pointer_cast<class Ship>(userShip));

fileManager.loadSound(tempShip->getNumThrusters(), true, "Thruster.wav"),
fileManager.loadSound(tempShip->getNumThrusters(), false, "ThrusterEnd.wav"));

return true;

void Thruster::control(Controller& input, GLfloat dt)

for each(int i in key){

isActive = true;

}else if(input.wasReleased(i)){

bool stillActive = false;
for each(int x in key){
stillActive = true;

isActive = false;

Share this post

Link to post
Share on other sites
Everything looks fine to me. It's been like a year since I used OpenAL tho.

I don't use alut but it looks like it's already creating a context by itself. As for the looping issue, the only difference I see is that I use

alSourcei(source, AL_LOOPING, loop);
alSourcei instead of alSourcef, but I'm not sure if it matters.

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!