Instantly share code, notes, and snippets.

Embed
What would you like to do?
private float AnalyzeSound()
{
float[] samples = new float[1024];
this.audioSource.GetOutputData(samples, 0); // fill array with samples
float sum = 0;
for (int i = 0; i < 1024; i++)
{
sum += samples[i] * samples[i]; // sum squared samples
}
return Mathf.Sqrt(sum / 1024); // rms = square root of average
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment