0

Hey, I have a function in C that I am trying to convert over to C++. I have done everything, apart from this line:

```
memcpy(mel[i],&temp[melstart[i]],mellength[i]*sizeof(double));
```

I need a way of copying the elements in temp[melstart[i]] over to a vector of doubles..

Here is the C code:

```
void Setup_Mel(int fft_size, int sample_rate) {
int i,j,k,tap;
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 (i=0; i<16; i++) {
melstart[i]=fft_size/2;
mellength[i]=0;
memset(temp,0,sizeof(double)*fft_size/2);
for (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] = malloc(sizeof(double)*mellength[i]);
memcpy(mel[i],&temp[melstart[i]],mellength[i]*sizeof(double));
printf("%f\n", temp[melstart[i]]);
for(k=0; (k < mellength[i]); k++)
{
//printf("%f\n", mel[i][k]);
}
// for (k=0; k<mellength[i]; tap++,k++) printf("mel filter: %d, %d, %d, %f, %f\n",i,melstart[i]+k,tap,mel[i][k],(melstart[i]+k)*freq);
}
}
```

And the C++ function I'm working on:

```
void setUp_Mel(int fft_size, int sample_rate, vector< vector< double > > &mel, int *melstart, int *mellength)
{
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 < 16); 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].resize(mellength[i]);
mel[i].assign(temp[melstart[0]], temp[melstart[0]] + mellength[i]);
for(int k=0; (k < mellength[i]); k++)
{
cout << mel[i][k] << endl;
}
//mel[i].assign(temp[melstart[i]], temp[melstart[i]] + mellength[i]);
//cout << temp[melstart[i]] << endl;
}
}
```

This throws up an error. Sorry there is a lot of code, but, the problem should be simple.. I just cannot figure it out. Thanks guys