6
* This program loads and plays a variety of files, basically an automated
7
* version of examples/playfile.c.
10
static void playFile(const char *fileName)
17
/* Create an AL buffer from the given sound file. */
18
buffer = alutCreateBufferFromFile(fileName);
19
if (buffer == AL_NONE)
21
error = alutGetError();
22
fprintf(stderr, "Error loading file: '%s'\n", alutGetErrorString(error));
27
/* Generate a single source, attach the buffer to it and start playing. */
28
alGenSources(1, &source);
29
alSourcei(source, AL_BUFFER, buffer);
32
/* Normally nothing should go wrong above, but one never knows... */
34
if (error != ALUT_ERROR_NO_ERROR)
36
fprintf(stderr, "%s\n", alGetString(error));
41
/* Check every 0.1 seconds if the sound is still playing. */
45
alGetSourcei(source, AL_SOURCE_STATE, &status);
47
while (status == AL_PLAYING);
50
int main(int argc, char **argv)
52
/* Initialise ALUT and eat any ALUT-specific commandline flags. */
53
if (!alutInit(&argc, argv))
55
ALenum error = alutGetError();
57
fprintf(stderr, "%s\n", alutGetErrorString(error));
61
/* If everything is OK, play the sound files and exit when finished. */
62
playFile("file1.wav");
64
playFile("file3.raw");
68
ALenum error = alutGetError();
70
fprintf(stderr, "%s\n", alutGetErrorString(error));