Created
January 7, 2016 18:54
-
-
Save SageStarCodes/981bea7ea48c5784736b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.d3add3d.d3utils; | |
/** | |
* | |
* This is simple smoothing buffer I created for working with audio in Processing but it can be used for anything. | |
* | |
* @author D3add3d | |
* | |
*/ | |
public class SmoothingFloatBuffer { | |
private float[] buffer; | |
private float average; | |
private int pointer; | |
/** | |
* @param length Size of the buffer (recommended values for smoothing output from FFT.getAvg() are 3 to 10) | |
*/ | |
public SmoothingFloatBuffer(int length) { | |
buffer = new float[length]; | |
pointer = 0; | |
} | |
public float get() { | |
average = 0.0f; | |
for(int i = 0; i < buffer.length; i++){ | |
average += (float)buffer[i]; | |
} | |
average = average/buffer.length; | |
return average; | |
} | |
public void add(float number) { | |
buffer[pointer] = number; | |
if(pointer < buffer.length-1) { | |
pointer++; | |
} else { | |
pointer = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment