assman was renamed to assfile
[laserbrain_demo] / src / audio / audio.cc
1 #include <stdio.h>
2 #include "audio.h"
3
4 #include "openal.h"
5
6 static ALCdevice *dev;
7 static ALCcontext *ctx;
8
9 bool init_audio()
10 {
11         if(!(dev = alcOpenDevice(0))) {
12                 fprintf(stderr, "failed to open OpenAL device\n");
13                 return false;
14         }
15
16         if(!(ctx = alcCreateContext(dev, 0))) {
17                 fprintf(stderr, "failed to create context\n");
18                 alcCloseDevice(dev);
19                 return false;
20         }
21
22         alcMakeContextCurrent(ctx);
23
24         alGetError();
25         return true;
26 }
27
28 void destroy_audio()
29 {
30         printf("shutting down audio system\n");
31         alcMakeContextCurrent(0);
32
33         if(ctx) {
34                 alcDestroyContext(ctx);
35                 ctx = 0;
36         }
37
38         if(dev) {
39                 alcCloseDevice(dev);
40                 dev = 0;
41         }
42 }
43
44 void set_audio_listener(const Mat4 &xform)
45 {
46         float pos[3], orient[6];
47
48         pos[0] = xform[3][0];
49         pos[1] = xform[3][1];
50         pos[2] = xform[3][2];
51
52         orient[0] = xform[2][0];
53         orient[1] = xform[2][1];
54         orient[2] = -xform[2][2];
55
56         orient[3] = xform[1][0];
57         orient[4] = xform[1][1];
58         orient[5] = xform[1][2];
59
60         alListenerfv(AL_POSITION, pos);
61         alListenerfv(AL_ORIENTATION, orient);
62 }