Minim: ArrayIndexOutOfBoundsException
in
Core Library Questions
•
3 years ago
hi, I am experimenting with minim and processing, really new to this, so maybe missing something obvious.
the following program continuously starts oscillators with filter, and when number of running oscillators becomes more than i want, it starts unpatching them one by one. It works for some time, then i get ArrayIndexOutOfBoundsException error, and the problem lies within unpatching, because it works fine without it, except for crackles i get when there are too many oscils. I tried to do this with SineWave at first, but couldn't figure out how to add filters with this method. so, here is my program:
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;
int maxSignals=7;
Minim minim;
AudioOutput out;
Oscil sine[]=new Oscil [maxSignals];
IIRFilter filt[]=new IIRFilter [maxSignals];
void setup()
{
size(512, 200, P3D);
minim = new Minim(this);
// this gets a stereo output
out = minim.getLineOut(Minim.STEREO);
}
float a=0;
float nexttime=0;
int i=0;
boolean unp=false;
void draw()
{
if (millis () >= nexttime) {
int noteLen = int (abs (sin ((PI-a)*19))*100)+100;
float begfreq = abs (sin (a))*400+200;
float endfreq = abs (sin (a))*1000+2000;
float filtFreq = 440;//abs (sin (a))*2000+2020;
float vol = abs (sin (a));
a+=.1;
sine[i]= new Oscil (begfreq, vol, Waves.SINE);
filt [i]=new BandPass(filtFreq, 1, out.sampleRate());
if ( unp) {
sine[maxSignals-i-1].unpatch(out);
filt[maxSignals-i-1].unpatch(out);
println (maxSignals-i-1);
}
sine[i].patch(filt[i]).patch(out);
i+=1;
if (i>=maxSignals) {
i=0;
unp=true;
};
nexttime=millis()+(noteLen);
background(0);
// see waveform.pde for an explanation of how this works
// erase the window to dark green
// draw using a purple stroke
stroke( 232, 255, 255 );
// draw the waveforms
for( int i = 0; i < out.bufferSize() - 1; i++ )
{
// find the x position of each buffer value
float x1 = map( i, 0, out.bufferSize(), 0, width );
float x2 = map( i+1, 0, out.bufferSize(), 0, width );
// draw a line from one buffer position to the next for both channels
line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
}
}
}
void stop()
{
// always close Minim audio classes when you are done with them
out.close();
// always stop Minim before exiting.
minim.stop();
super.stop();
}
it is a work in progress, i am just experimenting with examples, provided with library.
1