//Variance import ddf.minim.*; import ddf.minim.analysis.*; Minim minim; AudioPlayer player; // Minim class D2Graph tG; float[] data; //data Array float r = 0.75; // scale for view window void setup() { size(600, 400, P3D); background(255); tG = new D2Graph(int(width*r), int(height*r), "Time[S]", "Output[dB]"); minim = new Minim(this); //Minim initialize player = minim.loadFile("drumbeat.mp3", 512); //Audio input from file data = new float[player.bufferSize()]; } void draw() { //make Graph int ysp = int((height-height*r)/2); for (int i = 0; i < player.bufferSize() - 1; i++) { data[i] = map(player.mix.get(i), -1, 1, 0, (height/2+2*ysp)); } tG.graphArrayDraw(data, "P", 1); } void mousePressed() { player.rewind(); //Sound set to Start player.play(); //Sound play } void stop() { player.close(); minim.stop(); super.stop(); } class D2Graph { int X_LENGTH, Y_LENGTH; String X_LABEL, Y_LABEL; float[] y; //data float maxRange; int xsp, ysp; //space x, y D2Graph(int _X_LENGTH, int _Y_LENGTH, String xL, String yL) { X_LENGTH = _X_LENGTH; Y_LENGTH = _Y_LENGTH; X_LABEL = xL; Y_LABEL = yL; xsp = int((width-X_LENGTH)/2); ysp = int((height-Y_LENGTH)/2); y = new float[X_LENGTH]; for (int i = 0; i < X_LENGTH; i++) { y[i] = 0; } maxRange = 1; labels(); } void graphPointDraw(float _y) { y[X_LENGTH - 1] = _y; for (int i = 0; i < X_LENGTH - 1; i++) { y[i] = y[i + 1]; } for (int i=0; i maxRange ? abs(y[i]) : maxRange); } pushMatrix(); { clear(); translate(xsp, Y_LENGTH/2+ysp); scale(1, -1); strokeWeight(1); for (int i=0; i maxRange ? abs(y[i]) : maxRange); } clear(); translate(xsp, Y_LENGTH/2+ysp); scale(1, -1); strokeWeight(1); for (int i=0; i