Sign in to follow this  

openAL not looping source

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?


[code]ALboolean InitAL()

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

alutInit(NULL, 0);

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

[code]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;

[code]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;

[code]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

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

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