Note that there are some explanatory texts on larger screens.

plurals
  1. PONaudio - Count the times audio level rises above a level
    primarykey
    data
    text
    <p>I'm pretty new to this so I'll try to explain as best I can. I want to count the number of times the audio level goes above a certain level. I have found/created some code which can detect if the level has gone above a certain threshold, but can't figure out how to count the number of times it has risen above that threshold reliably. the sound/noise is being created by a switch which is connected to the microphone, every time it switches a noise is created by the switching. Do I need to use some sort of filtering?</p> <p>C#.net Naudio Library Steve.</p> <pre><code> public void StartListening() { WaveIn waveInStream = new WaveIn(); waveInStream.BufferMilliseconds = 500; waveInStream.DataAvailable += new EventHandler&lt;WaveInEventArgs&gt;(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 &lt; e.BytesRecorded; index += 2) { double Tmp = (short)((e.Buffer[index + 1] &lt;&lt; 8) | e.Buffer[index + 0]); Tmp /= 32768.0; Sum2 += Tmp * Tmp; if (Tmp &gt; 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 &gt; AudioThresh) { result = true; } else { result = false; } return result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload