dungeon_crawler
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/prototype/src/audio/audio.cc Sun Sep 16 08:16:50 2012 +0300 1.3 @@ -0,0 +1,44 @@ 1.4 +#include <stdio.h> 1.5 +#include "openal.h" 1.6 +#include "audio.h" 1.7 + 1.8 +#define CHECK_ERROR \ 1.9 + do { \ 1.10 + unsigned int err = alGetError(); \ 1.11 + if(err != 0) { \ 1.12 + fprintf(stderr, "%s:%d: AL error: %#x\n", __FILE__, __LINE__, err); \ 1.13 + abort(); \ 1.14 + } \ 1.15 + } while(0) 1.16 + 1.17 +static ALCdevice *dev; 1.18 +static ALCcontext *ctx; 1.19 + 1.20 + 1.21 +bool init_audio() 1.22 +{ 1.23 + if(dev) { 1.24 + return true; 1.25 + } 1.26 + 1.27 + if(!(dev = alcOpenDevice(0))) { 1.28 + fprintf(stderr, "failed to open OpenAL device\n"); 1.29 + return false; 1.30 + } 1.31 + ctx = alcCreateContext(dev, 0); 1.32 + alcMakeContextCurrent(ctx); 1.33 + 1.34 + alGetError(); // clear error code 1.35 + return true; 1.36 +} 1.37 + 1.38 +void destroy_audio() 1.39 +{ 1.40 + alcMakeContextCurrent(0); 1.41 + if(ctx) { 1.42 + alcDestroyContext(ctx); 1.43 + } 1.44 + if(dev) { 1.45 + alcCloseDevice(dev); 1.46 + } 1.47 +}