X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fopenal_test1.cxx;h=dd2a77f01620e813c6ba6b1026bf4518719557e9;hb=ea513d392e050578fcc017e0c888a3374f0dcead;hp=0a62ef1e052bcad62ee568c93ba4c6824468e6e1;hpb=d3a3466b142af9ae96cf3e664abad3c34f488754;p=simgear.git diff --git a/simgear/sound/openal_test1.cxx b/simgear/sound/openal_test1.cxx index 0a62ef1e..dd2a77f0 100644 --- a/simgear/sound/openal_test1.cxx +++ b/simgear/sound/openal_test1.cxx @@ -1,16 +1,31 @@ #include + +#ifdef __MINGW32__ +// This is broken, but allows the file to compile without a POSIX +// environment. +static unsigned int sleep(unsigned int secs) { return 0; } +#else #include // sleep() +#endif #if defined( __APPLE__ ) # define AL_ILLEGAL_ENUM AL_INVALID_ENUM # define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION # include +# include # include +#elif defined(OPENALSDK) +# include +# include +# include #else # include +# include # include #endif +#define AUDIOFILE SRC_DIR"/jet.wav" + #include static void print_openal_error( ALuint error ) { @@ -32,10 +47,18 @@ static void print_openal_error( ALuint error ) { int main( int argc, char *argv[] ) { // initialize OpenAL - alutInit( 0, NULL ); - alGetError(); - if ( alGetError() != AL_NO_ERROR) { - SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" ); + ALCdevice *dev; + ALCcontext *context; + + sglog().setLogLevels( SG_ALL, SG_ALERT ); + + // initialize OpenAL + if ( (dev = alcOpenDevice( NULL )) != NULL + && ( context = alcCreateContext( dev, NULL )) != NULL ) { + alcMakeContextCurrent( context ); + } else { + context = 0; + SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" ); } // Position of the listener. @@ -80,11 +103,11 @@ int main( int argc, char *argv[] ) { ALfloat source_vel[3]; // configuration values - ALenum format; - ALsizei size; - ALvoid* data; - ALsizei freq; - ALboolean loop; +// ALenum format; +// ALsizei size; +// ALvoid* data; +// ALsizei freq; + ALboolean loop = false; source_pos[0] = 0.0; source_pos[1] = 0.0; source_pos[2] = 0.0; source_vel[0] = 0.0; source_vel[1] = 0.0; source_vel[2] = 0.0; @@ -100,11 +123,19 @@ int main( int argc, char *argv[] ) { } // Load the sample file -#if defined (__APPLE__) - alutLoadWAVFile( (ALbyte *)"jet.wav", &format, &data, &size, &freq ); +#if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1 + + buffer = alutCreateBufferFromFile(AUDIOFILE); + if (buffer == AL_NONE) { + SG_LOG( SG_GENERAL, SG_ALERT, "Failed to buffer data."); + } + #else - alutLoadWAVFile( (ALbyte *)"jet.wav", &format, &data, &size, &freq, &loop ); -#endif +# if defined (__APPLE__) + alutLoadWAVFile( (ALbyte *)AUDIOFILE, &format, &data, &size, &freq ); +# else + alutLoadWAVFile( (ALbyte *)AUDIOFILE, &format, &data, &size, &freq, &loop ); +# endif if (alGetError() != AL_NO_ERROR) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to load wav file."); } @@ -116,6 +147,7 @@ int main( int argc, char *argv[] ) { } alutUnloadWAV( format, data, size, freq ); +#endif alGenSources(1, &source); if (alGetError() != AL_NO_ERROR) {