Question by
falzona · Mar 12, 2018 at 01:38 PM ·
microphonepitch
unity microphone pitch detection
Hi, im trying to read the microphone input, and obtain the pitch of the input. i cant seem to understand how it is done, can any one help me? currently i am using the loudness of the input.
AudioClip clip = new AudioClip();
int sample = 128;
float Loudness = 0;
//get data from microphone into audioclip
float maxLoud()
{
float[] soundData = new float[sample];
//when using null the default mic will be chosen
int micPosition = Microphone.GetPosition(null) - (sample + 1);
if (micPosition < 0)
return 0;
clip.GetData(soundData, micPosition);
// peak on the last X amount samples
for (int i = 0; i < sample; i++)
{
float peak = soundData[i] * soundData[i];
if (Loudness < peak)
{
Loudness = peak;
}
}
return Loudness;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612154426im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mic record on button click 1 Answer
I want to acquire by not default recording device. 0 Answers
Microphone sound convert to OGG 0 Answers