public void setup() {

    brek = new AudioSample[4][4];
    // load audio samples

    minim = new Minim(this);

    for (int i = 0; i < 4; i++) {
      println("break-beat-0" + (i + 1) + ".mp3");
      brek[i][0] = minim.loadSample("break-beat-0" + (i + 1) + ".mp3", 512);
      brek[i][1] = minim.loadSample("break-perc-0" + (i + 1) + ".mp3", 512);
      brek[i][2] = minim.loadSample("break-piano-0" + (i + 1) + ".mp3", 512);
      brek[i][3] = minim.loadSample("break-strings-0" + (i + 1) + ".mp3", 512);
    }

    size(cellSize * cols, cellSize * rows);

    //  bytes[0]=0;
    // bytes[1]=1;

    grid = new Cell[cols][rows];
    for (int i = 0; i < cols; i++) {
      for (int j = 0; j < rows; j++) {
        grid[i][j] = new Cell(i * cellSize, j * cellSize, cellSize, cellSize);
      }
    }
    println(Serial.list());

    String portName = Serial.list()[2];
    myPort = new Serial(this, portName, 9600);
  }
Esempio n. 2
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);
  }
 public boolean validFreq(float f) {
   if (f < 60) {
     Minim.error("This filter quickly becomes unstable below 60 Hz, setting frequency to 60 Hz.");
     return false;
   }
   return true;
 }
  public void setup() {
    int window_height = 220;
    size((int) (window_height * 5.12f), 220);
    canvas = createGraphics((int) (window_height * 5.12f) / 2, 220, JAVA2D);

    textMode(SCREEN);
    textFont(createFont("SanSerif", 12));

    minim = new Minim(this);

    in = minim.getLineIn(Minim.MONO, buffer_size, sample_rate);

    // create an FFT object that has a time-domain buffer
    // the same size as line-in's sample buffer
    fft = new FFT(in.bufferSize(), in.sampleRate());
    // Tapered window important for log-domain display
    fft.window(FFT.HAMMING);

    // initialize peak-hold structures
    peaksize = 1 + Math.round(fft.specSize() / binsperband);
    peaks = new float[peaksize];
    peak_age = new int[peaksize];

    particles = new Particle[fft.specSize()];
    for (int i = 0; i < fft.specSize(); i++) particles[i] = new Particle(i);
  }
Esempio n. 5
0
 @Override
 protected void removeInput(UGen input) {
   Minim.debug("Bus::removeInput - Removing " + input + " to the m_ugens list of " + this);
   for (int i = 0; i < m_ugens.size(); ++i) {
     if (m_ugens.get(i) == input) {
       m_ugens.set(i, null);
     }
   }
 }
Esempio n. 6
0
 /**
  * Performs a forward transform on the passed buffers.
  *
  * @param buffReal the real part of the time domain signal to transform
  * @param buffImag the imaginary part of the time domain signal to transform
  */
 public void forward(float[] buffReal, float[] buffImag) {
   if (buffReal.length != timeSize || buffImag.length != timeSize) {
     Minim.error("FFT.forward: The length of the passed buffers must be equal to timeSize().");
     return;
   }
   setComplex(buffReal, buffImag);
   bitReverseComplex();
   fft();
   fillSpectrum();
 }
Esempio n. 7
0
  public PureWaveSound(Minim minim, float frequency, float intensity) {
    // Creates the sine wave
    this.wave = new SineWave(frequency, intensity, SAMPLE_RATE);

    // Creates an output line, add the wave signal and silence it.
    this.output = minim.getLineOut(Minim.MONO, BUFFER_SIZE);
    this.output.addSignal(this.wave);
    this.output.noSound();
    // this.output.mute();
  }
Esempio n. 8
0
 // ddf: override because everything that patches to us
 //      goes into our list. then when we generate a sample
 //      we'll sum the audio generated by all of the ugens patched to us.
 @Override
 protected void addInput(UGen input) {
   Minim.debug("Bus::addInput - Adding " + input + " to the m_ugens list of " + this);
   // it needs to know how many channels of audio we expect
   // we set the channel count before adding because concurrency means
   // that we might try to tick input between the add finishing and
   // setAudioChannelCount completing.
   input.setAudioChannelCount(m_tickBuffer.length);
   m_ugens.add(input);
 }
Esempio n. 9
0
 @Override
 public void forward(float[] buffer) {
   if (buffer.length != timeSize) {
     Minim.error(
         "FFT.forward: The length of the passed sample buffer " + "must be equal to timeSize().");
     return;
   }
   doWindow(buffer);
   // copy samples to real/imag in bit-reversed order
   bitReverseSamples(buffer);
   // perform the fft
   fft();
   // fill the spectrum buffer with amplitudes
   fillSpectrum();
 }
Esempio n. 10
0
 @Override
 public void inverse(float[] buffer) {
   if (buffer.length > real.length) {
     Minim.error("FFT.inverse: the passed array's length must equal FFT.timeSize().");
     return;
   }
   // conjugate
   for (int i = 0; i < timeSize; i++) {
     imag[i] *= -1;
   }
   bitReverseComplex();
   fft();
   // copy the result in real into buffer, scaling as we do
   for (int i = 0; i < buffer.length; i++) {
     buffer[i] = real[i] / real.length;
   }
 }
Esempio n. 11
0
 @Override
 public void scaleBand(int i, float s) {
   if (s < 0) {
     Minim.error("Can't scale a frequency band by a negative value.");
     return;
   }
   if (spectrum[i] != 0) {
     real[i] /= spectrum[i];
     imag[i] /= spectrum[i];
     spectrum[i] *= s;
     real[i] *= spectrum[i];
     imag[i] *= spectrum[i];
   }
   if (i != 0 && i != timeSize / 2) {
     real[timeSize - i] = real[i];
     imag[timeSize - i] = -imag[i];
   }
 }
Esempio n. 12
0
 @Override
 public void setBand(int i, float a) {
   if (a < 0) {
     Minim.error("Can't set a frequency band to a negative value.");
     return;
   }
   if (real[i] == 0 && imag[i] == 0) {
     real[i] = a;
     spectrum[i] = a;
   } else {
     real[i] /= spectrum[i];
     imag[i] /= spectrum[i];
     spectrum[i] = a;
     real[i] *= spectrum[i];
     imag[i] *= spectrum[i];
   }
   if (i != 0 && i != timeSize / 2) {
     real[timeSize - i] = real[i];
     imag[timeSize - i] = -imag[i];
   }
 }
Esempio n. 13
0
 // EVENTUALLY, ASSOCIATE A SOUNDFILE FROM THE CONSTRUCTOR AS WELL!!!
 public Dialog(String sFile, int time, Minim m) {
   timeStamp = time;
   type = DIA_TIME;
   ap = m.loadFile(sFile, 2048);
 }
 public void stop() {
   in.close();
   minim.stop();
   super.stop();
 }
Esempio n. 15
0
 public void stop() {
   song.close();
   minim.stop();
 }
Esempio n. 16
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);
  }
Esempio n. 17
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();
  }