public static void main(String[] argv) throws Exception {
		MP3Decoder decoder = new MP3Decoder(new FileInputStream(FILE));
		FFT fft = new FFT(1024, 44100);
		fft.window(FFT.HAMMING);
		float[] samples = new float[1024];
		float[] spectrum = new float[1024 / 2 + 1];
		float[] lastSpectrum = new float[1024 / 2 + 1];
		
		//for each spectrum we calculate the difference to the spectrum of the 
		//sample window before the current spectrum. 
		//That’s it. What we get is a single number that tells us the 
		//absolute difference between the bin values of the current 
		//spectrum and the bin values of the last spectrum.
		ArrayList<Float> spectralFlux = new ArrayList<Float>();

		ArrayList<Float> threshold = new ArrayList<Float>();

		while (decoder.readSamples(samples) > 0) {
			fft.forward(samples);
			System.arraycopy(spectrum, 0, lastSpectrum, 0, spectrum.length);
			System
					.arraycopy(fft.getSpectrum(), 0, spectrum, 0,
							spectrum.length);

			float flux = 0;
			for (int i = 0; i < spectrum.length; i++) {
				float value = (spectrum[i] - lastSpectrum[i]);
				flux += value < 0 ? 0 : value;
			}
			spectralFlux.add(flux);
		}

		for (int i = 0; i < spectralFlux.size(); i++) {
			int start = Math.max(0, i - THRESHOLD_WINDOW_SIZE);
			int end = Math.min(spectralFlux.size() - 1, i
					+ THRESHOLD_WINDOW_SIZE);
			float mean = 0;
			for (int j = start; j <= end; j++)
				mean += spectralFlux.get(j);
			mean /= (end - start);
			threshold.add(mean * MULTIPLIER);
		}

		// Escolho apenas aqueles maiores q o treshold
		ArrayList<Float> prunnedSpectralFlux = new ArrayList<Float>();
		for (int i = 0; i < threshold.size(); i++) {
			if (threshold.get(i) <= spectralFlux.get(i))
				prunnedSpectralFlux.add(spectralFlux.get(i) - threshold.get(i));
			else
				prunnedSpectralFlux.add((float) 0);
		}

		// A Peak is a value that is bigger then the next value.
		ArrayList<Float> peaks = new ArrayList<Float>();
		for (int i = 0; i < prunnedSpectralFlux.size() - 1; i++) {
			if (prunnedSpectralFlux.get(i) > prunnedSpectralFlux.get(i + 1))
				peaks.add(prunnedSpectralFlux.get(i));
			else
				peaks.add((float) 0);
		}

		Plot plot = new Plot("Peaks", 1024, 512);
		//plot.plot(spectralFlux, 1, Color.red);
		//plot.plot(threshold, 1, Color.green);
		//plot.plot(prunnedSpectralFlux, 1, Color.blue);
		plot.plot(peaks, 1, Color.yellow);
		new PlaybackPlot(plot, 1024, new MP3Decoder(new FileInputStream(
				FILE)));

	}