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);
}
#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);
}
