8 * This program loads and plays a variety of files.
12 playFile (const char *fileName)
19 /* Create an AL buffer from the given sound file. */
20 buffer = alutCreateBufferFromFile (fileName);
21 if (buffer == AL_NONE)
23 error = alutGetError ();
24 fprintf (stderr, "Error loading file: '%s'\n",
25 alutGetErrorString (error));
30 /* Generate a single source, attach the buffer to it and start playing. */
31 alGenSources (1, &source);
32 alSourcei (source, AL_BUFFER, buffer);
33 alSourcePlay (source);
35 /* Normally nothing should go wrong above, but one never knows... */
36 error = alGetError ();
37 if (error != ALUT_ERROR_NO_ERROR)
39 fprintf (stderr, "%s\n", alGetString (error));
44 /* Check every 0.1 seconds if the sound is still playing. */
48 alGetSourcei (source, AL_SOURCE_STATE, &status);
50 while (status == AL_PLAYING);
54 main (int argc, char **argv)
56 /* Initialise ALUT and eat any ALUT-specific commandline flags. */
57 if (!alutInit (&argc, argv))
59 ALenum error = alutGetError ();
60 fprintf (stderr, "%s\n", alutGetErrorString (error));
64 /* Check for correct usage. */
67 fprintf (stderr, "usage: playfile <fileName>\n");
72 /* If everything is OK, play the sound file and exit when finished. */
77 ALenum error = alutGetError ();
78 fprintf (stderr, "%s\n", alutGetErrorString (error));