int offset = 0; class MyTable implements AudioSignal { int high; int low; int count = 0; int pos; boolean start = true; int amp = 0; void generate(float[] samp) { for (int x = 0; x < samp.length; x++) { for(int y=0;y<100;y++) { pos = x * 100 + y; color c = img.get(x, y); if(red(c)<=50) { imgArray[pos] = pos; } else { imgArray[pos] = 0; } sndArray[y] = imgArray[pos]; } high = sndArray[0]; for(int i=0;i<100;i++) { if(sndArray[i]>0 && start) { low = sndArray[i]; start = !start; } else if(sndArray[i]==0 && start) { offset++; } if(sndArray[i]>high) { high = sndArray[i]; } } if(high>0 && low>0) { amp = high-low+offset; if(x%2==1) { //top edge samp[x] = map(offset, 1, 100, 1, 0); } else { //bottom edge samp[x] = map(amp, 1, 100, 1, 0); } } else { amp = 0; samp[x] = amp; } start = !start; offset = 0; } } // this is a stricly mono signal void generate(float[] left, float[] right) { generate(left); generate(right); } }