servers/sound/main.cc

Go to the documentation of this file.
00001 // the above code was copied from an example of the OpenAL manual
00002 // but doesn't seem to work :(
00003 
00004 #include <AL/al.h>
00005 #include <AL/alut.h>
00006 #include <AL/alc.h>
00007 
00008 #include <iostream>
00009 #include <Platform.h>
00010 
00011 using namespace std;
00012 #define CHECK_SYSCALL(val, msg) if ((val) == -1) { perror(msg); return 3; }
00013 #define NUM_BUFFERS 1
00014 
00015 int main(int argc, char *argv[])
00016 {
00017 
00018 #define DisplayALError(s, e) cout << s << (int)e << endl;
00019         // INIT
00020         ALenum error;
00021         ALCdevice *Device = alcOpenDevice(NULL); // select the "preferred device"
00022         if (Device) {
00023                 alcMakeContextCurrent(alcCreateContext(Device,NULL));
00024         }
00025         // Check for EAX 2.0 support
00026         //alIsExtensionPresent((const ALubyte*)"EAX2.0");
00027         // Generate Buffers
00028         alGetError(); // clear error code
00029         ALuint g_Buffers[NUM_BUFFERS];
00030         alGenBuffers(NUM_BUFFERS, g_Buffers);
00031         if ((error = alGetError()) != AL_NO_ERROR) {
00032                 DisplayALError("alGenBuffers :", error);
00033                 return 2;
00034         }
00035         // Load test.wav
00036         ALenum format;
00037         ALvoid *data;
00038         ALsizei size, freq;
00039         ALboolean loop;
00040         alutLoadWAVFile((ALbyte*)"test.wav",&format,&data,&size,&freq,&loop);
00041         if ((error = alGetError()) != AL_NO_ERROR) {
00042                 DisplayALError("alutLoadWAVFile test.wav : ", error);
00043                 alDeleteBuffers(NUM_BUFFERS, g_Buffers);
00044                 return 3;
00045         }
00046         // Copy test.wav data into AL Buffer 0
00047         alBufferData(g_Buffers[0],format,data,size,freq);
00048         if ((error = alGetError()) != AL_NO_ERROR) {
00049                 DisplayALError("alBufferData buffer 0 : ", error);
00050                 alDeleteBuffers(NUM_BUFFERS, g_Buffers);
00051                 return 4;
00052         }
00053         // Unload test.wav
00054         alutUnloadWAV(format,data,size,freq);
00055         if ((error = alGetError()) != AL_NO_ERROR) {
00056                 DisplayALError("alutUnloadWAV : ", error);
00057                 alDeleteBuffers(NUM_BUFFERS, g_Buffers);
00058                 return 5;
00059         }
00060         // Generate Sources
00061         ALuint source[1];
00062         alGenSources(1,source);
00063         if ((error = alGetError()) != AL_NO_ERROR) {
00064                 DisplayALError("alGenSources 1 : ", error);
00065                 return 6;
00066         }
00067 
00068         // Attach buffer 0 to source
00069 /*      ALfloat source0Pos[]={-2,0,0}, source0Vel[]={0,0,0};
00070 
00071         alSourcef(source[0], AL_PITCH, 1.0f);
00072         alSourcef(source[0], AL_GAIN, 1.0f);
00073         alSourcefv(source[0], AL_POSITION, source0Pos);
00074         alSourcefv(source[0], AL_VELOCITY, source0Vel);*/
00075         alSourcei(source[0], AL_BUFFER, g_Buffers[0]);
00076         //alSourcei(source[0], AL_LOOPING, AL_TRUE);
00077         if ((error = alGetError()) != AL_NO_ERROR) {
00078                 DisplayALError("alSourcei AL_BUFFER 0 : ", error);
00079         }
00080 
00081         // EXIT
00082         ALCcontext *Context=alcGetCurrentContext();
00083         Device=alcGetContextsDevice(Context);
00084         alcMakeContextCurrent(NULL);
00085         alcDestroyContext(Context);
00086         alcCloseDevice(Device);
00087 
00088         return 0;
00089 }

Generated on Sun Dec 2 23:04:29 2007 for openSDK by  doxygen 1.3.9.1