// Split out channels from sample
int h = 0;
for (int i = 0; i < CaptureData.Length; i += 4)
{
_waveLeft[h] = (double)BitConverter.ToInt16(CaptureData, i);
_waveRight[h] = (double)BitConverter.ToInt16(CaptureData, i + 2);
h++;
}
double sum = 0;
foreach (double item in _waveLeft)
{
if (item > 0)
sum += item;
else
sum += -item;
}
int result = (int)(((sum / _waveLeft.Length)) / 32768 * 100);
if (state == State.Starting||state == State.Started)
{
secondBuffer.Add(CaptureData);
}
OnVolumeChanged(new OnVolumeChangedEventArgs(result));
if (state == State.Started)
{
if (result < accuracy)
{
silence++;
if (silence > 10)
{
silence = 0;
SwitchState(State.Paused);
}
}
}
else if (state == State.Paused)
{
if (result > accuracy)
{
silence = 0;
secondBuffer = new List<byte[]>();
int n = _thirdBuffer.Count;
for (int i = 0; i < n; i++)
{
secondBuffer.Add(_thirdBuffer.Dequeue());
}
secondBuffer.Add(CaptureData);
SwitchState(State.Started);
}
}
if (_thirdBuffer.Count <= _THIRD_BUFFER_SIZE)
{
_thirdBuffer.Enqueue(CaptureData);
}
else
{
_thirdBuffer.Enqueue(CaptureData);
_thirdBuffer.Dequeue();
}
}
第二个读buffer,然后用公式换算成电平值