1 module evael.audio.Source; 2 3 import evael.audio.AL; 4 import evael.audio.AudioException; 5 6 import evael.utils.Math; 7 8 import evael.system.Asset; 9 10 /** 11 * Source. 12 */ 13 struct Source 14 { 15 /// Buffer id. 16 private uint m_buffer; 17 18 /// Source id. 19 private uint m_id; 20 21 /** 22 * Source constructor. 23 * Params: 24 * id : AL source id 25 * buffer : AL sound id 26 */ 27 @nogc 28 public this(in uint id, in uint buffer) nothrow 29 { 30 this.m_id = id; 31 this.m_buffer = buffer; 32 33 this.volume = 1.0f; 34 this.pitch = 1.0f; 35 this.position = vec3(0); 36 } 37 38 /** 39 * Plays the current source. 40 */ 41 @nogc 42 public void play() nothrow 43 { 44 al.Sourcei(this.m_id, AL_BUFFER, this.m_buffer); 45 al.SourcePlay(this.m_id); 46 } 47 48 /** 49 * Stops current source. 50 */ 51 @nogc 52 public void stop() nothrow 53 { 54 al.SourceStop(this.m_id); 55 } 56 57 /** 58 * Properties 59 */ 60 @nogc 61 @property nothrow 62 { 63 public void volume(in float value) 64 { 65 al.Sourcef(this.m_id, AL_GAIN, value); 66 } 67 68 public void pitch(in float value) 69 { 70 al.Sourcef(this.m_id, AL_PITCH, value); 71 } 72 73 public void position()(in auto ref vec3 value) 74 { 75 al.Source3f(this.m_id, AL_POSITION, value.x, value.y, value.z); 76 } 77 78 public void loop(in bool value) 79 { 80 al.Sourcei(this.m_id, AL_LOOPING, value); 81 } 82 } 83 }