Created
December 6, 2017 22:13
-
-
Save namitts82/1b1556350d60188f0c3f4ba171eb0e1a to your computer and use it in GitHub Desktop.
This file contains 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
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