shatonyourcat
YaBB Newbies
Offline
Posts: 2
Minim Beat Detection isRange() Error
Mar 26th , 2010, 1:29pm
I am getting an arrayoutofboundsexception: 27 error when I try to use the isRange() function. However, when I use the isKick/isSnare/isHat functions it works. Any help would be greatly appreciated. Here is my code: I've commented out the problem code: if(beat.isRange(0, 5000, 0)){ print("TRUEEEEEEEE"); } The rest of it is here import ddf.minim.*; import ddf.minim.signals.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import processing.serial.*; import cc.arduino.*; Arduino arduino; int m0 = 0; int m1 = 1; int m2 = 2; int m3 = 3; int m4 = 4; int m5 = 5; int m6 = 6; int m7 = 7; int m8 = 8; int m12 = 0; class AudioSocket implements AudioListener, AudioSignal { private float[] left; private float[] right; private int buffer_max; private int inpos, outpos; private int count; // AudioSocket makes and AudioSignal out of an AudioListener. // That is, it will accept the samples supplied to it by other // AudioSignals (like an AudioListener), but then it will // pass these on to any listeners to which it is connected. // To deal with scheduling asynchronies, it maintains an // internal FIFO buffer to temporarily stage samples it // has been given until it has somewhere to send them. // Assumes that samples will always enter and exit in blocks // of buffer_size, so we don't have to worry about splitting // blocks across the ring-buffer boundary AudioSocket(int buffer_size) { int n_buffers = 4; buffer_max = n_buffers * buffer_size; left = new float[buffer_max]; right = new float[buffer_max]; inpos = 0; outpos = 0; count = 0; } // The AudioListener:samples method accepts new input samples synchronized void samples(float[] samp) { // handle mono by writing samples to both left and right samples(samp, samp); } synchronized void samples(float[] sampL, float[] sampR) { System.arraycopy(sampL, 0, left, inpos, sampL.length); System.arraycopy(sampR, 0, right, inpos, sampR.length); inpos += sampL.length; if (inpos == buffer_max) { inpos = 0; } count += sampL.length; // println("samples: count="+count); } // The AudioSignal:generate method supplies new output // samples when requested void generate(float[] samp) { // println("generate: count="+count); if (count > 0) { System.arraycopy(left, outpos, samp, 0, samp.length); outpos += samp.length; if (outpos == buffer_max) { outpos = 0; } count -= samp.length; } } void generate(float[] sampL, float[] sampR) { // handle stereo by copying one channel, then passing the other channel // to the mono handler which will update the pointers if (count > 0) { System.arraycopy(right, outpos, sampR, 0, sampR.length); generate(sampL); } } } Minim minim; AudioInput in; AudioOutput out; AudioSocket socket; FFT fft; BeatDetect beat; BeatListener bl; void setup() { size(512, 200); minim = new Minim(this); minim.debugOn(); // get a line in from Minim, default bit depth is 16 int buffer_size = 512; //int buffer_size = 4096; in = minim.getLineIn(Minim.STEREO, buffer_size); out = minim.getLineOut(Minim.STEREO, buffer_size); // Create the socket to connect input to output socket = new AudioSocket(buffer_size); // Connect the socket as a "listener" for the line-in in.addListener(socket); // .. and then connect it as a "signal" for the line-out out.addSignal(socket); fft = new FFT(in.bufferSize(), in.sampleRate()); beat = new BeatDetect(in.bufferSize(), in.sampleRate()); bl = new BeatListener(beat, in); //beat.detect(in.mix); } float band1 = 0; float band2 = 0; float band3 = 0; float[] band = new float[9]; float move = 0; void draw() { background(0); stroke(255); float m = millis(); fft.forward(in.mix); beat.detect(in.mix); if(beat.isHat()){ print("TRUEEEEEE"); } /* if(beat.isRange(0, 5000, 0)){ print("TRUEEEEEEEE"); } */ int numBands = 9; for (int i=0; i < numBands; i++) { float myHue = map(i, 0, numBands, 0, 100); fill(myHue, 100, 100); float h = fft.getBand(i)*2; int w = width / numBands; rectMode(CENTER); rect(i*w + w/2, height/2, w, h); band[i] = h; // println("band1: " + band[1]); }//end for//////////////////////// //delay(10); stroke(0, 50); for (int i=0; i < in.bufferSize()-1; i++) { float amp = in.mix.get(i/2) * height/2; float nextAmp = in.mix.get(i/2+1) * height/2; line(i, height/2 + amp, i, height/2 + nextAmp); } } float off = 0; //////////////////////////////////////////////////////////////////////////////// // void stop() { // always close Minim audio classes when you are done with them in.close(); out.close(); minim.stop(); super.stop(); }