diff options
author | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2013-04-06 12:36:08 -0700 |
---|---|---|
committer | Ehsan Akhgari <ehsan.akhgari@gmail.com> | 2013-04-06 12:36:08 -0700 |
commit | 350a2b08b6b19e57abc57e6ae607edae97a66fa8 (patch) | |
tree | 5de65f8e9c83101a2444449d755a71785bb76436 /tests/freealut/test_suite/test_fileloader.c | |
parent | 75c7e03bc5e282ee3969924c225a0e4545d5258b (diff) | |
parent | 6512c70b5487a9328e19a64f8118529eb4f77b55 (diff) |
Merge pull request #1010 from azmeuk/openal
Minor OpenAL improvements.
Diffstat (limited to 'tests/freealut/test_suite/test_fileloader.c')
-rw-r--r-- | tests/freealut/test_suite/test_fileloader.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/freealut/test_suite/test_fileloader.c b/tests/freealut/test_suite/test_fileloader.c new file mode 100644 index 00000000..ce447daf --- /dev/null +++ b/tests/freealut/test_suite/test_fileloader.c @@ -0,0 +1,74 @@ +#include <stdlib.h> +#include <stdio.h> +#include <AL/alut.h> + +/* + * This program loads and plays a variety of files, basically an automated + * version of examples/playfile.c. + */ + +static void playFile(const char *fileName) +{ + ALuint buffer; + ALuint source; + ALenum error; + ALint status; + + /* Create an AL buffer from the given sound file. */ + buffer = alutCreateBufferFromFile(fileName); + if (buffer == AL_NONE) + { + error = alutGetError(); + fprintf(stderr, "Error loading file: '%s'\n", alutGetErrorString(error)); + alutExit(); + exit(EXIT_FAILURE); + } + + /* Generate a single source, attach the buffer to it and start playing. */ + alGenSources(1, &source); + alSourcei(source, AL_BUFFER, buffer); + alSourcePlay(source); + + /* Normally nothing should go wrong above, but one never knows... */ + error = alGetError(); + if (error != ALUT_ERROR_NO_ERROR) + { + fprintf(stderr, "%s\n", alGetString(error)); + alutExit(); + exit(EXIT_FAILURE); + } + + /* Check every 0.1 seconds if the sound is still playing. */ + do + { + alutSleep(0.1f); + alGetSourcei(source, AL_SOURCE_STATE, &status); + } + while (status == AL_PLAYING); +} + +int main(int argc, char **argv) +{ + /* Initialise ALUT and eat any ALUT-specific commandline flags. */ + if (!alutInit(&argc, argv)) + { + ALenum error = alutGetError(); + + fprintf(stderr, "%s\n", alutGetErrorString(error)); + exit(EXIT_FAILURE); + } + + /* If everything is OK, play the sound files and exit when finished. */ + playFile("file1.wav"); + playFile("file2.au"); + playFile("file3.raw"); + + if (!alutExit()) + { + ALenum error = alutGetError(); + + fprintf(stderr, "%s\n", alutGetErrorString(error)); + exit(EXIT_FAILURE); + } + return EXIT_SUCCESS; +} |