Package com.sun.j3d.audioengines.javasound

Source Code of com.sun.j3d.audioengines.javasound.JSPositionalSample

/*      */ package com.sun.j3d.audioengines.javasound;
/*      */
/*      */ import com.sun.j3d.audioengines.AuralParameters;
/*      */ import javax.media.j3d.PhysicalBody;
/*      */ import javax.media.j3d.Transform3D;
/*      */ import javax.media.j3d.View;
/*      */ import javax.vecmath.Point3d;
/*      */ import javax.vecmath.Point3f;
/*      */ import javax.vecmath.Vector3f;
/*      */
/*      */ class JSPositionalSample extends JSSample
/*      */ {
/*   32 */   float leftGain = 1.0F;
/*   33 */   float rightGain = 1.0F;
/*   34 */   int leftDelay = 0;
/*   35 */   int rightDelay = 0;
/*      */   protected static final boolean dopplerFlag = true;
/*   47 */   int secondIndex = -1;
/*      */
/*   58 */   int reverbIndex = -1;
/*      */
/*   64 */   Point3f xformLeftEar = new Point3f(-0.09F, -0.03F, 0.095F);
/*   65 */   Point3f xformRightEar = new Point3f(0.09F, -0.03F, 0.095F);
/*      */
/*   67 */   Vector3f xformHeadZAxis = new Vector3f(0.0F, 0.0F, -1.0F);
/*      */
/*   72 */   Vector3f sourceToCenterEar = new Vector3f();
/*   73 */   Vector3f sourceToRightEar = new Vector3f();
/*   74 */   Vector3f sourceToLeftEar = new Vector3f();
/*      */
/*   76 */   boolean averageDistances = false;
/*   77 */   long deltaTime = 0L;
/*   78 */   double sourcePositionChange = -1.0D;
/*   79 */   double headPositionChange = -1.0D;
/*      */
/*   86 */   static int MAX_DISTANCES = 4;
/*   87 */   int numDistances = 0;
/*      */
/*   92 */   long[] times = new long[MAX_DISTANCES];
/*   93 */   Point3f[] positions = new Point3f[MAX_DISTANCES];
/*   94 */   Point3f[] centerEars = new Point3f[MAX_DISTANCES];
/*      */
/*   99 */   int firstIndex = 0;
/*  100 */   int lastIndex = 0;
/*  101 */   int currentIndex = 0;
/*      */
/*  111 */   double lastRequestedDopplerRateRatio = -1.0D;
/*  112 */   double lastActualDopplerRateRatio = -1.0D;
/*  113 */   static double maxRatio = 256.0D;
/*      */
/*  117 */   static int TOWARDS = 1;
/*  118 */   static int NO_CHANGE = 0;
/*  119 */   static int AWAY = -1;
/*      */
/*  124 */   boolean filterFlag = false;
/*  125 */   float filterFreq = -1.0F;
/*      */
/*      */   public JSPositionalSample()
/*      */   {
/*  135 */     for (int i = 0; i < MAX_DISTANCES; i++) {
/*  136 */       this.positions[i] = new Point3f();
/*  137 */       this.centerEars[i] = new Point3f(0.09F, -0.03F, 0.095F);
/*      */     }
/*  139 */     clear();
/*      */   }
/*      */
/*      */   boolean getFilterFlag()
/*      */   {
/*  148 */     return this.filterFlag;
/*      */   }
/*      */   float getFilterFreq() {
/*  151 */     return this.filterFreq;
/*      */   }
/*      */
/*      */   public void clear()
/*      */   {
/*  162 */     super.clear();
/*  163 */     this.leftGain = 1.0F;
/*  164 */     this.rightGain = 1.0F;
/*  165 */     this.leftDelay = 0;
/*  166 */     this.rightDelay = 0;
/*  167 */     this.xformLeftEar.set(-0.09F, -0.03F, 0.095F);
/*  168 */     this.xformRightEar.set(0.09F, -0.03F, 0.095F);
/*      */
/*  170 */     this.xformHeadZAxis.set(0.0F, 0.0F, -1.0F);
/*  171 */     this.sourceToCenterEar.set(0.0F, 0.0F, 0.0F);
/*  172 */     this.sourceToRightEar.set(0.0F, 0.0F, 0.0F);
/*  173 */     this.sourceToLeftEar.set(0.0F, 0.0F, 0.0F);
/*  174 */     reset();
/*      */   }
/*      */
/*      */   void reset()
/*      */   {
/*  186 */     super.reset();
/*  187 */     this.averageDistances = false;
/*  188 */     this.deltaTime = 0L;
/*  189 */     this.sourcePositionChange = -1.0D;
/*  190 */     this.headPositionChange = -1.0D;
/*  191 */     this.rateRatio = 1.0F;
/*  192 */     this.numDistances = 0;
/*  193 */     this.averageDistances = false;
/*      */   }
/*      */
/*      */   void incrementIndices()
/*      */   {
/*  200 */     int maxIndex = MAX_DISTANCES - 1;
/*  201 */     if (this.numDistances < maxIndex) {
/*  202 */       this.averageDistances = false;
/*  203 */       this.currentIndex = this.numDistances;
/*  204 */       this.lastIndex = (this.currentIndex - 1);
/*  205 */       this.firstIndex = 0;
/*  206 */       this.numDistances += 1;
/*      */     }
/*  208 */     else if (this.numDistances == maxIndex)
/*      */     {
/*  211 */       this.averageDistances = true;
/*  212 */       this.currentIndex = maxIndex;
/*  213 */       this.lastIndex = (this.currentIndex - 1);
/*  214 */       this.firstIndex = 0;
/*  215 */       this.numDistances += 1;
/*      */     }
/*  217 */     else if (this.numDistances > maxIndex)
/*      */     {
/*  219 */       this.averageDistances = true;
/*  220 */       this.currentIndex += 1;
/*  221 */       this.lastIndex += 1;
/*  222 */       this.firstIndex += 1;
/*  223 */       this.currentIndex %= MAX_DISTANCES;
/*  224 */       this.lastIndex %= MAX_DISTANCES;
/*  225 */       this.firstIndex %= MAX_DISTANCES;
/*      */     }
/*      */   }
/*      */
/*      */   void setXformedPosition()
/*      */   {
/*  237 */     Point3f newPosition = new Point3f();
/*      */
/*  241 */     if (getVWrldXfrmFlag())
/*      */     {
/*  244 */       this.vworldXfrm.transform(this.position, newPosition);
/*      */     }
/*      */     else
/*      */     {
/*  249 */       newPosition.set(this.position);
/*      */     }
/*      */
/*  252 */     if ((newPosition.x == this.positions[this.currentIndex].x) && (newPosition.y == this.positions[this.currentIndex].y) && (newPosition.z == this.positions[this.currentIndex].z))
/*      */     {
/*  257 */       return;
/*      */     }
/*      */
/*  260 */     incrementIndices();
/*      */
/*  262 */     this.times[this.currentIndex] = System.currentTimeMillis();
/*  263 */     this.positions[this.currentIndex].set(newPosition);
/*      */
/*  273 */     if (this.numDistances > 1)
/*  274 */       this.centerEars[this.currentIndex].set(this.centerEars[this.lastIndex]);
/*      */   }
/*      */
/*      */   float calculateDoppler(AuralParameters attribs)
/*      */   {
/*  330 */     double sampleRateRatio = 1.0D;
/*  331 */     double headVelocity = 0.0D;
/*  332 */     double soundVelocity = 0.0D;
/*  333 */     double distanceSourceToHead = 0.0D;
/*  334 */     double lastDistanceSourceToHead = 0.0D;
/*  335 */     float speedOfSound = 0.344F;
/*  336 */     double numerator = 1.0D;
/*  337 */     double denominator = 1.0D;
/*  338 */     int direction = NO_CHANGE;
/*      */
/*  344 */     float averagedSoundDistances = 0.0F;
/*  345 */     float averagedEarsDistances = 0.0F;
/*      */
/*  351 */     if (!this.averageDistances)
/*      */     {
/*  354 */       debugPrint("JSPositionalSample.calculateDoppler - not enough distance data collected, dopplerRatio set to zero");
/*      */
/*  358 */       return 0.0F;
/*      */     }
/*      */
/*  361 */     Point3f lastXformPosition = this.positions[this.lastIndex];
/*  362 */     Point3f lastXformCenterEar = this.centerEars[this.lastIndex];
/*  363 */     Point3f xformPosition = this.positions[this.currentIndex];
/*  364 */     Point3f xformCenterEar = this.centerEars[this.currentIndex];
/*  365 */     distanceSourceToHead = xformPosition.distance(xformCenterEar);
/*  366 */     lastDistanceSourceToHead = lastXformPosition.distance(lastXformCenterEar);
/*      */
/*  368 */     debugPrint("JSPositionalSample.calculateDoppler - distances: current,last = " + distanceSourceToHead + ", " + lastDistanceSourceToHead);
/*      */
/*  371 */     debugPrint("                                      current position = " + xformPosition.x + ", " + xformPosition.y + ", " + xformPosition.z);
/*      */
/*  375 */     debugPrint("                                      current ear = " + xformCenterEar.x + ", " + xformCenterEar.y + ", " + xformCenterEar.z);
/*      */
/*  379 */     debugPrint("                                      last position = " + lastXformPosition.x + ", " + lastXformPosition.y + ", " + lastXformPosition.z);
/*      */
/*  383 */     debugPrint("                                      last ear = " + lastXformCenterEar.x + ", " + lastXformCenterEar.y + ", " + lastXformCenterEar.z);
/*      */
/*  388 */     if (distanceSourceToHead == lastDistanceSourceToHead)
/*      */     {
/*  391 */       debugPrint("JSPositionalSample.calculateDoppler - distance diff = 0, dopplerRatio set to zero");
/*      */
/*  394 */       return 0.0F;
/*      */     }
/*      */
/*  397 */     this.deltaTime = (this.times[this.currentIndex] - this.times[this.firstIndex]);
/*  398 */     for (int i = 0; i < MAX_DISTANCES - 1; i++) {
/*  399 */       averagedSoundDistances += this.positions[(i + 1)].distance(this.positions[i]);
/*  400 */       averagedEarsDistances += this.centerEars[(i + 1)].distance(this.centerEars[i]);
/*      */     }
/*  402 */     averagedSoundDistances /= (MAX_DISTANCES - 1);
/*  403 */     averagedEarsDistances /= (MAX_DISTANCES - 1);
/*  404 */     soundVelocity = averagedSoundDistances / (float)this.deltaTime;
/*  405 */     headVelocity = averagedEarsDistances / (float)this.deltaTime;
/*      */
/*  407 */     debugPrint("                                      delta time = " + this.deltaTime);
/*      */
/*  409 */     debugPrint("                                      soundPosition delta = " + xformPosition.distance(lastXformPosition));
/*      */
/*  412 */     debugPrint("                                      soundVelocity = " + soundVelocity);
/*      */
/*  414 */     debugPrint("                                      headPosition delta = " + xformCenterEar.distance(lastXformCenterEar));
/*      */
/*  417 */     debugPrint("                                      headVelocity = " + headVelocity);
/*      */
/*  420 */     if (attribs != null)
/*      */     {
/*  422 */       float rolloff = attribs.rolloff;
/*  423 */       float velocityScaleFactor = attribs.velocityScaleFactor;
/*  424 */       if (rolloff != 1.0F) {
/*  425 */         speedOfSound *= rolloff;
/*      */
/*  427 */         debugPrint("                                      attrib rollof = " + rolloff);
/*      */       }
/*      */
/*  430 */       if (velocityScaleFactor != 1.0F) {
/*  431 */         soundVelocity *= velocityScaleFactor;
/*  432 */         headVelocity *= velocityScaleFactor;
/*      */
/*  434 */         debugPrint("                                      attrib velocity scale factor = " + velocityScaleFactor);
/*      */
/*  437 */         debugPrint("                                      new soundVelocity = " + soundVelocity);
/*      */
/*  439 */         debugPrint("                                      new headVelocity = " + headVelocity);
/*      */       }
/*      */
/*      */     }
/*      */
/*  444 */     if (distanceSourceToHead < lastDistanceSourceToHead)
/*      */     {
/*  447 */       debugPrint("                                      moving towards...");
/*      */
/*  449 */       direction = TOWARDS;
/*  450 */       numerator = speedOfSound + headVelocity;
/*  451 */       denominator = speedOfSound - soundVelocity;
/*      */     }
/*      */     else
/*      */     {
/*  457 */       debugPrint("                                      moving away...");
/*      */
/*  459 */       direction = AWAY;
/*  460 */       numerator = speedOfSound - headVelocity;
/*  461 */       denominator = speedOfSound + soundVelocity;
/*      */     }
/*  463 */     if (numerator <= 0.0D)
/*      */     {
/*  465 */       debugPrint("JSPositionalSample.calculateDoppler: BOOM!! - velocity of head > speed of sound");
/*      */
/*  467 */       return -1.0F;
/*      */     }
/*  469 */     if (denominator <= 0.0D)
/*      */     {
/*  471 */       debugPrint("JSPositionalSample.calculateDoppler: BOOM!! - velocity of sound source negative");
/*      */
/*  473 */       return -1.0F;
/*      */     }
/*      */
/*  477 */     debugPrint("JSPositionalSample.calculateDoppler: numerator = " + numerator + ", denominator = " + denominator);
/*      */
/*  480 */     sampleRateRatio = numerator / denominator;
/*      */
/*  494 */     return (float)sampleRateRatio;
/*      */   }
/*      */
/*      */   void updateEar(int dirtyFlags, View view)
/*      */   {
/*  501 */     Point3f xformCenterEar = new Point3f();
/*  502 */     if (!calculateNewEar(dirtyFlags, view, xformCenterEar))
/*      */     {
/*  505 */       return;
/*      */     }
/*      */
/*  508 */     if ((xformCenterEar.x == this.centerEars[this.currentIndex].x) && (xformCenterEar.y == this.centerEars[this.currentIndex].y) && (xformCenterEar.z == this.centerEars[this.currentIndex].z))
/*      */     {
/*  513 */       return;
/*      */     }
/*      */
/*  516 */     incrementIndices();
/*  517 */     this.times[this.currentIndex] = System.currentTimeMillis();
/*  518 */     this.centerEars[this.currentIndex].set(xformCenterEar);
/*      */
/*  521 */     if (this.numDistances > 1)
/*  522 */       this.positions[this.currentIndex].set(this.positions[this.lastIndex]);
/*      */   }
/*      */
/*      */   boolean calculateNewEar(int dirtyFlags, View view, Point3f xformCenterEar)
/*      */   {
/*  529 */     Point3d earPosition = new Point3d();
/*      */
/*  533 */     boolean earsXformed = false;
/*  534 */     if ((!earsXformed) &&
/*  535 */       (view != null)) {
/*  536 */       PhysicalBody body = view.getPhysicalBody();
/*  537 */       if (body != null)
/*      */       {
/*  542 */         Transform3D headToVwrld = new Transform3D();
/*  543 */         view.getUserHeadToVworld(headToVwrld);
/*      */
/*  560 */         body.getLeftEarPosition(earPosition);
/*  561 */         this.xformLeftEar.x = ((float)earPosition.x);
/*  562 */         this.xformLeftEar.y = ((float)earPosition.y);
/*  563 */         this.xformLeftEar.z = ((float)earPosition.z);
/*  564 */         body.getRightEarPosition(earPosition);
/*  565 */         this.xformRightEar.x = ((float)earPosition.x);
/*  566 */         this.xformRightEar.y = ((float)earPosition.y);
/*  567 */         this.xformRightEar.z = ((float)earPosition.z);
/*  568 */         headToVwrld.transform(this.xformRightEar);
/*  569 */         headToVwrld.transform(this.xformLeftEar);
/*      */
/*  571 */         this.xformHeadZAxis.set(0.0F, 0.0F, -1.0F);
/*  572 */         headToVwrld.transform(this.xformHeadZAxis);
/*      */
/*  576 */         xformCenterEar.x = (this.xformLeftEar.x + (this.xformRightEar.x - this.xformLeftEar.x) * 0.5F);
/*      */
/*  578 */         xformCenterEar.y = (this.xformLeftEar.y + (this.xformRightEar.y - this.xformLeftEar.y) * 0.5F);
/*      */
/*  580 */         xformCenterEar.z = (this.xformLeftEar.z + (this.xformRightEar.z - this.xformLeftEar.z) * 0.5F);
/*      */
/*  591 */         earsXformed = true;
/*      */       }
/*      */
/*      */     }
/*      */
/*  599 */     if (!earsXformed);
/*  604 */     return earsXformed;
/*      */   }
/*      */
/*      */   public void render(int dirtyFlags, View view, AuralParameters attribs)
/*      */   {
/*  616 */     updateEar(dirtyFlags, view);
/*      */
/*  632 */     float dopplerRatio = 1.0F;
/*  633 */     if (attribs != null) {
/*  634 */       float rolloff = attribs.rolloff;
/*  635 */       float frequencyScaleFactor = attribs.frequencyScaleFactor;
/*  636 */       float velocityScaleFactor = attribs.velocityScaleFactor;
/*      */
/*  638 */       debugPrint("JSPositionalSample: attribs NOT null");
/*  639 */       if (rolloff > 0.0F)
/*      */       {
/*  645 */         if (frequencyScaleFactor > 0.0F)
/*      */         {
/*  652 */           if (velocityScaleFactor > 0.0F)
/*      */           {
/*  654 */             debugPrint("    velocityScaleFactor = " + velocityScaleFactor);
/*      */
/*  661 */             dopplerRatio = calculateDoppler(attribs);
/*      */
/*  663 */             if (dopplerRatio != 0.0F)
/*      */             {
/*  671 */               if (dopplerRatio != -1.0F)
/*      */               {
/*  681 */                 if (dopplerRatio > 0.0F)
/*      */                 {
/*  683 */                   this.rateRatio = (dopplerRatio * frequencyScaleFactor * getRateScaleFactor());
/*      */                 }
/*      */
/*      */               }
/*      */
/*      */             }
/*      */
/*      */           }
/*      */           else
/*      */           {
/*  700 */             this.rateRatio = (frequencyScaleFactor * getRateScaleFactor());
/*      */           }
/*      */         }
/*      */
/*      */       }
/*      */
/*      */     }
/*      */     else
/*      */     {
/*  709 */       debugPrint("JSPositionalSample: attribs null");
/*  710 */       this.rateRatio = 1.0F;
/*      */     }
/*      */
/*  713 */     panSample(attribs);
/*      */   }
/*      */
/*      */   float calculateAngularGain()
/*      */   {
/*  729 */     return 1.0F;
/*      */   }
/*      */
/*      */   void calculateFilter(float distance, AuralParameters attribs)
/*      */   {
/*  751 */     float distanceFilter = 44100.0F;
/*  752 */     float angularFilter = 44100.0F;
/*  753 */     int arrayLength = attribs.getDistanceFilterLength();
/*  754 */     int filterType = attribs.getDistanceFilterType();
/*  755 */     boolean distanceFilterFound = false;
/*  756 */     boolean angularFilterFound = false;
/*  757 */     if ((filterType != -1) && (arrayLength > 0)) {
/*  758 */       double[] distanceArray = new double[arrayLength];
/*  759 */       float[] cutoffArray = new float[arrayLength];
/*  760 */       attribs.getDistanceFilter(distanceArray, cutoffArray);
/*      */
/*  767 */       distanceFilter = findFactor(distance, distanceArray, cutoffArray);
/*      */
/*  769 */       if (distanceFilter < 0.0F)
/*  770 */         distanceFilterFound = false;
/*      */       else
/*  772 */         distanceFilterFound = true;
/*      */     }
/*      */     else {
/*  775 */       distanceFilterFound = false;
/*  776 */       distanceFilter = -1.0F;
/*      */     }
/*      */
/*  783 */     angularFilterFound = false;
/*  784 */     angularFilter = -1.0F;
/*      */
/*  786 */     this.filterFlag = ((distanceFilterFound) || (angularFilterFound));
/*  787 */     this.filterFreq = distanceFilter;
/*      */   }
/*      */
/*      */   float findFactor(double distance, double[] distanceArray, float[] factorArray)
/*      */   {
/*  823 */     if ((distanceArray == null) || (factorArray == null))
/*      */     {
/*  826 */       return -1.0F;
/*      */     }
/*  828 */     int arrayLength = distanceArray.length;
/*  829 */     if (arrayLength < 2)
/*      */     {
/*  832 */       return -1.0F;
/*      */     }
/*  834 */     int largestIndex = arrayLength - 1;
/*      */
/*  839 */     if (distance >= distanceArray[largestIndex])
/*      */     {
/*  845 */       return factorArray[largestIndex];
/*      */     }
/*  847 */     if (distance <= distanceArray[0])
/*      */     {
/*  851 */       return factorArray[0];
/*      */     }
/*      */
/*  858 */     int lowIndex = 0;
/*  859 */     int highIndex = largestIndex;
/*      */
/*  862 */     while (lowIndex < highIndex - 1)
/*      */     {
/*  876 */       if (distanceArray[lowIndex] >= distance) {
/*  877 */         if (distance < distanceArray[lowIndex]);
/*  889 */         return factorArray[lowIndex];
/*      */       }
/*  891 */       if (distanceArray[highIndex] <= distance) {
/*  892 */         if (distance > distanceArray[highIndex]);
/*  904 */         return factorArray[highIndex];
/*      */       }
/*  906 */       if ((distance > distanceArray[lowIndex]) && (distance < distanceArray[highIndex]))
/*      */       {
/*  908 */         int indexMid = lowIndex + (highIndex - lowIndex) / 2;
/*  909 */         if (distance <= distanceArray[indexMid])
/*      */         {
/*  911 */           highIndex = indexMid;
/*      */         }
/*  913 */         else lowIndex = indexMid;
/*      */
/*      */       }
/*      */
/*      */     }
/*      */
/*  932 */     float outputFactor = (float)((distance - distanceArray[lowIndex]) / (distanceArray[highIndex] - distanceArray[lowIndex])) * (factorArray[highIndex] - factorArray[lowIndex]) + factorArray[lowIndex];
/*      */
/*  939 */     return outputFactor;
/*      */   }
/*      */
/*      */   float calculateDistanceAttenuation(float distance)
/*      */   {
/*  950 */     float factor = 1.0F;
/*  951 */     factor = findFactor(distance, this.attenuationDistance, this.attenuationGain);
/*      */
/*  953 */     if (factor >= 0.0D) {
/*  954 */       return factor;
/*      */     }
/*  956 */     return 1.0F;
/*      */   }
/*      */
/*      */   void panSample(AuralParameters attribs)
/*      */   {
/*  969 */     int quadrant = 1;
/*  970 */     float intensityHigh = 1.0F;
/*  971 */     float intensityLow = 0.125F;
/*  972 */     float intensityDifference = intensityHigh - intensityLow;
/*      */
/*  983 */     float nearZero = 1.0E-006F;
/*  984 */     float nearOne = 0.999999F;
/*  985 */     float nearNegativeOne = -nearOne;
/*  986 */     float halfPi = 1.570796F;
/*      */
/*  991 */     float distanceSourceToCenterEar = 0.0F;
/*  992 */     float lastDistanceSourceToCenterEar = 0.0F;
/*  993 */     float distanceSourceToRightEar = 0.0F;
/*  994 */     float distanceSourceToLeftEar = 0.0F;
/*  995 */     float distanceBetweenEars = 0.18F;
/*  996 */     float radiusOfHead = 0.0F;
/*  997 */     float radiusOverDistanceToSource = 0.0F;
/*      */
/*  999 */     float alpha = 0.0F;
/* 1000 */     float sinAlpha = 0.0F;
/* 1001 */     float gamma = 0.0F;
/*      */
/* 1004 */     float speedOfSound = 0.344F;
/* 1005 */     float invSpeedOfSound = 1.0F / 0.344F;
/*      */
/* 1007 */     float sampleRate = 44.099998F;
/*      */
/* 1009 */     boolean rightEarClosest = false;
/* 1010 */     boolean soundFromBehind = false;
/*      */
/* 1012 */     float distanceGain = 1.0F;
/* 1013 */     float allGains = this.gain;
/*      */
/* 1015 */     Point3f workingPosition = new Point3f();
/* 1016 */     Point3f workingCenterEar = new Point3f();
/*      */
/* 1020 */     Vector3f mixScale = new Vector3f();
/*      */
/* 1023 */     workingPosition.set(this.positions[this.currentIndex]);
/* 1024 */     workingCenterEar.set(this.centerEars[this.currentIndex]);
/*      */
/* 1042 */     this.sourceToCenterEar.x = (workingCenterEar.x - workingPosition.x);
/* 1043 */     this.sourceToCenterEar.y = (workingCenterEar.y - workingPosition.y);
/* 1044 */     this.sourceToCenterEar.z = (workingCenterEar.z - workingPosition.z);
/* 1045 */     this.sourceToRightEar.x = (this.xformRightEar.x - workingPosition.x);
/* 1046 */     this.sourceToRightEar.y = (this.xformRightEar.y - workingPosition.y);
/* 1047 */     this.sourceToRightEar.z = (this.xformRightEar.z - workingPosition.z);
/* 1048 */     this.sourceToLeftEar.x = (this.xformLeftEar.x - workingPosition.x);
/* 1049 */     this.sourceToLeftEar.y = (this.xformLeftEar.y - workingPosition.y);
/* 1050 */     this.sourceToLeftEar.z = (this.xformLeftEar.z - workingPosition.z);
/*      */
/* 1058 */     distanceSourceToCenterEar = workingPosition.distance(workingCenterEar);
/* 1059 */     distanceSourceToRightEar = workingPosition.distance(this.xformRightEar);
/* 1060 */     distanceSourceToLeftEar = workingPosition.distance(this.xformLeftEar);
/* 1061 */     distanceBetweenEars = this.xformRightEar.distance(this.xformLeftEar);
/*      */
/* 1066 */     radiusOfHead = distanceBetweenEars * 0.5F;
/*      */
/* 1069 */     radiusOverDistanceToSource = radiusOfHead / distanceSourceToCenterEar;
/*      */
/* 1087 */     double dotProduct = this.sourceToCenterEar.dot(this.xformHeadZAxis) / (this.sourceToCenterEar.length() * this.xformHeadZAxis.length());
/*      */
/* 1092 */     alpha = (float)Math.acos(dotProduct);
/*      */
/* 1096 */     if (alpha > halfPi)
/*      */     {
/* 1099 */       soundFromBehind = true;
/* 1100 */       alpha = 3.141593F - alpha;
/*      */     }
/*      */     else
/*      */     {
/* 1105 */       soundFromBehind = false;
/*      */     }
/*      */
/* 1110 */     gamma = (float)Math.acos(radiusOverDistanceToSource);
/*      */
/* 1114 */     rightEarClosest = distanceSourceToRightEar <= distanceSourceToLeftEar;
/*      */
/* 1119 */     if (rightEarClosest)
/*      */     {
/* 1122 */       if (soundFromBehind)
/* 1123 */         quadrant = 4;
/*      */       else {
/* 1125 */         quadrant = 1;
/*      */       }
/*      */
/*      */     }
/* 1130 */     else if (soundFromBehind)
/* 1131 */       quadrant = 3;
/*      */     else {
/* 1133 */       quadrant = 2;
/*      */     }
/* 1135 */     sinAlpha = (float)Math.sin(alpha);
/* 1136 */     if (sinAlpha < 0.0D) sinAlpha = -sinAlpha;
/*      */
/* 1145 */     float DISTANCE = (float)Math.sqrt(distanceSourceToCenterEar * distanceSourceToCenterEar + radiusOfHead * radiusOfHead);
/*      */
/* 1151 */     if (rightEarClosest) {
/* 1152 */       distanceSourceToLeftEar = DISTANCE + radiusOfHead * (halfPi + alpha - gamma);
/*      */     }
/*      */     else
/*      */     {
/* 1159 */       distanceSourceToRightEar = DISTANCE + radiusOfHead * (halfPi + alpha - gamma);
/*      */     }
/*      */
/* 1171 */     if (sinAlpha < radiusOverDistanceToSource)
/*      */     {
/* 1176 */       if (rightEarClosest) {
/* 1177 */         distanceSourceToRightEar = DISTANCE + radiusOfHead * (halfPi - alpha - gamma);
/*      */       }
/*      */       else
/*      */       {
/* 1184 */         distanceSourceToLeftEar = DISTANCE + radiusOfHead * (halfPi - alpha - gamma);
/*      */       }
/*      */
/*      */     }
/* 1194 */     else if (!rightEarClosest);
/* 1215 */     sampleRate = this.channel.rateInHz * 0.001F;
/* 1216 */     if (rightEarClosest) {
/* 1217 */       this.rightDelay = 0;
/* 1218 */       this.leftDelay = ((int)((distanceSourceToLeftEar - distanceSourceToRightEar) * invSpeedOfSound * sampleRate));
/*      */     }
/*      */     else
/*      */     {
/* 1222 */       this.leftDelay = 0;
/* 1223 */       this.rightDelay = ((int)((distanceSourceToRightEar - distanceSourceToLeftEar) * invSpeedOfSound * sampleRate));
/*      */     }
/*      */
/* 1236 */     workingPosition.sub(workingCenterEar);
/*      */
/* 1238 */     workingPosition.scale(1.0F / distanceSourceToCenterEar);
/*      */
/* 1249 */     distanceGain = calculateDistanceAttenuation(distanceSourceToCenterEar);
/*      */
/* 1251 */     allGains *= distanceGain;
/*      */
/* 1259 */     allGains *= calculateAngularGain();
/*      */
/* 1263 */     float halfX = workingPosition.x / 2.0F;
/*      */     float intensityOffset;
/*      */     float intensityOffset;
/* 1264 */     if (halfX >= 0.0F)
/* 1265 */       intensityOffset = intensityDifference * (0.5F - halfX);
/*      */     else {
/* 1267 */       intensityOffset = intensityDifference * (0.5F + halfX);
/*      */     }
/*      */
/* 1274 */     switch (quadrant)
/*      */     {
/*      */     case 1:
/*      */     case 4:
/* 1279 */       this.rightGain = (allGains * (intensityHigh - intensityOffset));
/* 1280 */       this.leftGain = (allGains * (intensityLow + intensityOffset));
/* 1281 */       break;
/*      */     case 2:
/*      */     case 3:
/* 1287 */       this.leftGain = (allGains * (intensityHigh - intensityOffset));
/* 1288 */       this.rightGain = (allGains * (intensityLow + intensityOffset));
/*      */     }
/*      */
/* 1297 */     calculateFilter(distanceSourceToCenterEar, attribs);
/*      */   }
/*      */ }

/* Location:           Z:\System\Library\Java\Extensions\j3daudio.jar
* Qualified Name:     com.sun.j3d.audioengines.javasound.JSPositionalSample
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.audioengines.javasound.JSPositionalSample

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.