开发者

Autocorrelation method for pitch determination: what is the input data form?

I have read a code for pitch determination using autocorrelation method. Can anybody please tell what would be the input data (passed as argument to DetectPitch()) function here:

double DetectPitch(short* data)
{
    int sampleRate = 2048;

    //Create sine wave
    double *buffer = malloc(1024*sizeof(short));
    double amplitude = 0.25 * 32768; //0.25 * max length of short
    double frequency = 726.0;
    for (int n = 0; n < 1024; n++)
    {
        buffer[开发者_C百科n] = (short)(amplitude * sin((2 * 3.14159265 * n * frequency) / sampleRate));
    }

    doHighPassFilter(data);

    printf("Pitch from sine wave: %f\n",detectPitchCalculation(buffer, 50.0, 1000.0, 1, 1));
    printf("Pitch from mic: %f\n",detectPitchCalculation(data, 50.0, 1000.0, 1, 1));
    return 0;
}


It seems that "data" is used exactly the same way as the locally allocated "buffer", so I suppose it's something like short data[1024], i.e. 1024 signal samples between -32768 and 32767 (the way "amplitude" is calculated makes suppose that the "short" type is 16 bit here). By the way, as "max length of short" (as the comment says) I would expect 32767, not 32768 (there is a theoretical overflow with maximum positive values).

Regards


It looks like you need to at least change:

double *buffer = malloc(1024*sizeof(short));

to:

short *buffer = malloc(1024*sizeof(short));

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜