6 * This program loads and plays a variety of files, basically an automated
7 * version of examples/playfile.c.
11 playFile (const char *fileName)
18 /* Create an AL buffer from the given sound file. */
19 buffer = alutCreateBufferFromFile (fileName);
20 if (buffer == AL_NONE)
22 error = alutGetError ();
23 fprintf (stderr, "Error loading file: '%s'\n",
24 alutGetErrorString (error));
29 /* Generate a single source, attach the buffer to it and start playing. */
30 alGenSources (1, &source);
31 alSourcei (source, AL_BUFFER, buffer);
32 alSourcePlay (source);
34 /* Normally nothing should go wrong above, but one never knows... */
35 error = alGetError ();
36 if (error != ALUT_ERROR_NO_ERROR)
38 fprintf (stderr, "%s\n", alGetString (error));
43 /* Check every 0.1 seconds if the sound is still playing. */
47 alGetSourcei (source, AL_SOURCE_STATE, &status);
49 while (status == AL_PLAYING);
53 main (int argc, char **argv)
55 /* Initialise ALUT and eat any ALUT-specific commandline flags. */
56 if (!alutInit (&argc, argv))
58 ALenum error = alutGetError ();
59 fprintf (stderr, "%s\n", alutGetErrorString (error));
63 /* If everything is OK, play the sound files and exit when finished. */
64 playFile ("file1.wav");
65 playFile ("file2.au");
66 playFile ("file3.raw");
70 ALenum error = alutGetError ();
71 fprintf (stderr, "%s\n", alutGetErrorString (error));