in Scripts/Runtime/Lib/Mic.cs [272:320]
IEnumerator ReadRawAudio()
{
int loops = 0;
int readAbsPos = Microphone.GetPosition(CurrentDeviceName);
int prevPos = readAbsPos;
float[] temp = new float[Sample.Length];
while (AudioClip != null && Microphone.IsRecording(CurrentDeviceName) && IsRecording)
{
bool isNewDataAvailable = true;
while (isNewDataAvailable && AudioClip)
{
int currPos = Microphone.GetPosition(CurrentDeviceName);
if (currPos < prevPos)
loops++;
prevPos = currPos;
var currAbsPos = loops * AudioClip.samples + currPos;
var nextReadAbsPos = readAbsPos + temp.Length;
float levelMax = 0;
if (nextReadAbsPos < currAbsPos)
{
AudioClip.GetData(temp, readAbsPos % AudioClip.samples);
for (int i = 0; i < temp.Length; i++)
{
float wavePeak = temp[i] * temp[i];
if (levelMax < wavePeak)
{
levelMax = wavePeak;
}
}
Sample = temp;
m_SampleCount++;
OnSampleReady?.Invoke(m_SampleCount, Sample, levelMax);
readAbsPos = nextReadAbsPos;
isNewDataAvailable = true;
}
else
isNewDataAvailable = false;
}
yield return null;
}
}