import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import ddf.minim.analysis.*; Minim minim; FFT fft; //FFT class 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), "Frequency[Hz]", "Output[dB]"); minim = new Minim(this); //Minim initialize player = minim.loadFile("sin.wav", 512); //Audio input from file fft = new FFT(player.bufferSize(), player.sampleRate()); //FFT initialize fft.window(FFT.HAMMING); //FFT window setting data = new float[fft.specSize()]; } void draw() { fft.forward(player.mix); //FFT Analyze //make Graph for (int i = 0; i < fft.specSize(); i++) { data[i] = fft.getBand(i); } tG.graphArrayDraw(data,"L", 5); } 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