1 #include <stdio.h>
2
3 #include "AL/alure.h"
4
5 volatile int isdone = 0;
eos_callback(void * unused,ALuint unused2)6 static void eos_callback(void *unused, ALuint unused2)
7 {
8 isdone = 1;
9 (void)unused;
10 (void)unused2;
11 }
12
main(int argc,char ** argv)13 int main( int argc, char **argv)
14 {
15 ALuint src, buf;
16
17 if(argc < 2)
18 {
19 fprintf(stderr, "Usage %s <soundfile>\n", argv[0]);
20 return 1;
21 }
22
23 if(!alureInitDevice(NULL, NULL))
24 {
25 fprintf(stderr, "Failed to open OpenAL device: %s\n", alureGetErrorString());
26 return 1;
27 }
28
29 alGenSources(1, &src);
30 if(alGetError() != AL_NO_ERROR)
31 {
32 fprintf(stderr, "Failed to create OpenAL source!\n");
33 alureShutdownDevice();
34 return 1;
35 }
36
37 buf = alureCreateBufferFromFile(argv[1]);
38 if(!buf)
39 {
40 fprintf(stderr, "Could not load %s: %s\n", argv[1], alureGetErrorString());
41 alDeleteSources(1, &src);
42
43 alureShutdownDevice();
44 return 1;
45 }
46
47 alSourcei(src, AL_BUFFER, buf);
48 if(alurePlaySource(src, eos_callback, NULL) == AL_FALSE)
49 {
50 fprintf(stderr, "Failed to start source!\n");
51 alDeleteSources(1, &src);
52 alDeleteBuffers(1, &buf);
53
54 alureShutdownDevice();
55 return 1;
56 }
57
58 while(!isdone)
59 {
60 alureSleep(0.125);
61 alureUpdate();
62 }
63
64 alDeleteSources(1, &src);
65 alDeleteBuffers(1, &buf);
66
67 alureShutdownDevice();
68 return 0;
69 }
70