dungeon_crawler

view prototype/src/audio/audio.cc @ 48:aa9e28670ae2

added sound playback, more to do
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 17 Sep 2012 08:40:59 +0300
parents d52711f2b9a1
children c40efa9cf844
line source
1 #include <stdio.h>
2 #include "openal.h"
3 #include "audio.h"
5 static ALCdevice *dev;
6 static ALCcontext *ctx;
9 bool init_audio()
10 {
11 if(dev) {
12 return true;
13 }
15 if(!(dev = alcOpenDevice(0))) {
16 fprintf(stderr, "failed to open OpenAL device\n");
17 return false;
18 }
19 ctx = alcCreateContext(dev, 0);
20 alcMakeContextCurrent(ctx);
22 alGetError(); // clear error code
23 return true;
24 }
26 void destroy_audio()
27 {
28 alcMakeContextCurrent(0);
29 if(ctx) {
30 alcDestroyContext(ctx);
31 }
32 if(dev) {
33 alcCloseDevice(dev);
34 }
35 }