开发者

Programmatically detect and extract an audio envelope

All suggestions and links to relevant info welcome here. This is the scenario:

Let us say I have a .wav file of someone speaking (and therefore all the samples associated with it).

开发者_运维问答

I would like to run an algorithm on the series of samples to detect when an event happens i.e. the beginning and the end of an envelope. I would then use this starting and end point to extract that data to be used elsewhere.

What would be the best way to tackle this? Any pseudocode? Example code? Source code?

I will eventually be writing this in C.

Thanks!


EDIT 1

Parsing the wav file is not a problem. But some pseudo-code for the envelope detection would be nice! :)


The usual method is:

  1. take absolute value of waveform, abs(x[t])
  2. low pass filter (say 10 Hz cut-off)
  3. apply threshold


You could use the same method as an old fashioned analog meter. Rectify the sample vector, pass the absolute value result though a low pass filter (FIR, IIR, moving average, etc.), than compare against some threshold. For a more accurate event time, you will have to subtract the group delay time of the low pass filter.

Added: You might also need to remove DC beforehand (say with a high-pass filter or other DC blocker equivalent to capacitive coupling).


Source code of simple envelope detectors can be found in the Music-DSP Source Code Archive.


I have written an activity detector class in Java. It's part of my open-source Java DSP collection.


first order low pass filter C# Code:

    double old_y = 0;

    double R1Filter(double x, double rct)
    {
        if (rct == 0.0)
            return 0;
        if (x > old_y)
            old_y = old_y-(old_y - x)*rct/256;
        else
            old_y = old_y + (x - old_y) * rct/256;
        return old_y;
    }

When rct=2, it works like this:

Programmatically detect and extract an audio envelope

The signal = (ucm + ucm * ma * Cos(big_omega * x)) * (Cos(small_omega1 * x) + Cos(small_omega2 * x) ) where ucm=3,big_omega=200,small_omega1=4,small_omega2=12 and ma=0.8

Pay attention that the filter may change the phase of the base band signal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜