1 module evael.audio.AudioDevice;
2 
3 import std.exception;
4 
5 import evael.audio.AL;
6 
7 /**
8  * AudioDevice
9  */
10 class AudioDevice
11 {
12 	private ALCdevice*  m_audioDevice;
13 	private ALCcontext* m_audioContext;
14 
15 	/**
16 	 * AudioDevice constructor.
17 	 */
18 	public this()
19 	{
20 		this.m_audioDevice = alcOpenDevice(null);
21 
22 		enforce(this.m_audioDevice !is null, "Failed to open the audio device");
23 
24 		this.m_audioContext = alcCreateContext(this.m_audioDevice, null);
25 
26 		enforce(this.m_audioContext !is null, "Failed to create the audio context");
27 
28 		alcMakeContextCurrent(this.m_audioContext);
29 
30 		this.initialize();
31 	}
32 	
33 	/**
34 	 * AudioDevice destructor.
35 	 */
36 	@nogc
37 	public void dispose() nothrow
38 	{
39 		alcMakeContextCurrent(null);
40 
41 		if (this.m_audioContext !is null)
42 		{
43 			alcDestroyContext(this.m_audioContext);
44 		}
45 
46 		if (this.m_audioDevice !is null)
47 		{
48 			alcCloseDevice(this.m_audioDevice);
49 		}
50 	}
51 
52 	/**
53 	 * Initializes the device.
54 	 */
55 	@nogc
56 	private void initialize() nothrow
57 	{
58 		al.Listener3f(AL_POSITION, 0, 0, 0);
59 		al.Listener3f(AL_VELOCITY, 0, 0, 0);
60 	}
61 }