我已经阅读了使用自相关方法确定音高的代码。任何人都可以在这里告诉输入数据是什么(作为参数传递给DetectPitch())函数:
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[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;
}
答案 0 :(得分:2)
看起来你至少需要改变:
double *buffer = malloc(1024*sizeof(short));
为:
short *buffer = malloc(1024*sizeof(short));
答案 1 :(得分:2)
似乎“数据”的使用方式与本地分配的“缓冲区”完全相同,所以我想它就像是
short data[1024]
,即在-32768和32767之间的1024个信号样本(计算“幅度”的方式使得假设“短”类型在这里是16位)。
顺便说一句,作为“最短的短期”(正如评论所说),我期望32767,而不是32768(理论溢出有最大正值)。
此致