Exemplo n.º 1
0
  private static void rand(int t, int range) {
    long t0 = System.currentTimeMillis();
    Random r = new Random();
    double hz;
    double n;
    int d;
    int i;

    while (System.currentTimeMillis() <= t0 + t) {
      n = r.nextInt(range * 12 + 1) / 2.0;
      d = 250 * (r.nextInt(8 - 1) + 1);
      if (r.nextDouble() <= 0.1) {
        i = 0;
      } else {
        i = 1;
      }

      hz = 440 * Math.pow(2, n / 6.0);
      try {
        Tone.sound(hz, d, i);
      } catch (LineUnavailableException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 2
0
 public static void main(String[] args) throws LineUnavailableException {
   Tone.sound(440, 1000, 1);
   scale(440, 2);
   try {
     Thread.sleep(1000);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   rand(30000, 2);
 }
Exemplo n.º 3
0
 private static void scale(int f0, int range) {
   double hz;
   for (double n = 0; n <= 6 * range; n += 0.5) {
     if ((int) (n / 6) != n / 6 && (int) ((n - 2.5) / 6) != (n - 2.5) / 6) {
       n += 0.5;
     }
     hz = f0 * Math.pow(2, n / 6.0);
     try {
       Tone.sound(hz, 100, 1);
     } catch (LineUnavailableException e) {
       e.printStackTrace();
     }
   }
 }