Пример #1
0
  public void draw() {
    if (tone.isPlaying()) {
      background(255);
    } else {
      background(100);
    }

    // Set the volume to a range between 0 and 1.0
    float ratio = (float) mouseX / width;
    tone.setVolume(ratio);

    // Set the rate to a range between 0 and 88,200
    // Changing the rate alters the pitch
    ratio = (float) mouseY / height;

    // The rate is set according to the mouseY position.
    tone.setRate(ratio * 88200);

    // Draw some rectangles to show what is going on
    stroke(0);
    fill(175);
    rect(0, 160, mouseX, 20);
    stroke(0);
    fill(175);
    rect(160, 0, 20, mouseY);
  }
Пример #2
0
 // Pressing the mouse stops and starts the sound
 public void mousePressed() {
   if (tone.isPlaying()) {
     tone.stop(); //   The sound can be stopped with the function stop().
   } else {
     tone.repeat();
   }
 }
Пример #3
0
  public void setup() {
    size(200, 200);
    // Start Sonia engine.
    Sonia.start(this);

    // Create a new sample object.
    tone = new Sample("tone.wav");

    // Loop the sound forever
    // (well, at least until stop() is called)
    tone.repeat();
    smooth();
  }