#include <stdio.h>
+#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 <unistd.h> // sleep()
+#endif
+
#if defined( __APPLE__ )
# define AL_ILLEGAL_ENUM AL_INVALID_ENUM
# define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION
# include <OpenAL/al.h>
+# include <OpenAL/alc.h>
# include <OpenAL/alut.h>
#else
# include <AL/al.h>
+# include <AL/alc.h>
# include <AL/alut.h>
#endif
+#define AUDIOFILE SRC_DIR"/jet.wav"
+
#include <simgear/debug/logstream.hxx>
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;
+
+ // 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.
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;
}
// 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
+# 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.");
}
}
alutUnloadWAV( format, data, size, freq );
+#endif
alGenSources(1, &source);
if (alGetError() != AL_NO_ERROR) {