class BeatZone{ FFT fft; AudioInput in; float [] zone; float [] threshold; int [] zoneStart; int [] zoneEnd; boolean [] beat; float decay = 0.005; BeatZone(FFT fft, AudioInput in, int numZone){ this.fft = fft; this.in = in; zone = new float[numZone]; threshold = new float[numZone]; zoneStart = new int[numZone]; zoneEnd = new int[numZone]; beat = new boolean[numZone]; } void read(){ for(int i = 0; i < zone.length; i++){ zone[i] = 0.0; beat[i] = false; for(int j = zoneStart[i]; j < zoneEnd[i]; j++){ zone[i] += fft.spectrum[j]; } zone[i] /= zoneEnd[i] - zoneStart[i]; if(zone[i] > threshold[i]){ threshold[i] = zone[i]; beat[i] = true; } else { threshold[i] = threshold[i] > 0.0 ? threshold[i] - decay : 0.0; } } } void setZone(int num, int start, int end){ zoneStart[num] = start; zoneEnd[num] = end; } }