00001
00002
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
00020 ALenum error;
00021 ALCdevice *Device = alcOpenDevice(NULL);
00022 if (Device) {
00023 alcMakeContextCurrent(alcCreateContext(Device,NULL));
00024 }
00025
00026
00027
00028 alGetError();
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
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
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
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
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
00069
00070
00071
00072
00073
00074
00075 alSourcei(source[0], AL_BUFFER, g_Buffers[0]);
00076
00077 if ((error = alGetError()) != AL_NO_ERROR) {
00078 DisplayALError("alSourcei AL_BUFFER 0 : ", error);
00079 }
00080
00081
00082 ALCcontext *Context=alcGetCurrentContext();
00083 Device=alcGetContextsDevice(Context);
00084 alcMakeContextCurrent(NULL);
00085 alcDestroyContext(Context);
00086 alcCloseDevice(Device);
00087
00088 return 0;
00089 }