PDA

View Full Version : need openal help


animatedantmo
04-30-2006, 10:55 AM
Im trying to see if i can produce a working openal console proj from "scratch". I can get the sample code to compile without errors but whenever i simply transfer the code to a blank project i can not produce any sounds. I recieve two warnings about the depricated alut functions but that is it. Would someone be kind enough to look at the code and tell me if i have done anything wrong?



#include <al/alut.h>
#include <al/Framework.h>


#define WAV_FILE "smile.wav"

// Position of the source sound.
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };

// Velocity of the source sound.
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };


// Position of the Listener.
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };

// Velocity of the Listener.
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };

// Orientation of the Listener. (first 3 elements are "at", second 3 are "up")
// Also note that these should be units of '1'.
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };



int main()
{
ALuint buffer;
ALuint source;


ALenum format;
ALsizei size;
ALvoid *data;
ALsizei freq;
ALboolean loop;

ALint error;

ALCdevice *device = alcOpenDevice(NULL);

if (device)
{
ALCcontext *context = alcCreateContext(device,NULL);
alcMakeContextCurrent(context);
}
alGetError(); // clear error code
alGenBuffers(1, &buffer);
if ((error = alGetError()) != AL_NO_ERROR)
{
return(-1);
}
// Load test.wav
alutLoadWAVFile(WAV_FILE,&format,&data,&size,&freq,&loop);
if ((error = alGetError()) != AL_NO_ERROR)
{
alDeleteBuffers(1, &buffer);
return(-2);
}
// Copy test.wav data into AL Buffer 0
alBufferData(buffer,format,data,size,freq);
if ((error = alGetError()) != AL_NO_ERROR)
{
alDeleteBuffers(1, &buffer);
return(-3);
}
// Unload test.wav
alutUnloadWAV(format, data, size, freq);
if ((error = alGetError()) != AL_NO_ERROR)
{
alDeleteBuffers(1, &buffer);
return(-4);
}
// Generate Sources
alGenSources(1, &source);
if ((error = alGetError()) != AL_NO_ERROR)
{
return(-5);
}


alSourcei (source, AL_BUFFER, buffer );
alSourcef (source, AL_PITCH, 1.0 );
alSourcef (source, AL_GAIN, 1.0 );
alSourcefv(source, AL_POSITION, SourcePos);
alSourcefv(source, AL_VELOCITY, SourceVel);
alSourcei (source, AL_LOOPING, loop );


if(alGetError() != AL_NO_ERROR)
return(-6);



// Attach buffer 0 to source
alSourcei(source, AL_BUFFER, buffer);
if ((error = alGetError()) != AL_NO_ERROR)
{
return(-7);
}

alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);


alSourcePlay(source);

// EXIT
ALCcontext *Context=alcGetCurrentContext();
ALCdevice *Device=alcGetContextsDevice(Context);
alcMakeContextCurrent(NULL);
alcDestroyContext(Context);
alcCloseDevice(Device);

return(0);
}

Reedbeta
04-30-2006, 11:02 AM
When you transfer the code to a blank project, are you setting it to link with the OpenAL libraries? Also, is "smile.wav" in the new project directory?

animatedantmo
04-30-2006, 11:46 AM
When you transfer the code to a blank project, are you setting it to link with the OpenAL libraries? Also, is "smile.wav" in the new project directory?

I believe i have set it to link to the openal lib otherwise i would get linker errors right? I have "alut.lib OpenAL32.lib" listed in the additional dependencies spot for the linker settings. and smile.wav is in the project directory (with the main.cpp file)

_fs
05-01-2006, 01:29 AM
If you're using windows check any openal dlls are accessable (in the path or the same directory as the program)

animatedantmo
05-01-2006, 11:11 AM
If you're using windows check any openal dlls are accessable (in the path or the same directory as the program)

alut.dll is in the directory but i dont have any openal dll files. also the program doesnt run without the alut.dll file so does that mean alut.dll is the only one it needs?

animatedantmo
05-12-2006, 12:51 PM
OK i managed to get sound to work. I used a different OpenAL32.dll and that seemed to fix the problem.

Thanks for trying guys :)