我遇到了一段代码的问题。我在 C 程序中有这一行:
mel[i] = malloc(sizeof(double)*mellength[i]);
在哪里:
double *mel[16];
int mellength[16];
我需要在 C++ 中执行此操作,但是我使用的是“new”运算符:
mel[i] = new double(sizeof(double)*mellength[i]);
在哪里:
int *mellength = new int[16];
double *mel = new double[16];
我收到以下错误:
错误:无法在赋值中将 'double*' 转换为 'double'
完整功能:
void setup_Mel(int fft_size, int sample_rate, int *melstart, int *mellength, double *mel)
{
double fmax;
double dphi;
double fsample;
double freq;
double temp[fft_size/2];
fmax=2595*log10(8000.0f/700+1);
dphi = fmax/17;
freq = (double)sample_rate/fft_size;
for(int i=0; (i < 13); i++)
{
melstart[i] = fft_size/2;
mellength[i] = 0;
memset(temp, 0, sizeof(double)*fft_size/2);
for(int j=0; (j < fft_size/2); j++)
{
fsample = 2595*log10(freq*j/700 + 1);
if((dphi * i <= fsample) && (fsample < dphi*(i+1)))
{
temp[j] = (fsample-dphi*i)/(dphi*(i+1)-dphi*i);
}
if ((dphi*(i+1) <= fsample) && (fsample < dphi*(i+2)))
{
temp[j] = (fsample-dphi*(i+2))/(dphi*(i+1)-dphi*(i+2));
}
if ((temp[j] != 0) && (melstart[i] > j))
{
melstart[i] = j;
}
if (temp[j] != 0) mellength[i]++;
}
mel[i] = new double(sizeof(double)*mellength[i]);
}
}
希望有人可以提供帮助:)