0

私はこれにかなり慣れていないので、できる限り説明しようと思います。オーディオ レベルが特定のレベルを超えた回数をカウントしたい。レベルが特定のしきい値を超えたかどうかを検出できるコードを見つけて作成しましたが、そのしきい値を確実に超えた回数をカウントする方法がわかりません。音/ノイズは、マイクに接続されているスイッチによって作成されており、スイッチが切り替わるたびに、切り替えによってノイズが作成されます。ある種のフィルタリングを使用する必要がありますか?

C#.net ナウディオ ライブラリ スティーブ。

    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;
    }
4

1 に答える 1