Пример #1
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);
  }
Пример #2
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);
  }