X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fopenal_test1.cxx;h=0a6dc885a2961584d79977acc092d612d3f4ae03;hb=be7065674586ffbb5940ab21a028bc8c461217e2;hp=91b8c84958a6ea3a93650d358684187f7bf9de2f;hpb=5bbcd386fa837885782f128af77ff0162761945c;p=simgear.git diff --git a/simgear/sound/openal_test1.cxx b/simgear/sound/openal_test1.cxx index 91b8c849..0a6dc885 100644 --- a/simgear/sound/openal_test1.cxx +++ b/simgear/sound/openal_test1.cxx @@ -1,7 +1,29 @@ #include -#include -#include +#ifdef _WIN32 +#include +#define sleep(x) Sleep(x*1000) +#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 @@ -24,10 +46,19 @@ 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; + + alutInit(&argc, argv); + 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. @@ -72,11 +103,7 @@ int main( int argc, char *argv[] ) { ALfloat source_vel[3]; // configuration values - ALenum format; - ALsizei size; - ALvoid* data; - ALsizei freq; - ALboolean loop; + 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; @@ -92,7 +119,24 @@ int main( int argc, char *argv[] ) { } // Load the sample file - alutLoadWAVFile( (ALbyte *)"jet.wav", &format, &data, &size, &freq, &loop ); +#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 + ALenum format; + ALsizei size; + ALvoid* data; + ALsizei freq; + +# 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."); } @@ -104,6 +148,7 @@ int main( int argc, char *argv[] ) { } alutUnloadWAV( format, data, size, freq ); +#endif alGenSources(1, &source); if (alGetError() != AL_NO_ERROR) { @@ -120,6 +165,7 @@ int main( int argc, char *argv[] ) { alSourcePlay( source ); sleep(10); + alutExit(); return 0; }