float[]samp_data=newfloat[buf_size];//Creates an array pre-allocated (We want it quite small to reduce latency, I made it tweakable from the inspector)
mic_source.clip.GetData(samp_data,0);//Stores all the output data into the array I pre-allocated
floatvol_sum=0;
for(inti=0;i<buf_size;i++){
for(inti=0;i<samp_size;i++){
vol_sum+=Mathf.Abs(samp_data[i]*samp_data[i]);//Calculates the square sum of all the data
}
rms=Mathf.Sqrt(vol_sum/buf_size)*100;//RMS value
rms=Mathf.Sqrt(vol_sum/samp_size)*100;//RMS value
vol=0;
if(!(vol<0))
...
...
@@ -61,66 +72,71 @@ public class AM : MonoBehaviour {
//Seperates the array in 3 from lowest pitch to Highest
//Low Pitch
floatlow_pitch_sum=0;//Inits a float to store the sum of all the index arrays
for(intspec_index=0;spec_index<5;spec_index++){
low_pitch_sum+=Mathf.Abs(spec_data[spec_index]*spec_data[spec_index]);//Only grabs the first Third values of the array (so the "low" pitch values) squared
low_pitch_sum+=Mathf.Abs(spec_data[spec_index]*spec_data[spec_index]);//Only grMathf.abs the first Third values of the array (so the "low" pitch values) squared
}
//Medium Pitch
floatmid_pitch_sum=0;//Inits a float to store the sum of all the index arrays
for(intspec_index=5;spec_index<30;spec_index++){
mid_pitch_sum+=Mathf.Abs(spec_data[spec_index]*spec_data[spec_index]);//Only grabs the second Third values of the array (so the "mid" pitch values) squared
mid_pitch_sum+=Mathf.Abs(spec_data[spec_index]*spec_data[spec_index]);//Only grMathf.abs the second Third values of the array (so the "mid" pitch values) squared
}
//High Pitch
floathigh_pitch_sum=0;//Inits a float to store the sum of all the index arrays
high_pitch_sum+=Mathf.Abs(spec_data[spec_index]*spec_data[spec_index]);//Only grabs the third Third values of the array (so the "high" pitch values) squared
high_pitch_sum+=Mathf.Abs(spec_data[spec_index]*spec_data[spec_index]);//Only grMathf.abs the third Third values of the array (so the "high" pitch values) squared