dungeon_crawler

view prototype/src/audio/audio.cc @ 47:d52711f2b9a1

started writting audio code
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 16 Sep 2012 08:16:50 +0300
parents
children aa9e28670ae2
line source
1 #include <stdio.h>
2 #include "openal.h"
3 #include "audio.h"
5 #define CHECK_ERROR \
6 do { \
7 unsigned int err = alGetError(); \
8 if(err != 0) { \
9 fprintf(stderr, "%s:%d: AL error: %#x\n", __FILE__, __LINE__, err); \
10 abort(); \
11 } \
12 } while(0)
14 static ALCdevice *dev;
15 static ALCcontext *ctx;
18 bool init_audio()
19 {
20 if(dev) {
21 return true;
22 }
24 if(!(dev = alcOpenDevice(0))) {
25 fprintf(stderr, "failed to open OpenAL device\n");
26 return false;
27 }
28 ctx = alcCreateContext(dev, 0);
29 alcMakeContextCurrent(ctx);
31 alGetError(); // clear error code
32 return true;
33 }
35 void destroy_audio()
36 {
37 alcMakeContextCurrent(0);
38 if(ctx) {
39 alcDestroyContext(ctx);
40 }
41 if(dev) {
42 alcCloseDevice(dev);
43 }
44 }