wioneo 0 Newbie Poster

I have been using c++ for a short time now and wanted to add sounds support via the OpenAL library, but I am having problems. In the end I tried to directly copy the code from a tutorial, but it is still not working.

I have...

alutInit(&argc, argv);
alGetError();
////////////////////
ALfloat listenerPos[]={0.0,0.0,4.0};
ALfloat listenerVel[]={0.0,0.0,0.0};
ALfloat listenerOri[]={0.0,0.0,1.0, 0.0,1.0,0.0};

ALfloat source0Pos[]={ -2.0, 0.0, 0.0};
ALfloat source0Vel[]={ 0.0, 0.0, 0.0};

alListenerfv(AL_POSITION,listenerPos);
alListenerfv(AL_VELOCITY,listenerVel);
alListenerfv(AL_ORIENTATION,listenerOri);
alGenBuffers(NUM_BUFFERS, buffer);
ALboolean al_bool;
alutLoadWAVFile("rifle.wav", &format, &data, &size, &freq, &al_bool);
alBufferData(buffer[0],format,data,size,freq);
alutUnloadWAV(format,data,size,freq);
alGenSources(NUM_SOURCES, source);

alSourcef(source[0], AL_PITCH, 1.0f);
alSourcef(source[0], AL_GAIN, 1.0f);
alSourcefv(source[0], AL_POSITION, source0Pos);
alSourcefv(source[0], AL_VELOCITY, source0Vel);
alSourcei(source[0], AL_BUFFER,buffer[0]);
alSourcei(source[0], AL_LOOPING, AL_TRUE);
///////////////
alSourcePlay(p_resource->source[0]);//<-triggered by mouse

I tried using the AL function to error check each function, but the only error returned was 40961 on the 'alsourceplay' function.

Does anyone have any ideas on what could cause this? I looked at the attribute variables for the file after loading and it seems like it is being loaded succesfully.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.