1 /* 2 DSFML - The Simple and Fast Multimedia Library for D 3 4 Copyright (c) 2013 - 2015 Jeremy DeHaan (dehaan.jeremiah@gmail.com) 5 6 This software is provided 'as-is', without any express or implied warranty. 7 In no event will the authors be held liable for any damages arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, including commercial applications, 10 and to alter it and redistribute it freely, subject to the following restrictions: 11 12 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. 13 If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 14 15 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 16 17 3. This notice may not be removed or altered from any source distribution 18 */ 19 20 module dsfml.audio.listener; 21 22 import dsfml.system.vector3; 23 24 /++ 25 + The audio listener is the point in the scene from where all the sounds are heard. 26 + 27 + The audio listener defines the global properties of the audio environment, it defines where and how sounds and musics are heard. 28 + 29 + If View is the eyes of the user, then Listener is his ears (by the way, they are often linked together – same position, orientation, etc.). 30 + 31 + Listener is a simple interface, which allows to setup the listener in the 3D audio environment (position and direction), and to adjust the global volume. 32 + 33 + Because the listener is unique in the scene, Listener only contains static functions and doesn't have to be instanciated. 34 + 35 + See_Also: http://www.sfml-dev.org/documentation/2.0/classsf_1_1Listener.php#details 36 + Authors: Laurent Gomila, Jeremy DeHaan 37 +/ 38 final abstract class Listener 39 { 40 /** 41 * The orientation of the listener in the scene. The orientation defines the 3D axes of the listener (left, up, front) in the scene. The orientation vector doesn't have to be normalized. 42 * 43 * The default listener's orientation is (0, 0, -1). 44 */ 45 @property 46 { 47 static void Direction(Vector3f orientation) 48 { 49 sfListener_setDirection(orientation.x, orientation.y, orientation.z); 50 } 51 52 static Vector3f Direction() 53 { 54 Vector3f temp; 55 56 sfListener_getDirection(&temp.x, &temp.y, &temp.z); 57 58 return temp; 59 } 60 } 61 62 /** 63 * The global volume of all the sounds and musics. The volume is a number between 0 and 100; it is combined with the individual volume of each sound / music. 64 * 65 * The default value for the volume is 100 (maximum). 66 */ 67 @property 68 { 69 static void GlobalVolume(float volume) 70 { 71 sfListener_setGlobalVolume(volume); 72 } 73 74 static float GlobalVolume() 75 { 76 return sfListener_getGlobalVolume(); 77 } 78 79 } 80 81 /// The position of the listener in the scene. 82 /// The default listener's position is (0, 0, 0). 83 @property 84 { 85 static void Position(Vector3f position) 86 { 87 sfListener_setPosition(position.x, position.y, position.z); 88 } 89 90 static Vector3f Position() 91 { 92 Vector3f temp; 93 94 sfListener_getPosition(&temp.x, &temp.y, &temp.z); 95 96 return temp; 97 } 98 } 99 } 100 101 unittest 102 { 103 version(DSFML_Unittest_Audio) 104 { 105 import std.stdio; 106 107 writeln("Unit test for Listener"); 108 109 float volume = Listener.GlobalVolume; 110 volume-=10; 111 Listener.GlobalVolume = volume; 112 113 114 Vector3f pos = Listener.Position; 115 pos.x += 10; 116 pos.y -= 10; 117 pos.z *= 3; 118 Listener.Position = pos; 119 120 Vector3f dir = Listener.Direction; 121 dir.x += 10; 122 dir.y -= 10; 123 dir.z *= 3; 124 Listener.Direction = dir; 125 writeln("Unit tests pass!"); 126 writeln(); 127 } 128 } 129 130 private extern(C): 131 132 void sfListener_setGlobalVolume(float volume); 133 134 float sfListener_getGlobalVolume(); 135 136 void sfListener_setPosition(float x, float y, float z); 137 138 void sfListener_getPosition(float* x, float* y, float* z); 139 140 void sfListener_setDirection(float x, float y, float z); 141 142 void sfListener_getDirection(float* x, float* y, float* z); 143