1 module polyplex.core.audio.device;
2 import polyplex.core.audio;
3 import ppc.audio;
4 import derelict.openal;
5 
6 public enum ALExtensionSupport {
7 	/**
8 		Basic OpenAL context is supported.
9 	*/
10 	Basic = 0x00,
11 
12 	/**
13 		EAX 2.0 is supported.
14 	*/
15 	EAX2 = 0x01
16 	// TODO add more extensions here.
17 }
18 
19 public static AudioDevice DefaultAudioDevice;
20 
21 public class AudioDevice {
22 	public ALCdevice* ALDevice;
23 	public ALCcontext* ALContext;
24 	public ALExtensionSupport SupportedExt;
25 
26 	/**
27 		Constucts an audio device, NULL for preffered device.
28 	*/
29 	this(string device = null) {
30 		ALCdevice* dev = alcOpenDevice(device.ptr);
31 		if (dev) {
32 			ALContext = alcCreateContext(dev, null);
33 			alcMakeContextCurrent(ALContext);
34 		} else {
35 			throw new Exception("Could not create device!");
36 		}
37 		
38 		// If EAX 2.0 is supported, flag it as supported.
39 		bool supex = cast(bool)alIsExtensionPresent("EAX2.0");
40 		if (supex) SupportedExt |= ALExtensionSupport.EAX2;
41 	}
42 
43 	~this() {
44 		alcMakeContextCurrent(null);
45 		alcDestroyContext(ALContext);
46 		alcCloseDevice(ALDevice);
47 	}
48 
49 	/**
50 		Makes the context for this device, a current context.
51 	*/
52 	public void MakeCurrent() {
53 		alcMakeContextCurrent(ALContext);
54 	}
55 
56 	public ALBuffer GenerateBuffer(Audio aud) {
57 		return new ALBuffer(aud);
58 	}
59 }