anyone know why this is crashing right when it should loop?
import processing.sound.*;
// Declare the processing sound variables
SoundFile sample;
Amplitude rms;
// Declare a scaling factor
float scale=1;
// Declare a smooth factor
float smooth_factor=0.25;
// Used for smoothing
float sum;
PImage img; // The source image
int cellsize = 2; // Dimensions of each cell in the grid
int columns, rows; // Number of columns and rows in our system
public void setup() {
size(800, 1000, P3D);
//fullScreen(P3D);
img = loadImage("..."); // Load the image
columns = img.width / cellsize; // Calculate # of columns
rows = img.height / cellsize; // Calculate # of rows
//Load and play a soundfile and loop it
sample = new SoundFile(this, "...");
sample.loop();
// Create and patch the rms tracker
rms = new Amplitude(this);
rms.input(sample);
}
void draw() {
background(255,0,255);
// Begin loop for columns
for ( int i = 0; i < columns; i++) {
// Begin loop for rows
for ( int j = 0; j < rows; j++) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*img.width; // Pixel array location
color c = img.pixels[loc]; // Grab the color
// Calculate a z position as a function of mouseX and pixel brightness
//float z = width/2 * brightness(img.pixels[loc]) - 20.0;
float rms_scaled=sum*width/10 * brightness(img.pixels[loc]) - 20.0;
// smooth the rms data by smoothing factor
sum += (rms.analyze() - sum) * smooth_factor;
// rms.analyze() return a value between 0 and 1. It's
// scaled to height/2 and then multiplied by a scale factor
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
//translate(x + 300, y + 250, rms_scaled);
translate(x + 200, y + 200, rms_scaled);
fill(c, 204);
noStroke();
rectMode(CENTER);
rect(0, 0, cellsize, cellsize);
popMatrix();
}
}
}