1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream> //changed from conio.h
#include <stdlib.h>
#include <al.h>
#include <alc.h>
//#include <alu.h> //does not exist..
#include <al/alut.h>
ALuint Buffer;
ALuint Source;
ALfloat SourcePos[] = { 0.0, 0.0, 0.0 };
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 };
ALboolean LoadALData()
{
ALenum format;
ALsizei size;
ALvoid* data;
ALsizei freq;
ALboolean loop;
alGenBuffers(1, &Buffer);
if (alGetError() != AL_NO_ERROR)
return AL_FALSE;
alutLoadWAVFile("wavdata/FancyPants.wav", &format, &data, &size, &freq, &loop);
alBufferData(Buffer, format, data, size, freq);
alutUnloadWAV(format, data, size, freq);
alGenSources(1, &Source);
if (alGetError() != AL_NO_ERROR)
return AL_FALSE;
alSourcei (Source, AL_BUFFER, Buffer );
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 );
if (alGetError() == AL_NO_ERROR)
return AL_TRUE;
return AL_FALSE;
void SetListenerValues()
{
alListenerfv(AL_POSITION, ListenerPos);
alListenerfv(AL_VELOCITY, ListenerVel);
alListenerfv(AL_ORIENTATION, ListenerOri);
}
void KillALData()
{
alDeleteBuffers(1, &Buffer);
alDeleteSources(1, &Source);
alutExit();
}
int main(int argc, char *argv[])
{
alutInit(&argc, argv);
alGetError();
if (LoadALData() == AL_FALSE)
return -1;
SetListenerValues();
atexit(KillALData);
ALubyte c = ' ';
while (c != 'q')
{
c = getchar(); //changed from getche
switch (c)
{
case 'p': alSourcePlay(Source); break;
case 's': alSourceStop(Source); break;
case 'h': alSourcePause(Source); break;
};
}
return 0;
}
| |