我很新,所以我會盡力解釋。 我想統計音頻電平超過特定電平的次數。我發現/創建了一些代碼,可以檢測到該級別是否超過了某個閾值,但無法確定如何可靠地計算出超過該閾值的次數。聲音/噪音是由連接到麥克風的開關產生的,每次切換噪音都是由切換產生的。我需要使用某種過濾嗎?Naudio - 計數音頻電平上升到一個水平
C#.NET n音訊庫 史蒂夫。
public void StartListening()
{
WaveIn waveInStream = new WaveIn();
waveInStream.BufferMilliseconds = 500;
waveInStream.DataAvailable += new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
waveInStream.StartRecording();
}
//Handler for the sound listener
private void waveInStream_DataAvailable(object sender, WaveInEventArgs e)
{
bool result = ProcessData(e);
if (result)
{
intCounter++;
label1.Text = intCounter.ToString();
}
else
{
//no peak in sound
}
}
//calculate the sound level based on the AudioThresh
private bool ProcessData(WaveInEventArgs e)
{
bool result = false;
bool Tr = false;
double Sum2 = 0;
int Count = e.BytesRecorded/2;
for (int index = 0; index < e.BytesRecorded; index += 2)
{
double Tmp = (short)((e.Buffer[index + 1] << 8) | e.Buffer[index + 0]);
Tmp /= 32768.0;
Sum2 += Tmp * Tmp;
if (Tmp > AudioThresh)
Tr = true;
}
Sum2 /= Count;
// If the Mean-Square is greater than a threshold, set a flag to indicate that noise has happened
if (Sum2 > AudioThresh)
{
result = true;
}
else
{
result = false;
}
return result;
}
這個問題應該與編程有關,你應該更具體。 – mor