Jamoma API  0.6.0.a19
Mic.cpp
1 // Mic.cpp
2 /***************************************************/
3 /*! \class Mic
4  \brief Microphone class
5 
6  This class implements a microphone, which consists
7  of directivity pattern, a scalar gain, 3-d coordinates,
8  azimuth angle and elevation angle.
9 
10  by Tristan Matthews and Nils Peters, 2007-2008.
11  */
12 /***************************************************/
13 
14 #include "Mic.h"
15 #include "Angle.h"
16 #include "Coordinate.h"
17 #include "ext.h"
18 #include "Moveable.h"
19 #include "Properties.h"
20 
21 extern bool globWarningFlag;
22 extern bool globReportFlag;
23 
24 Mic::Mic(double x, double y, double z, double newAzi, double newEle) : Moveable(x, y, z)
25 {
26  aziAng_ = Angle(newAzi, -180.0, 180.0, 2 * 180.0); // initial angle and constraints are defined
27  eleAng_ = Angle(newEle, -90.0, 90.0, 90.0);
28  gain_ = 1.0;
29  dirPow_ = 1.0;
30  dirGainA_ = 1.0;
31  dirGainB_ = 0.0;
32  distPow_ = -1.0;
33  //TODO: add dbUnit_
34  flag(true);
35 }
36 
37 void Mic::printPos() const
38 {
39  post("/MicPos = %f, %f, %f", xPos(), yPos(), zPos());
40 }
41 
42 void Mic::printAngles() const
43 {
44  post("/MicAzi = %f, /MicEle = %f", aziAng_() * Properties::RAD2DEG, eleAng_() * Properties::RAD2DEG);
45 }
46 
47 void Mic::reset()
48 {
49  init();
50 }
51 
52 void Mic::init()
53 {
54  gain_ = 1.0;
55  xPos(0.0);
56  yPos(0.0);
57  zPos(0.0);
58  aziAng_(0.0);
59  eleAng_(0.0);
60  dirPow_ = 1.0;
61  dirGainA_ = 1.0;
62  dirGainB_ = 0.0;
63  distPow_ = -1.0;
64  //TODO: add dbUnit_
65  flag(true);
66 }
67 
68 void Mic::azi(double newAzi)
69 {
70  aziAng_(newAzi);
71  if (globReportFlag)
72  printAngles();
73  flag(true);
74 }
75 
76 double Mic::azi() const
77 {
78  return aziAng_();
79 }
80 
81 
82 void Mic::ele(double newEle)
83 {
84  eleAng_(newEle);
85  if (globReportFlag)
86  printAngles();
87  flag(true);
88 }
89 
90 
91 double Mic::ele() const
92 {
93  return eleAng_();
94 }
95 
96 void Mic::dirGainA(double newDirGain)
97 {
98  bool capped = false;
99 
100  if (newDirGain > 1.0) {
101  newDirGain = 1.0;
102  capped = true;
103  }
104  else if (newDirGain < -1.0) {
105  newDirGain = -1.0;
106  capped = true;
107  }
108 
109  dirGainA_ = newDirGain;
110  dirGainB_ = 1.0 - dirGainA_;
111  if (capped && globWarningFlag)
112  post("Directivity gain capped at %f", dirGainA_);
113 
114  if (globReportFlag)
115  post("DirGainA: %f, DirGainB: %f", dirGainA_, dirGainB_);
116 
117  flag(true);
118 }
119 
120 
121 double Mic::dirGainA() const
122 {
123  return dirGainA_;
124 }
125 
126 double Mic::dirGainB() const
127 {
128  return dirGainB_;
129 }
130 
131 void Mic::dirPow(double newDirPow)
132 {
133  bool capped = false;
134 
135  if (newDirPow > 9.0)
136  {
137  newDirPow = 9.0;
138  capped = true;
139  }
140  else if (newDirPow < 0.0)
141  {
142  newDirPow = 0.0;
143  capped = true;
144  }
145 
146  dirPow_ = newDirPow;
147 
148  if (capped && globWarningFlag)
149  post("Directivity power capped at %f", dirPow_);
150 
151  if (globReportFlag)
152  post("Mic dirPow = %f", dirPow_);
153 
154  flag(true);
155 }
156 
157 
158 double Mic::dirPow() const
159 {
160  return dirPow_;
161 }
162 
163 void Mic::distPow(double newDistPow)
164 {
165  bool capped = false;
166 
167  if (newDistPow > 9.0)
168  {
169  newDistPow = 9.0;
170  capped = true;
171  }
172  else if (newDistPow < 0.0)
173  {
174  newDistPow = 0.0;
175  capped = true;
176  }
177  newDistPow = -1.0 * newDistPow; // optimization, for sensi calculation
178  distPow_ = newDistPow;
179  if (capped && globWarningFlag)
180  post("Distance power capped at %f", distPow_);
181 
182  if (globReportFlag)
183  post("Mic distpow = %f", distPow_);
184  flag(true);
185 }
186 
187 
188 double Mic::distPow() const
189 {
190  return distPow_;
191 }
192 
193 void Mic::dbUnit(double newDbUnit)
194 {
195  bool capped = false;
196 
197  if (newDbUnit > 60.0)
198  {
199  newDbUnit = 60.0;
200  capped = true;
201  }
202  else if (newDbUnit < 0.0)
203  {
204  newDbUnit = 0.0;
205  capped = true;
206  }
207  newDbUnit = -0.05 * newDbUnit;
208  dbUnit_ = newDbUnit;
209  if (capped && globWarningFlag)
210  post("dB Unit for exponential distance model capped at %f", dbUnit_);
211 
212  if (globReportFlag)
213  post("dB Unit for exponential distance model = %f", dbUnit_);
214  flag(true);
215 }
216 
217 double Mic::dbUnit() const
218 {
219  return dbUnit_;
220 }
221 
222 
223 
224 void Mic::gain(double newGain)
225 {
226  bool capped = false;
227 
228  if (newGain > 1.0)
229  {
230  newGain = 1.0;
231  capped = true;
232  }
233  else if (newGain < 0.0)
234  {
235  newGain = 0.0;
236  capped = true;
237  }
238 
239  gain_ = newGain;
240  if (capped && globWarningFlag)
241  post("Mic gain capped at %f", gain_);
242 
243  if (globReportFlag)
244  post("Mic gain = %f", gain_);
245 
246  flag(true);
247 }
248 
249 double Mic::gain() const
250 {
251  return gain_;
252 }
253 
255 {
256 }
257 
258 // vim:sw=4:et:cindent:
double gain() const
Get gain.
Definition: Mic.cpp:249
double azi() const
Get azimuth angle.
Definition: Mic.cpp:76
virtual void printPos() const
Print position in x,y,z.
Definition: Mic.cpp:37
void printAngles() const
Print azimuth and elevation.
Definition: Mic.cpp:42
Mic(double x, double y, double z, double azi, double ele)
Class constructor, taking 3d position and azimuth and elevation angles.
Definition: Mic.cpp:24
double distPow() const
Get distance power.
Definition: Mic.cpp:188
double xPos() const
Get x position.
Definition: Moveable.cpp:26
virtual ~Mic()
Class destructor.
Definition: Mic.cpp:254
void reset()
Reset microphone to default values.
Definition: Mic.cpp:47
double dirPow() const
Get directivity power.
Definition: Mic.cpp:158
double dirGainB() const
Get directivity gain b.
Definition: Mic.cpp:126
bool flag() const
True if object has moved.
Definition: Moveable.cpp:65
double dirGainA() const
Get directivity gain a.
Definition: Mic.cpp:121
double ele() const
Get elevation angle.
Definition: Mic.cpp:91
double zPos() const
Get z position.
Definition: Moveable.cpp:52
double dbUnit() const
Get distance power.
Definition: Mic.cpp:217
Moveable class.
Definition: Moveable.h:18
Angle class.
Definition: Angle.h:18
double yPos() const
Get y position.
Definition: Moveable.cpp:39