~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/freealut/test_suite/test_fileloader.c

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <stdio.h>
 
3
#include <AL/alut.h>
 
4
 
 
5
/*
 
6
 * This program loads and plays a variety of files, basically an automated
 
7
 * version of examples/playfile.c.
 
8
 */
 
9
 
 
10
static void playFile(const char *fileName)
 
11
{
 
12
  ALuint buffer;
 
13
  ALuint source;
 
14
  ALenum error;
 
15
  ALint status;
 
16
 
 
17
  /* Create an AL buffer from the given sound file. */
 
18
  buffer = alutCreateBufferFromFile(fileName);
 
19
  if (buffer == AL_NONE)
 
20
  {
 
21
    error = alutGetError();
 
22
    fprintf(stderr, "Error loading file: '%s'\n", alutGetErrorString(error));
 
23
    alutExit();
 
24
    exit(EXIT_FAILURE);
 
25
  }
 
26
 
 
27
  /* Generate a single source, attach the buffer to it and start playing. */
 
28
  alGenSources(1, &source);
 
29
  alSourcei(source, AL_BUFFER, buffer);
 
30
  alSourcePlay(source);
 
31
 
 
32
  /* Normally nothing should go wrong above, but one never knows... */
 
33
  error = alGetError();
 
34
  if (error != ALUT_ERROR_NO_ERROR)
 
35
  {
 
36
    fprintf(stderr, "%s\n", alGetString(error));
 
37
    alutExit();
 
38
    exit(EXIT_FAILURE);
 
39
  }
 
40
 
 
41
  /* Check every 0.1 seconds if the sound is still playing. */
 
42
  do
 
43
  {
 
44
    alutSleep(0.1f);
 
45
    alGetSourcei(source, AL_SOURCE_STATE, &status);
 
46
  }
 
47
  while (status == AL_PLAYING);
 
48
}
 
49
 
 
50
int main(int argc, char **argv)
 
51
{
 
52
  /* Initialise ALUT and eat any ALUT-specific commandline flags. */
 
53
  if (!alutInit(&argc, argv))
 
54
  {
 
55
    ALenum error = alutGetError();
 
56
 
 
57
    fprintf(stderr, "%s\n", alutGetErrorString(error));
 
58
    exit(EXIT_FAILURE);
 
59
  }
 
60
 
 
61
  /* If everything is OK, play the sound files and exit when finished. */
 
62
  playFile("file1.wav");
 
63
  playFile("file2.au");
 
64
  playFile("file3.raw");
 
65
 
 
66
  if (!alutExit())
 
67
  {
 
68
    ALenum error = alutGetError();
 
69
 
 
70
    fprintf(stderr, "%s\n", alutGetErrorString(error));
 
71
    exit(EXIT_FAILURE);
 
72
  }
 
73
  return EXIT_SUCCESS;
 
74
}