Пример #1
0
  public void draw() {
    background(0);
    stroke(255);

    // perform a forward FFT on the samples in jingle's mix buffer,
    // which contains the mix of both the left and right channels of the file
    fft.forward(jingle.mix);

    for (int i = 0; i < fft.specSize(); i++) {
      // draw the line for frequency band i, scaling it up a bit so we can see it
      line(i, height / 2, i, height / 2 - fft.getBand(i) * 4);
    }

    stroke(255, 0, 0);
    for (int beat : beats) {
      float x = beat * width / totalSamples;
      line(x, 0, x, height);
    }

    stroke(255, 255, 0);
    float x = jingle.position() * width / jingle.length();
    line(x, 0, x, height);

    image(preview, 0, 0);

    stroke(0, 255, 0);
    float s = (float) width / samples.length;
    line(loopStart * s, 0, loopStart * s, height);
    line(loopEnd * s, 0, loopEnd * s, height);
  }
Пример #2
0
 public void execute(int globalTime) {
   if (!ap.isPlaying()) {
     int playAt = globalTime - timeStamp;
     ap.play(playAt);
     println("gTime is " + globalTime + " delTime is " + playAt);
   }
 }
Пример #3
0
 /** Fades the song out, then pauses the song. */
 public void pauseSong() {
   if (!fadeEnter) {
     songPause = System.currentTimeMillis();
     setGainShift(-30);
     fadeEnter = true;
   }
   if (song.isPlaying() && (System.currentTimeMillis() - songPause) >= songFade) {
     song.pause();
   }
   ourPause = true;
 }
Пример #4
0
 /** Resumes the song. Used when there is user input */
 public void resumeSong() {
   if (fadeEnter) {
     song.play();
     setGainShift(0);
     fadeEnter = false;
   }
   ourPause = false;
 }
Пример #5
0
  /** Returns true if the song has been played through, otherwise false */
  public boolean isEndOfSong() {
    if (songOver) return true;

    if (!song.isPlaying() && !ourPause) { // If song is not playing and we did not pause
      songOver = true;
      return true;
    } else return false;
  }
Пример #6
0
 public void start() {
   song.play();
   // FOR STARTING FROM LAST TEN SECONDS
   // int t = song.length() - 5000;
   // song.play(t);
   // song.setGain(0);
   ourPause = false;
 }
Пример #7
0
  public SoundControl(String s) throws IOException {
    MinimObject minimObj = new MinimObject();
    minim = new Minim(minimObj);
    maxBass = Constants.MAX_PLAYER_SIZE;
    frame = Constants.FRAME_TO_GENERATE_ENEMIES;
    fftThreshold = Constants.FFT_THRESHOLD;
    fftLeftThreshold = Constants.FFT_LEFT_THRESHOLD;
    consecFramesGenned = 0;

    song = minim.loadFile(s);
    songLength = song.length();
    songOver = false;

    fadeEnter = false;

    fft = new FFT(song.bufferSize(), song.sampleRate());
    fft.linAverages(bands);
    setFftLog(new FFT(song.bufferSize(), song.sampleRate()));
    getFftLog().logAverages(22, 12);

    fftPrev = new float[bands];
    fftDiff = new float[bands];
    groupings = new int[120];
    beats = new boolean[120];

    beat = new BeatDetect(song.bufferSize(), song.sampleRate());
    beat.setSensitivity(10);

    bl = new BeatListener(beat, song);
  }
Пример #8
0
  public void analyze(int start) {
    diffs.clear();

    loopStart = start;
    int SUB = 64;
    int N = 2048 * SUB;
    float maxDiff = 0;
    int upper = (int) min(samples.length - N, start + 30 * jingle.getFormat().getSampleRate());
    for (int i = start + N; i < upper - N; i++) {
      if (i % 10000 == 0) System.out.println(i + "/" + (upper - start));
      float diff = 0;
      for (int j = 0; j < N; j += SUB) {
        diff += Math.abs(samples[i + j] - samples[start + j]);
      }
      maxDiff = max(maxDiff, diff);
      diffs.put(i, new PVector(i, diff));
    }

    preview.beginDraw();
    preview.clear();
    preview.noFill();
    preview.stroke(255);
    preview.beginShape();
    for (int i = 0; i <= width; i++) {
      preview.vertex(
          i, preview.height / 2 + height / 2 * samples[(int) (i * (samples.length - 1l) / width)]);
    }
    preview.endShape();
    preview.endDraw();

    preview.beginDraw();
    preview.clear();
    preview.stroke(255, 0, 0);
    preview.beginShape();
    int n = 0;
    int prevX = 0;
    float sum = maxDiff;
    for (PVector diff : diffs.values()) {
      int x = (int) (diff.x * (long) width / samples.length);
      sum = min(diff.y, sum);
      n = 1;
      if (x != prevX) {
        preview.vertex(x, preview.height * sum / maxDiff / n);
        n = 0;
        sum = maxDiff;
        prevX = x;
      }
    }
    preview.endShape();
    preview.endDraw();
  }
Пример #9
0
  @Override
  public void keyPressed() {
    if (key == 'r') {
      loopEnd = (int) (mouseX * (long) samples.length / width);
    }
    if (key == 'a') {
      PVector best = new PVector(0, Float.MAX_VALUE);
      int sampleNr = (int) (mouseX * (long) samples.length / width);
      for (int i = sampleNr - 500000; i < sampleNr + 500000; i++) {
        PVector diff = diffs.get(i);
        if (diff != null) {
          if (diff.y < best.y) best = diff;
        }
      }

      if (best.x != 0) {
        loopEnd = (int) best.x;
      }
    }
    if (keyCode == RIGHT) {
      jingle.cue((int) (loopEnd * 1000l / jingle.getFormat().getSampleRate() - 1000));
    }
  }
Пример #10
0
 /**
  * Sets gain.
  *
  * @param gain the value to set gain to
  */
 public void setGainShift(float gain) {
   song.shiftGain(song.getGain(), gain, songFade);
 }
Пример #11
0
 public void stop() {
   song.close();
   minim.stop();
 }
Пример #12
0
 public boolean isPlaying() {
   return song.isPlaying();
 }
Пример #13
0
  public void setup() {
    size(1200, 200, JAVA2D);
    preview = createGraphics(width, 100);
    minim = new Minim(this);
    mimp = new JSMinim(this);
    mimp.debugOn();
    // specify that we want the audio buffers of the AudioPlayer
    // to be 1024 samples long because our FFT needs to have
    // a power-of-two buffer size and this is a good size.
    jingle = minim.loadFile(filename, 1024);
    // loop the file indefinitely
    jingle.loop();

    // create an FFT object that has a time-domain buffer
    // the same size as jingle's sample buffer
    // note that this needs to be a power of two
    // and that it means the size of the spectrum will be half as large.
    fft = new FFT(jingle.bufferSize(), jingle.sampleRate());
    MultiChannelBuffer sampleBuffer = new MultiChannelBuffer(0, 0); // params don't matter!
    float jingleBuffer = loadFileIntoBuffer(filename, sampleBuffer);
    totalSamples = sampleBuffer.getBufferSize();
    beat = new BeatDetect(4096 * 4, jingle.sampleRate());
    beat.setSensitivity(1);
    beat.detectMode(BeatDetect.FREQ_ENERGY);
    // find ALL beats
    float data[] = new float[2048];
    samples = sampleBuffer.getChannel(1);

    //		for( int i = 0; i < samples.length; i+= data.length ){
    //			int j = Math.min( samples.length-1, i + data.length - 1 );
    ////			System.out.println( "copy up to including " + ( j ) + " / " + samples.length);
    //			System.arraycopy( samples, i, data, 0, 1 + j - i );
    //			beat.detect( data );
    //			if( beat.isOnset() ){
    //				beats.add( i );
    //				System.out.println( i + ": " + beat.isKick() );
    //			}
    //		}

    // pick some starting point ...
    loopEnd = samples.length;
    int start = (int) random(3 * samples.length / 5);
    analyze(start);
    new Thread() {
      public void run() {
        try {
          while (true) {
            Thread.sleep(1);
            // figure it out
            int s = (int) (loopStart * 1000l / jingle.getFormat().getSampleRate());
            int e = (int) (loopEnd * 1000l / jingle.getFormat().getSampleRate());
            if (jingle.position() < s) jingle.cue(s + 10);
            else if (jingle.position() > e) jingle.cue(s);
            else continue;
            Thread.sleep(500);
          }
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }.start();

    //		System.exit(0);
  }
Пример #14
0
  SplashScreen(PApplet p) {
    parent = p;
    splash1 = loadImage("spaceFury01.png");
    splash2 = loadImage("spaceFury02.png");
    splash3 = loadImage("spaceFury03.png");

    playbutton = loadImage("playbutton.png");
    playbutton2 = loadImage("playbutton2.png");

    highscorebutton = loadImage("highscore.png");
    highscorebutton2 = loadImage("highscore2.png");

    settingbutton = loadImage("setting.png");
    settingbutton2 = loadImage("setting2.png");

    quitbutton = loadImage("quit.png");
    quitbutton2 = loadImage("quit2.png");

    backbutton = loadImage("back.png");
    backbutton2 = loadImage("back2.png");

    // control images
    moverl = parent.loadImage("moverightleft.png");
    spaceShoot = parent.loadImage("spaceShoot.png");
    pauseimg = parent.loadImage("pauseimg.png");
    buttonR = parent.loadImage("buttonR.png");
    buttonM = parent.loadImage("buttonM.png");
    buttonQ = parent.loadImage("buttonQ.png");

    // headers
    controlsline = parent.loadImage("controlsline.png");
    bulletsline = parent.loadImage("bulletsline.png");
    difficultyline = parent.loadImage("difficultyline.png");

    // firebullet
    bullet1 = parent.loadImage("fireball1.png");
    bullet2 = parent.loadImage("fireball2.png");
    bullet3 = parent.loadImage("fireball3.png");
    bullet4 = parent.loadImage("fireball4.png");

    // waterbullet
    waterbullet1 = parent.loadImage("waterbullet1.png");
    waterbullet2 = parent.loadImage("waterbullet2.png");
    waterbullet3 = parent.loadImage("waterbullet3.png");
    waterbullet4 = parent.loadImage("waterbullet4.png");

    // difficulty image rollover
    easy = parent.loadImage("easy.png");
    easy2 = parent.loadImage("easy2.png");
    medium = parent.loadImage("medium.png");
    medium2 = parent.loadImage("medium2.png");
    hard = parent.loadImage("hard.png");
    hard2 = parent.loadImage("hard2.png");

    // highscore animation images
    topShooters = parent.loadImage("topShooters.png");
    topShooters2 = parent.loadImage("topShooters2.png");
    topShooters3 = parent.loadImage("topShooters3.png");
    topShooters4 = parent.loadImage("topShooters4.png");
    topShooters5 = parent.loadImage("topShooters5.png");
    topShooters6 = parent.loadImage("topShooters6.png");

    scoreList.add(0);
    scoreList.add(0);
    scoreList.add(0);

    minim = new Minim(this);
    menuMusic = minim.loadFile("menuMusic.mp3", 2048);
    menuMusic.play();
  }
Пример #15
0
 public void pauseAudio() {
   ap.pause();
 }