evolcdc
YaBB Newbies
Offline
Posts: 5
Minim reading lines from image
Jan 21st , 2008, 9:28am
I am trying to assemble the pieces to create a synth that "plays" the vertical lines of pixels from an image. Can Minim handle 400 addSignals? is there a better way to go about this? Thanks in advance! import ddf.minim.*; import ddf.minim.signals.*; AudioOutput sound; MuzikMaker[] muzik = new MuzikMaker[400]; PImage file; int[][] pixel; float[] redC, greenC, blueC; int x = 0; void setup() { size(600, 400); Minim.start(this); frameRate(10); sound = Minim.getLineOut(Minim.STEREO, 512); for (int m=0; m < height; m++) { muzik[m] = new MuzikMaker(); muzik[m].update(m); sound.addSignal(muzik[m]); } pixel = new int[width][height]; file = loadImage("mountain.jpg"); for(int i=0; i<width; i++) { for(int j=0; j<height; j++) { pixel[i][j] = file.pixels[i + width*j]; } } } void draw() { image(file, 0, 0); for(int i = 0; i<height; i++){ redC[i] = red(pixel[500][i]); greenC[i] = green(pixel[500][i]); blueC[i] = blue(pixel[500][i]); println(redC[i]); println(greenC[i]); println(blueC[i]); // x ++; } } class MuzikMaker implements AudioSignal { int xcode; void update(int xtemp) { xcode = xtemp; } void generate(float[] samp) { float range = map(redC[xcode], 0, 255, 0, 1); float peaks = map(blueC[xcode], 0, 255, 1, 20); float inter = float(samp.length) / peaks; for ( int i = 0; i < samp.length; i += inter ) { for ( int j = 0; j < inter && (i+j) < samp.length; j++ ) { samp[i + j] = map(j, 0, inter, -range, range); } } } // this is a stricly mono signal void generate(float[] left, float[] right) { generate(left); generate(right); } } void stop() { // always closes audio I/O classes sound.close(); super.stop(); }