AutoCorrelation.java (1563B)
1 /* 2 * _______ _____ _____ _____ 3 * |__ __| | __ \ / ____| __ \ 4 * | | __ _ _ __ ___ ___ ___| | | | (___ | |__) | 5 * | |/ _` | '__/ __|/ _ \/ __| | | |\___ \| ___/ 6 * | | (_| | | \__ \ (_) \__ \ |__| |____) | | 7 * |_|\__,_|_| |___/\___/|___/_____/|_____/|_| 8 * 9 * ------------------------------------------------------------- 10 * 11 * TarsosDSP is developed by Joren Six at IPEM, University Ghent 12 * 13 * ------------------------------------------------------------- 14 * 15 * Info: http://0110.be/tag/TarsosDSP 16 * Github: https://github.com/JorenSix/TarsosDSP 17 * Releases: http://0110.be/releases/TarsosDSP/ 18 * 19 * TarsosDSP includes modified source code by various authors, 20 * for credits and info, see README. 21 * 22 */ 23 24 package be.tarsos.dsp; 25 26 public class AutoCorrelation implements AudioProcessor { 27 28 private float result; 29 30 public AutoCorrelation(){ 31 } 32 33 @Override 34 public boolean process(AudioEvent audioEvent) { 35 float[] audioFloatbuffer = audioEvent.getFloatBuffer(); 36 37 result = 0; 38 39 for (int i=0; i<audioFloatbuffer.length; i++){ 40 result += ((float)Math.abs(audioFloatbuffer[i]))/(float)audioFloatbuffer.length; 41 } 42 return true; 43 } 44 45 @Override 46 public void processingFinished() { 47 } 48 49 public float[] getValues() { 50 float[] returnValue = new float[1]; 51 returnValue[0] = result; 52 return returnValue; 53 } 54 }