Skip to content

Instantly share code, notes, and snippets.

@namitts82
Created December 6, 2017 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namitts82/1b1556350d60188f0c3f4ba171eb0e1a to your computer and use it in GitHub Desktop.
Save namitts82/1b1556350d60188f0c3f4ba171eb0e1a to your computer and use it in GitHub Desktop.
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