Exemplo n.º 1
0
  public static void main(String[] args) throws Exception {
    SoundUtils.laser(5);
    Thread.sleep(1000);
    SoundUtils.warp(10);
    Thread.sleep(1000);
    SoundUtils.bang();

    SoundUtils.tone(5000, 100);
    Thread.sleep(1000);
  }
Exemplo n.º 2
0
 private void leuchten(JLabel label, String farbe) {
   try {
     if (!leuchten) {
       Thread.sleep(200);
       label.setIcon(new ImageIcon(farbe + "_0.png"));
       Thread.sleep(200);
       label.setIcon(new ImageIcon(farbe + "_1.png"));
       Thread.sleep(200);
       label.setIcon(new ImageIcon(farbe + "_0.png"));
       Thread.sleep(200);
       label.setIcon(new ImageIcon(farbe + "_1.png"));
       leuchten = true;
     }
   } catch (Exception e) {
   }
 }
Exemplo n.º 3
0
  public int write(byte[] data, int ofs, int len) {

    int maxTries = 10;
    int totWrite = 0;
    int nofs = ofs, nlen = len;
    while (nofs < ofs + len && maxTries > 0) {

      int written = 0;
      if (format.getBits() == 16 && format.getChannels() == 2 && format.getRate() == INPUT_RATE)
        written = sdl.write(data, nofs, nlen);
      else written = writeConv(data, nofs, nlen);

      nofs += written;
      nlen -= written;
      totWrite += written;
      maxTries--;
      deliveredData += written;

      // calculations when channels and bits and rate varies...
      // int divisor = (format.getBits() / 8) * format.getChannels();
      // int deliveredTime =
      // (int) (1000 * deliveredData / (format.getRate() * divisor));

      int deliveredTime = (int) (1000 * deliveredData / (INPUT_RATE * 4));
      long pos = sdl.getMicrosecondPosition() / 1000;
      long sleepTime = deliveredTime - pos - bufferTime;
      if (sleepTime < 0) sleepTime = 0;

      try {
        Thread.sleep(sleepTime);
      } catch (InterruptedException e) {
      }
    }
    return totWrite;
  }
Exemplo n.º 4
0
  public static void laser(int repeat) throws LineUnavailableException, InterruptedException {
    AudioFormat af =
        new AudioFormat(
            SAMPLE_RATE, // sampleRate
            8, // sampleSizeInBits
            1, // channels
            true, // signed
            false); // bigEndian
    SourceDataLine sdl = AudioSystem.getSourceDataLine(af);
    sdl.open(af);
    sdl.start();

    byte[] buf = new byte[1];
    int step;

    for (int j = 0; j < repeat; j++) {
      step = 10;
      for (int i = 0; i < 2000; i++) {
        buf[0] = ((i % step > 0) ? 32 : (byte) 0);

        if (i % 250 == 0) step += 2;
        sdl.write(buf, 0, 1);
      }
      Thread.sleep(200);
    }
    sdl.drain();
    sdl.stop();
    sdl.close();
  }
Exemplo n.º 5
0
    @Override
    public void run() {
      while (!stopped) {
        synchronized (this) {
          if (updateRequired_0) {
            if (frequency_0 == 0) {
              clip0.stop();
            } else {
              playFrequency(clip0, frequency_0);
            }

            updateRequired_0 = false;
          }
        }

        synchronized (this) {
          if (updateRequired_1) {
            if (frequency_1 == 0) {
              clip1.stop();
            } else {
              playFrequency(clip1, frequency_1);
            }

            updateRequired_1 = false;
          }
        }

        try {
          Thread.sleep(50);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
Exemplo n.º 6
0
 private void neueFarbe() {
   try {
     if ((runde % 2) == 0 && wait > 25) {
       wait = wait - 25;
     }
     klick = 0;
     durchgang++;
     zahl = zufall.nextInt(4);
     switch (zahl) {
       case (0):
         rot.setIcon(new ImageIcon("files/Minigames/Senso/red_1.png"));
         soundAbspielen(soundR);
         einfuegen(runde, 1);
         Thread.sleep(wait + 25);
         rot.setIcon(new ImageIcon("files/Minigames/Senso/red_0.png"));
         break;
       case (1):
         gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_1.png"));
         soundAbspielen(soundG);
         einfuegen(runde, 2);
         Thread.sleep(wait + 25);
         gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_0.png"));
         break;
       case (2):
         blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_1.png"));
         soundAbspielen(soundB);
         einfuegen(runde, 3);
         Thread.sleep(wait + 25);
         blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_0.png"));
         break;
       case (3):
         gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_1.png"));
         soundAbspielen(soundY);
         einfuegen(runde, 4);
         Thread.sleep(wait + 25);
         gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_0.png"));
         break;
     }
     durchgang = 0;
     runde++;
     neu = false;
     kopieren();
   } catch (Exception ex) {
   }
 }
Exemplo n.º 7
0
 /*
  * Maintenance to be done before playing; pause/mute management.
  */
 private static void prePlay() {
   if (muted) {
     return;
   }
   while (paused) {
     try {
       Thread.sleep(100);
     } catch (InterruptedException ie) {
       // empty
     }
   }
 }
Exemplo n.º 8
0
 ////////////////////////////////////////////////////////////////////////////
 // needed for     implement runnable
 public void run() {
   while (true) {
     animate();
     repaint();
     double seconds = 0.04; // time that 1 frame takes.
     int miliseconds = (int) (1000.0 * seconds);
     try {
       Thread.sleep(miliseconds);
     } catch (InterruptedException e) {
     }
   }
 }
Exemplo n.º 9
0
 private void alteFarbe() {
   try {
     int alt = 0;
     for (int i = 0; i < farben.length; i++) {
       durchgang++;
       alt = farben[i];
       Thread.sleep(wait);
       switch (alt) {
         case 1:
           rot.setIcon(new ImageIcon("files/Minigames/Senso/red_1.png"));
           soundAbspielen(soundR);
           Thread.sleep(wait + 25);
           rot.setIcon(new ImageIcon("files/Minigames/Senso/red_0.png"));
           break;
         case 2:
           gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_1.png"));
           soundAbspielen(soundG);
           Thread.sleep(wait + 25);
           gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_0.png"));
           break;
         case 3:
           blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_1.png"));
           soundAbspielen(soundB);
           Thread.sleep(wait + 25);
           blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_0.png"));
           break;
         case 4:
           gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_1.png"));
           soundAbspielen(soundY);
           Thread.sleep(wait + 25);
           gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_0.png"));
           break;
       }
     }
     wiedergeben = false;
     neu = true;
   } catch (Exception e) {
   }
 }
Exemplo n.º 10
0
 public static void main(String[] args) {
   try {
     byte[] wav = Base64Coder.base64ToBinary(getWaveLiteral().toCharArray(), 0, WAV_SIZE);
     InputStream is = new ByteArrayInputStream(wav);
     AudioFormat fmt = AudioSystem.getAudioFileFormat(is).getFormat();
     AudioInputStream sound = AudioSystem.getAudioInputStream(is);
     DataLine.Info info = new DataLine.Info(Clip.class, fmt);
     Clip clip = (Clip) AudioSystem.getLine(info);
     clip.open(sound);
     clip.start();
     Thread.sleep(3000);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
Exemplo n.º 11
0
  /**
   * this will try to write all the indicated data whitout ever giving up... Either all the data is
   * written or it will loop for ever.
   *
   * @param data
   * @param ofs
   * @param len
   */
  private void writeData(byte[] data, int ofs, int len) {
    int count = 0;
    int written = 0;
    while (written < len) {
      written += sdl.write(data, ofs + written, len - written);

      // take a litle break if we couldn't write everything in 100
      // tries...
      count++;
      if (count >= 100) {
        try {
          Thread.sleep(10);
        } catch (InterruptedException e) {
        }
        count = 0;
      }
    }
  }
Exemplo n.º 12
0
 public void run() {
   try {
     while (läuft) {
       Thread.sleep(1);
       if (verloren) {
         verloren();
       } else {
         if (intro) {
           rot.setIcon(new ImageIcon("files/Minigames/Senso/red_n.png"));
           gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_n.png"));
           blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_n.png"));
           gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_n.png"));
           lblVerloren.setText("");
           start.setText("3");
           Thread.sleep(1000);
           start.setText("2");
           Thread.sleep(1000);
           start.setText("1");
           Thread.sleep(1000);
           start.setLocation(start.getX() - 20, start.getY());
           start.setText("Los!");
           Thread.sleep(250);
           start.setText("");
           start.setLocation(start.getX() + 20, start.getY());
           rot.setIcon(new ImageIcon("files/Minigames/Senso/red_0.png"));
           gruen.setIcon(new ImageIcon("files/Minigames/Senso/green_0.png"));
           blau.setIcon(new ImageIcon("files/Minigames/Senso/blue_0.png"));
           gelb.setIcon(new ImageIcon("files/Minigames/Senso/yellow_0.png"));
           intro = false;
           neu = true;
         }
         if (wiedergeben && !verloren) {
           Thread.sleep(500);
           alteFarbe();
         } else if (neu && !verloren) neueFarbe();
         if (!wiedergeben && !neu) {
           String s = "Noch ";
           vKlicks = runde - klick;
           if (vKlicks >= 1) s = s + String.valueOf(vKlicks);
           else s = "";
           klicks.setText(s);
         } else klicks.setText("");
       }
     }
   } catch (Exception e) {
   }
 }
Exemplo n.º 13
0
  private void fade(FloatControl control, double to) {
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (control) {
      int steps = FADE_DURATION / FADE_STEP_DURATION;

      to = (to <= 0.0) ? 0.0001 : ((to > 1.0) ? 1.0 : to);

      float currDB = control.getValue();
      float toDB = getDb(to);

      float diffStep = (toDB - currDB) / (float) steps;
      for (int i = 0; i < steps; i++) {
        currDB += diffStep;
        currDB = (Math.abs(currDB - toDB) < Math.abs(diffStep * 1.5)) ? toDB : currDB;
        control.setValue(currDB);
        try {
          Thread.sleep(FADE_STEP_DURATION);
        } catch (Exception ignored) {
          ignored.printStackTrace();
        }
      }
    }
  }
Exemplo n.º 14
0
 public static void sleep(int ms) {
   try {
     Thread.sleep(ms);
   } catch (Exception e) {
   }
 }