6 * This program loads and plays a file the deprecated ALUT 0.x.x way.
10 playFile (const char *fileName)
16 #if !defined(__APPLE__)
24 /* Create an AL buffer from the given sound file. */
25 alutLoadWAVFile ((ALbyte *) "file1.wav", &format, &data, &size, &frequency
26 #if !defined(__APPLE__)
30 alGenBuffers (1, &buffer);
31 alBufferData (buffer, format, data, size, frequency);
34 /* Generate a single source, attach the buffer to it and start playing. */
35 alGenSources (1, &source);
36 alSourcei (source, AL_BUFFER, buffer);
37 alSourcePlay (source);
39 /* Normally nothing should go wrong above, but one never knows... */
40 error = alGetError ();
41 if (error != ALUT_ERROR_NO_ERROR)
43 fprintf (stderr, "%s\n", alGetString (error));
48 /* Check every 0.1 seconds if the sound is still playing. */
52 alGetSourcei (source, AL_SOURCE_STATE, &status);
54 while (status == AL_PLAYING);
58 main (int argc, char **argv)
60 /* Initialise ALUT and eat any ALUT-specific commandline flags. */
61 if (!alutInit (&argc, argv))
63 ALenum error = alutGetError ();
64 fprintf (stderr, "%s\n", alutGetErrorString (error));
68 /* If everything is OK, play the sound files and exit when finished. */
69 playFile ("file1.wav");
73 ALenum error = alutGetError ();
74 fprintf (stderr, "%s\n", alutGetErrorString (error));