/*
** Haaf’s Game Engine 1.8
** Copyright (C) 2003-2007, Relish Games
** hge.relishgames.com
**
** Core functions implementation: OpenAL audio routines
*/
#include “hge_impl.h”
//OpenAL CoreSDK v.3.05 + Alut 1.1.0
#include “C:\Program Files (x86)\OpenAL 1.1 SDK\include\al.h”
#include “C:\Program Files (x86)\OpenAL 1.1 SDK\include\alc.h”
#include “C:\Program Files (x86)\OpenAL 1.1 SDK\freealut-1.1.0-bin\include\AL\alut.h”
ALCcontext *Context;
ALCdevice *Device;
ALEFFECT CALL HGE_Impl::AL_Load(const char *filename, DWORD _size)
{
ALsizei size, length, samples;
ALuint Buffer;
ALuint Source;
ALvoid *buffer, *data;
if(bSilent) return 1;
else
{
data=Resource_Load(filename,0);
if(!data) return NULL;
}
// Load wav data into a buffer.
alGenBuffers(1, &Buffer);
if (alGetError() != AL_NO_ERROR) _PostError(“Can’t load sound into buffer | LN37 SoundAL”);
// Variables to load into.
ALenum format;
ALsizei freq;
ALboolean loop;
alutLoadWAVFile((ALbyte *)data, &format, &data, &size, &freq, &loop);
alBufferData(Buffer, format, data, size, freq);
alutUnloadWAV(format, data, size, freq);
// Bind buffer with a source.
alGenSources(1, &Source);
alSourcei (Source, AL_BUFFER, Buffer);
if(!size) Resource_Free(data);
return Source;
}
void HGE_Impl::AL_Initalize()
{
// Initialization
Device = alcOpenDevice(0); // select the “preferred device”
if(Device)
{
Context=alcCreateContext(Device,0);
alcMakeContextCurrent(Context);
System_Log(“AL: Initalize()”);
}
else _PostError(“AL: Device initalization failed”);
}
void HGE_Impl::AL_Shutdown()
{
// Exit
Context=alcGetCurrentContext();
Device=alcGetContextsDevice(Context);
alcMakeContextCurrent(NULL);
alcDestroyContext(Context);
alcCloseDevice(Device);
System_Log(“AL: Shutdown()”);
}
void HGE_Impl::AL_PlayWAV(ALEFFECT Source)
{
// 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”)
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
ALboolean loop;
alSourcef (Source, AL_PITCH, 1.0f );
alSourcef (Source, AL_GAIN, 1.0f );
alSourcefv(Source, AL_POSITION, SourcePos);
alSourcefv(Source, AL_VELOCITY, SourceVel);
// alSourcei (Source, AL_LOOPING, loop );
alSourcePlay(Source);
} |