Jamoma API  0.6.0.a19
MicArray.cpp
1 // MicArray.cpp
2 // A collection of mics that allows position changes to be applied to all its members.
3 // TODO: Have real out of bounds error
4 
5 #include "MicArray.h"
6 #include "Mic.h"
7 #include "Properties.h"
8 #include "Angle.h"
9 #include "TTBase.h"
10 #include <cassert>
11 #include <vector>
12 
13 extern bool globReportFlag;
14 
15 int MicArray::AziAngle[Properties::MAXNUMCHANNELS][Properties::MAXNUMCHANNELS] = { // first NumOfChannels, second Speaker Angle
16  /* 1ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
17  /* 2ch */ {-30,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
18  /* 3ch */ {-30,0,30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
19  /* 4ch */ {-135,-45,45,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
20  /* 5ch */ {-110,-30,0,30,110,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
21  /* 6ch */ {-110,-30,0,30,110,180,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
22  /* 7ch */ {-110,-30,0,30,110,180,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
23  /* 8ch */ {0,45,90,135,180,-135,-90,-45,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, //{-135,-90,-45,0,45,90,135,180,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, // 8 channels
24  /* 9ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
25  /* 10ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
26  /* 11ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
27  /* 12ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
28  /* 13ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
29  /* 14ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
30  /* 15ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
31  // /* 16ch */ {0,22.5,45,67.5,90,112.5,135,157.5,180,-157.5,-135,-112.5,-90,-67.5,-45,-22.5,0,0,0,0,0,0,0,0},
32  /* 16ch */ {0,22,45,67,90,112,135,157,180,-157,-135,-112,-90,-67,-45,-22,0,0,0,0,0,0,0,0},
33  //{-157.5,-135,-112.5,-90,-67.5,-45,-22.5,0,22.5,45,67.5,90,112.5,135,157.5,180,0,0,0,0,0,0,0,0},
34  /* 17ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
35  /* 18ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
36  /* 19ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
37 // /* 20ch */ {-157.5,-135,-112.5,-90,-67.5,-45,-22.5,0,22.5,45,67.5,90,112.5,135,157.5,180,-135,-45,45,135,0,0,0,0},
38  /* 20ch */ {-157,-135,-112,-90,-67,-45,-22,0,22,45,67,90,112,135,157,180,-135,-45,45,135,0,0,0,0},
39  /* 21ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
40  /* 22ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
41  /* 23ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
42  /* 24ch */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
43 };
44 
45 MicArray::MicArray(short initNumChannels)
46 {
47  centerLR_ = 0.0;
48  centerFB_ = 0.0;
49  centerUD_ = 0.0;
50  centerDistance_ = 0; //NP: was 5
51 
52  if (initNumChannels <= Properties::MAXNUMCHANNELS && initNumChannels > 0)
53  numChannels_ = initNumChannels;
54  else
55  numChannels_ = 8;
56 
57  for (int i = 0; i < numChannels_; i++)
58  mics.push_back(Mic(0.0, 0.0, 0.0, AziAngle[numChannels_ - 1][i], 0.0));
59  flag_ = true;
60 }
61 
63 
64 void MicArray::centerLR(double newCenterLR)
65 {
66  centerLR_ = newCenterLR;
67  renderMics();
68 }
69 
70 void MicArray::centerFB(double newCenterFB)
71 {
72  centerFB_ = newCenterFB;
73  renderMics();
74 }
75 
76 void MicArray::centerUD(double newCenterUD)
77 {
78  centerUD_ = newCenterUD;
79  renderMics();
80 }
81 
82 void MicArray::centerDistance(double newCenterDistance)
83 {
84  centerDistance_ = newCenterDistance;
85  renderMics();
86 }
87 
88 // recalculates all mic positions
90 {
91  for (int m = 0; m < numChannels_; m++)
92  renderMic(m);
93  flag_ = true;
94 }
95 
96 // updates the mic position based on the current array geometry
98 {
99  double temp;
100 
101  temp = (double)(AziAngle[numChannels_ - 1][m] * Angle::PI_X_180);
102 
103  mics[m].xPos(centerLR_ + sin((double) temp) * centerDistance_);
104  mics[m].yPos(centerFB_ + cos((double) temp) * centerDistance_);
105  mics[m].zPos(centerUD_);
106  mics[m].azi(AziAngle[numChannels_ - 1][m]);
107  mics[m].ele(0);
108 }
109 
110 // returns reference to Mic at position index
111 Mic& MicArray::operator [](const int index)
112 {
113  assert(index >= 0 && index < numChannels_); // should already be checked at higher level
114  return mics[index];
115 }
116 
117 // returns reference to Mic at position index (const version)
118 const Mic& MicArray::operator [](const int index) const
119 {
120  assert(index >= 0 && index < numChannels_); // should already be checked at higher level
121  return mics[index];
122 }
123 
125 { double rad2deg_ = 180.0/kTTPi;
126  post("Number of Channels: %d", numChannels_);
127  post("Mic Array Center: %f, %f, %f, Distance: %f", centerLR_, centerFB_, centerUD_, centerDistance_);
128  int m = 0;
129  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++, m++)
130  {
131  post("Mic %d: Pos: %f, %f, %f ::::: Orientation: %f azimuth, %f elevation", m + 1, iter->xPos(), iter->yPos(), iter->zPos(), iter->azi()*rad2deg_, iter->ele()*rad2deg_);
132  post("Directivitiy: %f, DirPow: %f, DisPow: %f", iter->dirGainA(), iter->dirPow(), -1.0*iter->distPow());
133  }
134 }
135 
137 {
138  if (b > 0 && b <= numChannels_)
139  return true;
140  else
141  return false;
142 }
143 
144 void MicArray::distPow(double newDistPow)
145 {
146  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
147  iter->distPow(newDistPow);
148  flag_ = true;
149 }
150 
151 void MicArray::dbUnit(double newDbUnit)
152 {
153  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
154  iter->dbUnit(newDbUnit);
155  flag_ = true;
156 }
157 
158 void MicArray::dirGain(double newDirGain)
159 {
160  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
161  iter->dirGainA(newDirGain);
162  flag_ = true;
163 }
164 
165 void MicArray::gain(double newGain)
166 {
167  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
168  iter->gain(newGain);
169  flag_ = true;
170 }
171 
172 void MicArray::dirPow(double newDirPow)
173 {
174  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
175  iter->dirPow(newDirPow);
176  flag_ = true;
177 }
178 
179 void MicArray::xPos(double newXpos)
180 {
181  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
182  iter->xPos(newXpos);
183  flag_ = true;
184 }
185 
186 void MicArray::yPos(double newYpos)
187 {
188  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
189  iter->yPos(newYpos);
190  flag_ = true;
191 }
192 
193 void MicArray::zPos(double newZpos)
194 {
195  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
196  iter->zPos(newZpos);
197  flag_ = true;
198 }
199 
200 void MicArray::azi(double newAzi)
201 {
202  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
203  iter->azi(newAzi);
204  flag_ = true;
205 }
206 
207 void MicArray::ele(double newEle)
208 {
209  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
210  iter->ele(newEle);
211  flag_ = true;
212 }
213 
214 void MicArray::flag(bool changed)
215 {
216  flag_ = changed;
217 }
218 
219 bool MicArray::flag() const
220 {
221  return flag_;
222 }
223 
224 bool MicArray::checkWidth(double newWidth)
225 {
226  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
227  {
228  if (!iter->checkWidth(newWidth))
229  return false;
230  }
231  return true;
232 }
233 
234 bool MicArray::checkDepth(double newDepth)
235 {
236  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
237  {
238  if (!iter->checkDepth(newDepth))
239  return false;
240  }
241  return true;
242 }
243 
244 bool MicArray::checkHeight(double newHeight)
245 {
246  for (std::vector<Mic>::iterator iter = mics.begin(); iter != mics.end(); iter++)
247  {
248  if (!iter->checkHeight(newHeight))
249  return false;
250  }
251  return true;
252 }
253 
255 {
256  return numChannels_;
257 }
258 
259 // vim:sw=4:et:cindent:
~MicArray()
Class destructor.
Definition: MicArray.cpp:62
void distPow(double pow)
Sets all of the MicArray's mics' distance powers.
Definition: MicArray.cpp:144
static const double PI_X_180
Constant to convert degrees to radians.
Definition: Angle.h:36
void dirPow(double pow)
Sets all of the MicArray's mics' directivity powers.
Definition: MicArray.cpp:172
void centerUD(double newCenterUD)
Set center in z.
Definition: MicArray.cpp:76
void dirGain(double gain)
Sets all of the MicArray's mics' directivity gains.
Definition: MicArray.cpp:158
short numChannels() const
Returns the size of the mic array.
Definition: MicArray.cpp:254
void azi(double azi)
Sets all of the MicArray's mics' azimuth angles.
Definition: MicArray.cpp:200
void ele(double ele)
Sets all of the MicArray's mics' elevation angles.
Definition: MicArray.cpp:207
void xPos(double x)
Sets all of the MicArray's mics' x positions to x.
Definition: MicArray.cpp:179
bool flag() const
Returns true if the mic array has changed, false otherwise.
Definition: MicArray.cpp:219
bool checkDepth(double newDepth)
Checks that new room depth will not exclude any mics.
Definition: MicArray.cpp:234
MicArray(short numMics)
Class constructor.
Definition: MicArray.cpp:45
bool validChannel(short channelNum=8)
True if the channel num >= 0 and < the total number of channels.
Definition: MicArray.cpp:136
bool checkHeight(double newHeight)
Checks that new room height will not exclude any mics.
Definition: MicArray.cpp:244
Jamoma's lowest-level base class and related infrastructure.
void centerDistance(double rad)
Set mic array's radius.
Definition: MicArray.cpp:82
void gain(double gain)
Sets all of the MicArray's mics' gain.
Definition: MicArray.cpp:165
void renderMics()
Updates all mics.
Definition: MicArray.cpp:89
void renderMic(int mic)
Updates the specified mic.
Definition: MicArray.cpp:97
Microphone class.
Definition: Mic.h:22
Mic & operator[](const int idx)
Returns the mic at the given index.
Definition: MicArray.cpp:111
void zPos(double z)
Sets all of the MicArray's mics' z positions to z.
Definition: MicArray.cpp:193
void centerFB(double newCenterFB)
Set center in y.
Definition: MicArray.cpp:70
void centerLR(double newCenterLR)
Set center in x.
Definition: MicArray.cpp:64
void yPos(double y)
Sets all of the MicArray's mics' y positions to y.
Definition: MicArray.cpp:186
TTFOUNDATION_EXPORT const TTFloat64 kTTPi
[doxygenAppendixC_constExample]
Definition: TTBase.cpp:23
bool checkWidth(double newWidth)
Checks that new room width will not exclude any mics.
Definition: MicArray.cpp:224
void dbUnit(double dbUnit)
Sets all of the MicArray's mics' dB unit.
Definition: MicArray.cpp:151
void print()
Prints information about all of the mics.
Definition: MicArray.cpp:124