Esempio n. 1
0
 /**
  * Returns the <sup>10</sup>log() of a value
  *
  * @return the <sup>10</sup>log()
  */
 static double log10(int v) {
   double dl = 0.0;
   if (v != 0.0) {
     dl = Math.log(v) / Math.log(10);
   }
   return dl;
 }
Esempio n. 2
0
  public boolean play() {

    try {
      if (playState != STOPPED) playStop();

      if (audioBytes == null) return false;

      DataLine.Info info = new DataLine.Info(Clip.class, format);

      clip = (Clip) AudioSystem.getLine(info);
      clip.addLineListener(new ClipListener());

      long clipStart = (long) (audioBytes.length * getStartTime() / (getDuration() * 1000.0));
      long clipEnd = (long) (audioBytes.length * getEndTime() / (getDuration() * 1000.0));
      if ((clipEnd - clipStart) > MAX_CLIP_LENGTH) clipEnd = clipStart + MAX_CLIP_LENGTH;
      byte[] clipBytes = new byte[(int) (clipEnd - clipStart)];
      System.arraycopy(audioBytes, (int) clipStart, clipBytes, 0, clipBytes.length);
      clip.open(format, clipBytes, 0, clipBytes.length);

      FloatControl panControl = (FloatControl) clip.getControl(FloatControl.Type.PAN);

      panControl.setValue((float) panSetting / 100.0f);

      double value = (double) gainSetting;

      FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
      float dB = (float) (Math.log(value == 0.0 ? 0.0001 : value) / Math.log(10.0) * 20.0);
      gainControl.setValue(dB);
      double playStartTime = (player.getSeekTime() / 100) * (playGetLength());
      clip.setMicrosecondPosition((long) playStartTime);

      clip.start();

      playState = PLAYING;

      return true;

    } catch (Exception ex) {
      ex.printStackTrace();
      playState = STOPPED;
      clip = null;
      return false;
    }
  }
 public double evaluate(double x) {
   return Math.log(x * x + 1) - Math.exp(0.4 * x) * Math.cos(Math.PI * x);
 }
Esempio n. 4
0
  /**
   * Computes the output property. A {@link java.beans.PropertyChangeEvent} is fired for the output
   * property if it differs from the previous value.
   *
   * @throws VisADException if a VisAD failure occurs.
   * @throws RemoteException if a Java RMI exception occurs.
   */
  void clock() throws VisADException, RemoteException {

    Set domainSet = buoyProfile.getDomainSet();
    Real oldLfc;
    Real newLfc;
    double[] pressures = domainSet.getDoubles()[0];
    float[] buoys = buoyProfile.getFloats()[0];

    /* Eliminate non-finite pressures and buoyancies. */
    int n = 0;

    for (int i = 0; i < pressures.length; i++) {
      if ((pressures[i] != pressures[i]) || (buoys[i] != buoys[i])) {
        n++;
      }
    }

    if (n > 0) {
      double[] tmpPres = new double[pressures.length - n];
      float[] tmpBuoy = new float[tmpPres.length];

      n = 0;

      for (int i = 0; i < pressures.length; i++) {
        if ((pressures[i] != pressures[i]) || (buoys[i] != buoys[i])) {
          continue;
        }

        tmpPres[n] = pressures[i];
        tmpBuoy[n] = buoys[i];

        n++;
      }

      pressures = tmpPres;
      buoys = tmpBuoy;
    }

    if (pressures.length <= 1) {
      newLfc = missingLfc;
    } else {
      Unit presUnit = domainSet.getSetUnits()[0];
      boolean ascending = pressures[0] > pressures[1];

      if (!ascending) {

        /*
         * The profile is descending.  Make the temporary value arrays
         * ascending.
         */
        for (int i = 0, j = pressures.length; i < pressures.length / 2; i++) {
          --j;

          double pres = pressures[i];

          pressures[i] = pressures[j];
          pressures[j] = pres;

          float buoy = buoys[i];

          buoys[i] = buoys[j];
          buoys[j] = buoy;
        }
      }

      /*
       * Descend from the top to positive buoyancy.
       */
      int i = buoys.length;

      while ((--i >= 0) && (buoys[i] <= 0)) ;

      if (i < 0) {

        /*
         * There is no positively buoyant region.
         */
        newLfc = missingLfc;
      } else {

        /*
         * Descend to first non-positive buoyant region.
         */
        while ((--i >= 0) && (buoys[i] > 0)) ;

        if (i < 0) {

          /*
           * There is no non-positive buoyant region.
           */
          newLfc = missingLfc;
        } else {

          /*
           * Interpolate the LFC.
           */
          double pressure =
              pressures[i + 1]
                  / Math.exp(
                      buoys[i + 1]
                          * (Math.log(pressures[i] / pressures[i + 1])
                              / (buoys[i] - buoys[i + 1])));

          newLfc = new Real((RealType) missingLfc.getType(), pressure, presUnit);
        }
      }
    }

    synchronized (this) {
      oldLfc = lfc;
      lfc = newLfc;
    }

    firePropertyChange(OUTPUT_PROPERTY_NAME, oldLfc, newLfc);
  }