X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fsound%2Fopenal_test1.cxx;h=7909f2cd3938028f58b35b7062a5c43ba1ba2365;hb=1f23fb89c01549349204f6fe559a9639b7a4a60b;hp=91b8c84958a6ea3a93650d358684187f7bf9de2f;hpb=5bbcd386fa837885782f128af77ff0162761945c;p=simgear.git diff --git a/simgear/sound/openal_test1.cxx b/simgear/sound/openal_test1.cxx index 91b8c849..7909f2cd 100644 --- a/simgear/sound/openal_test1.cxx +++ b/simgear/sound/openal_test1.cxx @@ -1,9 +1,31 @@ #include - -#include -#include - +#include // EXIT_FAILURE + +#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 +#elif defined(OPENALSDK) +# include +# include +#else +# include +# include +#endif + +#define AUDIOFILE SRC_DIR"/jet.wav" + +#include #include +#include static void print_openal_error( ALuint error ) { if ( error == AL_INVALID_NAME ) { @@ -22,13 +44,24 @@ static void print_openal_error( ALuint error ) { } -int main( int argc, char *argv[] ) { +int main( int argc, char *argv[] ) +{ + sglog().setLogLevels( SG_ALL, SG_ALERT ); + // initialize OpenAL - alutInit( 0, NULL ); - alGetError(); - if ( alGetError() != AL_NO_ERROR) { - SG_LOG( SG_GENERAL, SG_ALERT, "Audio initialization failed!" ); + ALCdevice *dev = alcOpenDevice(NULL); + if (!dev) { + SG_LOG( SG_GENERAL, SG_ALERT, "Audio device initialization failed!" ); + return EXIT_FAILURE; + } + + ALCcontext *context = alcCreateContext(dev, NULL); + if (!context) { + SG_LOG( SG_GENERAL, SG_ALERT, "Audio context initialization failed!" ); + return EXIT_FAILURE; } + + alcMakeContextCurrent( context ); // Position of the listener. ALfloat listener_pos[3]; @@ -72,41 +105,20 @@ 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; - // create an OpenAL buffer handle - alGenBuffers(1, &buffer); - ALuint error = alGetError(); - if ( error != AL_NO_ERROR ) { - print_openal_error( error ); - SG_LOG( SG_GENERAL, SG_ALERT, "Failed to gen OpenAL buffer." ); - } else { - SG_LOG( SG_GENERAL, SG_ALERT, "Buffer created ok!" ); - } - // Load the sample file - alutLoadWAVFile( (ALbyte *)"jet.wav", &format, &data, &size, &freq, &loop ); - if (alGetError() != AL_NO_ERROR) { - SG_LOG( SG_GENERAL, SG_ALERT, "Failed to load wav file."); - } - - // Copy data to the internal OpenAL buffer - alBufferData( buffer, format, data, size, freq ); - if (alGetError() != AL_NO_ERROR) { + buffer = simgear::createBufferFromFile(SGPath(AUDIOFILE)); + if (buffer == AL_NONE) { SG_LOG( SG_GENERAL, SG_ALERT, "Failed to buffer data."); - } - - alutUnloadWAV( format, data, size, freq ); + } alGenSources(1, &source); if (alGetError() != AL_NO_ERROR) { + ALuint error = alGetError(); print_openal_error( error ); } @@ -120,6 +132,10 @@ int main( int argc, char *argv[] ) { alSourcePlay( source ); sleep(10); - + + alcMakeContextCurrent(NULL); + alcDestroyContext(context); + alcCloseDevice(dev); + return 0; }