Public feed
#598277
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <al/al.h>
#include <al/alc.h>
#include <al/alut.h>
class cAudio {
ALuint Buffer; //the buffer were the data will be held
ALuint Source; //were the buffer goes to be played and such
public:
void a2dLoad(); //laod function thing
void a2dPlay(); //play function thing
void aKill(); //destroys the crap
};
void cAudio::a2dLoad()
{
alutInit(NULL, 0); //initialze alut
alGetError();
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; //the next few are sort of self explanitory
ALfloat SourceVel[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };
ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
ALenum format; //the data types
ALsizei size;
ALvoid* data;
ALsizei freq;
ALboolean loop;
alGenBuffers(1, &Buffer); //how many buffers theres going to be
alutLoadWAVFile("test.wav", &format, &data, &size, &freq, &loop);//loads the wav file then holds the data,,freq,loop,etc
alBufferData(Buffer, format, data, size, freq);
alutUnloadWAV(format, data, size, freq);
alGenSources(1, &Source);
//here down just the pitch the players position
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 );
alListenerfv(AL_POSITION, ListenerPos);//this is the listener were the player is how fast hes going etc..
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);
}
void cAudio::a2dPlay()
{
alSourcePlay(Source); //play
}
void cAudio::aKill()
{
alDeleteBuffers(1, &Buffer);//delete buffer
alDeleteSources(1, &Source);//delete source
alutExit();
}