/Users/lyon/j4p/src/sound/filterDesign/ControlBean.java

1    package sound.filterDesign; 
2     
3    // Decompiled by Jad v1.5.8c. Copyright 2001 Pavel Kouznetsov. 
4    // Jad home page: http://www.geocities.com/kpdus/jad.html 
5    // Decompiler options: packimports(3)  
6    // Source File Name:   ControlBean.java 
7     
8    import java.io.Serializable; 
9    import java.util.Enumeration; 
10   import java.util.StringTokenizer; 
11   import java.util.Vector; 
12    
13   public class ControlBean 
14           implements BodeListener, Serializable, AutoscaleListener { 
15    
16       public synchronized void addBodeListener(BodeListener bodelistener) { 
17           bodeListeners.addElement(bodelistener); 
18       } 
19    
20       public synchronized void addAutoscaleListener( 
21               AutoscaleListener autoscalelistener) { 
22           autoscaleListeners.addElement(autoscalelistener); 
23       } 
24    
25       public synchronized void removeBodeListener(BodeListener bodelistener) { 
26           bodeListeners.removeElement(bodelistener); 
27       } 
28    
29       public synchronized void removeAutoscaleListener( 
30               AutoscaleListener autoscalelistener) { 
31           autoscaleListeners.removeElement(autoscalelistener); 
32       } 
33    
34       public void fireBodeEvent(BodeEvent bodeevent) { 
35           Vector vector = null; 
36           synchronized (this) { 
37               vector = (Vector) bodeListeners.clone(); 
38           } 
39           for (int i = 0; i < vector.size(); i++) { 
40               BodeListener bodelistener = (BodeListener) vector.elementAt(i); 
41               bodelistener.changeOccured(bodeevent); 
42           } 
43    
44       } 
45    
46       public void fireAutoscaleEvent(AutoscaleEvent autoscaleevent) { 
47           Vector vector = null; 
48           synchronized (this) { 
49               vector = (Vector) autoscaleListeners.clone(); 
50           } 
51           for (int i = 0; i < vector.size(); i++) { 
52               AutoscaleListener autoscalelistener = (AutoscaleListener) vector.elementAt( 
53                       i); 
54               autoscalelistener.autoscaleOccured(autoscaleevent); 
55           } 
56    
57       } 
58    
59       public void changeOccured(BodeEvent bodeevent) { 
60           switch (bodeevent.getType()) { 
61               case 0: // '\0' 
62                   pole.addElement(new Pole((Pole) bodeevent.getRoot())); 
63                   break; 
64    
65               case 1: // '\001' 
66                   zero.addElement(new Zero((Zero) bodeevent.getRoot())); 
67                   break; 
68    
69               case 2: // '\002' 
70                   ((Pole) pole.elementAt(bodeevent.getPosition())).setPos( 
71                           bodeevent.getRoot().getReal(), 
72                           bodeevent.getRoot().getImag()); 
73                   break; 
74    
75               case 3: // '\003' 
76                   ((Zero) zero.elementAt(bodeevent.getPosition())).setPos( 
77                           bodeevent.getRoot().getReal(), 
78                           bodeevent.getRoot().getImag()); 
79                   break; 
80    
81               case 4: // '\004' 
82                   pole.removeElementAt(bodeevent.getPosition()); 
83                   break; 
84    
85               case 5: // '\005' 
86                   zero.removeElementAt(bodeevent.getPosition()); 
87                   break; 
88    
89               case 6: // '\006' 
90                   zero.removeAllElements(); 
91                   pole.removeAllElements(); 
92                   break; 
93    
94               case 7: // '\007' 
95                   Vector vector = bodeevent.getPoles(); 
96                   gain = bodeevent.getGain(); 
97                   synchronized (this) { 
98                       if (vector != null) { 
99                           pole.removeAllElements(); 
100                          for (int i2 = 0; i2 < vector.size(); i2++) 
101                              pole.addElement( 
102                                      new Pole((Pole) vector.elementAt(i2))); 
103   
104                      } 
105                  } 
106                  break; 
107   
108              case 8: // '\b' 
109                  Vector vector1 = bodeevent.getZeros(); 
110                  gain = bodeevent.getGain(); 
111                  synchronized (this) { 
112                      if (vector1 != null) { 
113                          zero.removeAllElements(); 
114                          for (int j2 = 0; j2 < vector1.size(); j2++) 
115                              zero.addElement( 
116                                      new Zero((Zero) vector1.elementAt(j2))); 
117   
118                      } 
119                  } 
120                  break; 
121   
122              case 9: // '\t' 
123                  Vector vector2 = bodeevent.getPoles(); 
124                  Vector vector9 = bodeevent.getZeros(); 
125                  gain = bodeevent.getGain(); 
126                  synchronized (this) { 
127                      if (vector2 != null) { 
128                          pole.removeAllElements(); 
129                          for (int k2 = 0; k2 < vector2.size(); k2++) 
130                              pole.addElement( 
131                                      new Pole((Pole) vector2.elementAt(k2))); 
132   
133                      } 
134                      if (vector9 != null) { 
135                          zero.removeAllElements(); 
136                          for (int l2 = 0; l2 < vector9.size(); l2++) 
137                              zero.addElement( 
138                                      new Zero((Zero) vector9.elementAt(l2))); 
139   
140                      } 
141                  } 
142                  break; 
143   
144              case 10: // '\n' 
145                  Vector vector3 = new Vector(); 
146                  Vector vector10 = bodeevent.getPoles(); 
147                  for (int i = 0; i < vector10.size(); i++) 
148                      vector3.insertElementAt( 
149                              new ComplexNumber( 
150                                      ((Double) vector10.elementAt(i)).doubleValue()), 
151                              0); 
152   
153                  gain = ((ComplexNumber) vector3.elementAt(0)).getReal(); 
154                  vector3 = findRoots(vecToArray(vector3)); 
155                  pole = purgeRoot(vector3, false); 
156                  fireBodeEvent(new BodeEvent(this, pole, gain, 7)); 
157                  break; 
158   
159              case 11: // '\013' 
160                  Vector vector4 = new Vector(); 
161                  Vector vector11 = bodeevent.getZeros(); 
162                  for (int j = 0; j < vector11.size(); j++) 
163                      vector4.insertElementAt( 
164                              new ComplexNumber( 
165                                      ((Double) vector11.elementAt(j)).doubleValue()), 
166                              0); 
167   
168                  gain = ((ComplexNumber) vector4.elementAt(0)).getReal(); 
169                  vector4 = findRoots(vecToArray(vector4)); 
170                  zero = purgeRoot(vector4, true); 
171                  fireBodeEvent(new BodeEvent(this, zero, gain, 8)); 
172                  break; 
173   
174              case 12: // '\f' 
175                  Vector vector5 = new Vector(); 
176                  Vector vector12 = bodeevent.getZeros(); 
177                  for (int k = 0; k < vector12.size(); k++) 
178                      vector5.insertElementAt( 
179                              new ComplexNumber( 
180                                      ((Double) vector12.elementAt(k)).doubleValue()), 
181                              0); 
182   
183                  gain = ((ComplexNumber) vector5.elementAt(0)).getReal(); 
184                  vector5 = findRoots(vecToArray(vector5)); 
185                  zero = purgeRoot(vector5, true); 
186                  vector5 = new Vector(); 
187                  vector12 = bodeevent.getPoles(); 
188                  for (int l = 0; l < vector12.size(); l++) 
189                      vector5.insertElementAt( 
190                              new ComplexNumber( 
191                                      ((Double) vector12.elementAt(l)).doubleValue()), 
192                              0); 
193   
194                  gain /= ((ComplexNumber) vector5.elementAt(0)).getReal(); 
195                  vector5 = findRoots(vecToArray(vector5)); 
196                  pole = purgeRoot(vector5, false); 
197                  fireBodeEvent(new BodeEvent(this, pole, zero, gain, 9)); 
198                  break; 
199   
200              case 13: // '\r' 
201                  Vector vector6 = new Vector(); 
202                  for (int i1 = 0; i1 < bodeevent.poles.length; i1++) 
203                      vector6.insertElementAt( 
204                              new ComplexNumber(bodeevent.poles[i1]), 0); 
205   
206                  gain = bodeevent.poles[0]; 
207                  vector6 = findRoots(vecToArray(vector6)); 
208                  pole = purgeRoot(vector6, false); 
209                  fireBodeEvent(new BodeEvent(this, pole, gain, 7)); 
210                  break; 
211   
212              case 14: // '\016' 
213                  Vector vector7 = new Vector(); 
214                  for (int j1 = 0; j1 < bodeevent.zeros.length; j1++) 
215                      vector7.insertElementAt( 
216                              new ComplexNumber(bodeevent.zeros[j1]), 0); 
217   
218                  gain = bodeevent.zeros[0]; 
219                  vector7 = findRoots(vecToArray(vector7)); 
220                  zero = purgeRoot(vector7, true); 
221                  fireBodeEvent(new BodeEvent(this, zero, gain, 8)); 
222                  break; 
223   
224              case 15: // '\017' 
225                  Vector vector8 = new Vector(); 
226                  for (int k1 = 0; k1 < bodeevent.zeros.length; k1++) 
227                      vector8.insertElementAt( 
228                              new ComplexNumber(bodeevent.zeros[k1]), 0); 
229   
230                  gain = bodeevent.zeros[0]; 
231                  if (vector8.size() > 1) { 
232                      vector8 = findRoots(vecToArray(vector8)); 
233                      zero = purgeRoot(vector8, true); 
234                  } 
235                  vector8 = new Vector(); 
236                  for (int l1 = 0; l1 < bodeevent.poles.length; l1++) 
237                      vector8.insertElementAt( 
238                              new ComplexNumber(bodeevent.poles[l1]), 0); 
239   
240                  gain /= bodeevent.poles[0]; 
241                  if (vector8.size() > 1) { 
242                      vector8 = findRoots(vecToArray(vector8)); 
243                      pole = purgeRoot(vector8, false); 
244                  } 
245                  fireBodeEvent(new BodeEvent(this, pole, zero, gain, 9)); 
246                  break; 
247          } 
248          if (bodeevent.getType() < 10) 
249              fireBodeEvent(bodeevent); 
250          if (bodeevent.getType() != 9 && bodeevent.getType() != 15) 
251              fireBodeEvent(new BodeEvent(this, pole, zero, gain, 16)); 
252      } 
253   
254      public void autoscaleOccured(AutoscaleEvent autoscaleevent) { 
255          fireAutoscaleEvent(autoscaleevent); 
256      } 
257   
258      public static Vector purgeRoot(Vector vector, boolean flag) { 
259          Vector vector1 = new Vector(); 
260          for (int i = 0; i < vector.size(); i++) { 
261              ComplexNumber complexnumber = (ComplexNumber) vector.elementAt( 
262                      i); 
263              if (flag) 
264                  vector1.addElement( 
265                          new Zero(complexnumber.getReal() / 100000D, 
266                                  complexnumber.getImag() / 100000D)); 
267              else 
268                  vector1.addElement( 
269                          new Pole(complexnumber.getReal() / 100000D, 
270                                  complexnumber.getImag() / 100000D)); 
271              for (int j = i + 1; j < vector.size(); j++) { 
272                  ComplexNumber complexnumber1 = (ComplexNumber) vector.elementAt( 
273                          j); 
274                  if (complexnumber.getReal() == complexnumber1.getReal() && 
275                          complexnumber.getImag() == 
276                          -complexnumber1.getImag() && 
277                          complexnumber.getImag() != 0.0D) 
278                      vector.removeElementAt(j); 
279              } 
280   
281          } 
282   
283          return vector1; 
284      } 
285   
286      public static Vector findRoots(ComplexNumber acomplexnumber[]) { 
287          Vector vector = new Vector(); 
288          int i = acomplexnumber.length - 1; 
289          ComplexNumber acomplexnumber2[] = new ComplexNumber[acomplexnumber.length]; 
290          ComplexNumber acomplexnumber1[] = new ComplexNumber[i + 1]; 
291          ComplexNumber complexnumber = new ComplexNumber(); 
292          for (int k = 0; k <= i; k++) 
293              acomplexnumber2[k] = acomplexnumber[k]; 
294   
295          if (i <= 1) { 
296              vector.addElement( 
297                      acomplexnumber[0].div(acomplexnumber[1]).scale( 
298                              -100000D)); 
299              return vector; 
300          } 
301          for (int l = i; l >= 1; l--) { 
302              ComplexNumber complexnumber1 = new ComplexNumber( 
303                      -100D * Math.random(), -100D * Math.random()); 
304              complexnumber1 = 
305                      findARoot(acomplexnumber2, l, complexnumber1); 
306              if (Math.abs(complexnumber1.getImag()) <= 
307                      3.9999999999999998E-06D * 
308                      Math.abs(complexnumber1.getReal())) 
309                  complexnumber1.setImag(0.0D); 
310              acomplexnumber1[l] = complexnumber1; 
311              ComplexNumber complexnumber3 = new ComplexNumber( 
312                      acomplexnumber2[l]); 
313              for (int l1 = l - 1; l1 >= 0; l1--) { 
314                  ComplexNumber complexnumber4 = new ComplexNumber( 
315                          acomplexnumber2[l1]); 
316                  acomplexnumber2[l1] = complexnumber3; 
317                  complexnumber3 = 
318                          complexnumber4.add( 
319                                  complexnumber1.mul(complexnumber3)); 
320              } 
321   
322          } 
323   
324          for (int i1 = 1; i1 <= i; i1++) { 
325              ComplexNumber complexnumber5 = new ComplexNumber( 
326                      acomplexnumber1[i1]); 
327              acomplexnumber1[i1] = 
328                      findARoot(acomplexnumber, i, complexnumber5); 
329          } 
330   
331          for (int j1 = 2; j1 <= i; j1++) { 
332              int i2 = 0; 
333              ComplexNumber complexnumber2 = new ComplexNumber( 
334                      acomplexnumber1[j1]); 
335              for (int j = j1 - 1; j >= 1; j--) { 
336                  ComplexNumber complexnumber6 = new ComplexNumber( 
337                          acomplexnumber1[j]); 
338                  i2 = j; 
339                  if (complexnumber6.getReal() <= complexnumber2.getReal()) 
340                      break; 
341                  acomplexnumber1[j + 1] = acomplexnumber1[j]; 
342              } 
343   
344              acomplexnumber1[i2 + 1] = complexnumber2; 
345          } 
346   
347          for (int k1 = 1; k1 < acomplexnumber1.length; k1++) { 
348              double d = Math.round(acomplexnumber1[k1].real * 100000D); 
349              double d1 = Math.round(acomplexnumber1[k1].imag * 100000D); 
350              ComplexNumber complexnumber7 = new ComplexNumber(d, d1); 
351              acomplexnumber1[k1 - 1] = complexnumber7; 
352          } 
353   
354          for (int j2 = 0; j2 < acomplexnumber1.length - 1; j2++) 
355              vector.addElement(acomplexnumber1[j2]); 
356   
357          return vector; 
358      } 
359   
360      public static ComplexNumber findARoot(ComplexNumber acomplexnumber[], 
361                                            int i, 
362                                            ComplexNumber complexnumber) { 
363          double ad[] = { 
364              0, 0.5D, 0.25D, 0.75D, 0.13D, 0.38D, 0.62D, 0.88D, 1.0D 
365          }; 
366          ComplexNumber complexnumber1 = new ComplexNumber(); 
367          ComplexNumber complexnumber3 = new ComplexNumber(); 
368          ComplexNumber complexnumber8 = new ComplexNumber(); 
369          ComplexNumber complexnumber10 = new ComplexNumber(); 
370          ComplexNumber complexnumber12 = new ComplexNumber(); 
371          ComplexNumber complexnumber14 = new ComplexNumber(); 
372          ComplexNumber complexnumber16 = new ComplexNumber(); 
373          ComplexNumber complexnumber18 = new ComplexNumber(); 
374          for (int j = 1; j <= 80; j++) { 
375              ComplexNumber complexnumber5 = new ComplexNumber( 
376                      acomplexnumber[i]); 
377              double d3 = complexnumber5.abs(); 
378              ComplexNumber complexnumber6 = new ComplexNumber(); 
379              ComplexNumber complexnumber7 = new ComplexNumber(); 
380              double d = complexnumber.abs(); 
381              for (int k = i - 1; k >= 0; k--) { 
382                  complexnumber7 = 
383                          complexnumber6.add( 
384                                  complexnumber7.mul(complexnumber)); 
385                  complexnumber6 = 
386                          complexnumber5.add( 
387                                  complexnumber6.mul(complexnumber)); 
388                  complexnumber5 = 
389                          acomplexnumber[k].add( 
390                                  complexnumber5.mul(complexnumber)); 
391                  d3 = complexnumber5.abs() + d * d3; 
392              } 
393   
394              d3 *= 9.9999999999999995E-08D; 
395              if (complexnumber5.abs() <= d3) 
396                  return complexnumber; 
397              ComplexNumber complexnumber9 = complexnumber6.div( 
398                      complexnumber5); 
399              ComplexNumber complexnumber19 = complexnumber9.mul( 
400                      complexnumber9); 
401              ComplexNumber complexnumber11 = complexnumber19.sub( 
402                      complexnumber7.div(complexnumber5).scale(2D)); 
403              ComplexNumber complexnumber13 = complexnumber11.scale(i) 
404                      .sub(complexnumber19) 
405                      .scale(i - 1) 
406                      .sqrt(); 
407              ComplexNumber complexnumber15 = complexnumber9.add( 
408                      complexnumber13); 
409              ComplexNumber complexnumber17 = complexnumber9.sub( 
410                      complexnumber13); 
411              double d1 = complexnumber15.abs(); 
412              double d2 = complexnumber17.abs(); 
413              if (d1 < d2) 
414                  complexnumber15 = complexnumber17; 
415              ComplexNumber complexnumber2; 
416              if (Math.max(d1, d2) > 0.0D) { 
417                  complexnumber2 = 
418                          (new ComplexNumber(i, 0.0D)).div(complexnumber15); 
419              } else { 
420                  ComplexNumber complexnumber20 = new ComplexNumber( 
421                          Math.cos(j), Math.sin(j)); 
422                  complexnumber2 = 
423                          complexnumber20.scale( 
424                                  Math.exp(Math.log(1.0D + d))); 
425              } 
426              ComplexNumber complexnumber4 = complexnumber.sub( 
427                      complexnumber2); 
428              if (complexnumber.equals(complexnumber4)) 
429                  return complexnumber; 
430              if (j % 10 != 0) 
431                  complexnumber = complexnumber4; 
432              else 
433                  complexnumber = 
434                          complexnumber.sub( 
435                                  complexnumber2.scale(ad[j / 10])); 
436          } 
437   
438          return complexnumber; 
439      } 
440   
441      public static ComplexNumber[] vecToArray(Vector vector) { 
442          ComplexNumber acomplexnumber[] = new ComplexNumber[vector.size()]; 
443          int i = 0; 
444          for (Enumeration enumeration = vector.elements(); 
445               enumeration.hasMoreElements();) 
446              acomplexnumber[i++] = 
447                      new ComplexNumber( 
448                              (ComplexNumber) enumeration.nextElement()); 
449   
450          return acomplexnumber; 
451      } 
452   
453      public static Vector parseParams(String s) 
454              throws NumberFormatException { 
455          Vector vector = new Vector(); 
456          for (StringTokenizer stringtokenizer = new StringTokenizer(s); 
457               stringtokenizer.hasMoreElements(); 
458               vector.insertElementAt( 
459                       new ComplexNumber( 
460                               (new Double(stringtokenizer.nextToken())).doubleValue()), 
461                       0)) ; 
462          return vector; 
463      } 
464   
465      public static void rootsToPoly(boolean flag) { 
466          Vector vector = new Vector(); 
467          Vector vector1 = flag ? zero : pole; 
468          if (flag) { 
469              for (int i = 0; i < vector1.size(); i++) { 
470                  Zero zero1 = new Zero((Zero) vector1.elementAt(i)); 
471                  vector.addElement(new ComplexNumber(zero1)); 
472                  if (zero1.getImag() != 0.0D) 
473                      vector.addElement(new ComplexNumber(zero1.conj())); 
474              } 
475   
476              Object obj = null; 
477          } else { 
478              for (int j = 0; j < vector1.size(); j++) { 
479                  Pole pole1 = new Pole((Pole) vector1.elementAt(j)); 
480                  vector.addElement(new ComplexNumber(pole1)); 
481                  if (pole1.getImag() != 0.0D) 
482                      vector.addElement(new ComplexNumber(pole1.conj())); 
483              } 
484   
485              Object obj1 = null; 
486          } 
487          vector1 = null; 
488          ComplexNumber acomplexnumber[] = new ComplexNumber[vector.size() + 
489                  1]; 
490          for (int k = 0; k < acomplexnumber.length; k++) 
491              acomplexnumber[k] = new ComplexNumber(); 
492   
493          acomplexnumber[0] = new ComplexNumber(1.0D); 
494          acomplexnumber[1] = 
495                  new ComplexNumber((ComplexNumber) vector.elementAt(0)); 
496          for (int l = 1; l < vector.size(); l++) { 
497              ComplexNumber complexnumber = new ComplexNumber( 
498                      (ComplexNumber) vector.elementAt(l)); 
499              for (int i1 = l + 1; i1 > 0; i1--) 
500                  acomplexnumber[i1] = 
501                          acomplexnumber[i1 - 1].mul(complexnumber).add( 
502                                  acomplexnumber[i1]); 
503   
504          } 
505   
506          if (flag) { 
507              zeroPoly = new double[acomplexnumber.length]; 
508              for (int j1 = 0; j1 < acomplexnumber.length; j1++) 
509                  zeroPoly[j1] = acomplexnumber[j1].getReal(); 
510   
511              return; 
512          } 
513          polePoly = new double[acomplexnumber.length]; 
514          for (int k1 = 0; k1 < acomplexnumber.length; k1++) 
515              polePoly[k1] = acomplexnumber[k1].getReal(); 
516   
517      } 
518   
519      public static void main(String args[]) { 
520      } 
521   
522      public ControlBean() { 
523          bodeListeners = new Vector(); 
524          autoscaleListeners = new Vector(); 
525      } 
526   
527      private static Vector pole = new Vector(); 
528      private static Vector zero = new Vector(); 
529      private static double polePoly[]; 
530      private static double zeroPoly[]; 
531      private Vector bodeListeners; 
532      private Vector autoscaleListeners; 
533      boolean done; 
534      double gain; 
535   
536  } 
537