I am using this onset source code and this fft file to try to perform onset detection. Currently the code is working, but as my DSP and C skills are subpar I could use some advice on how to improve it.
My main points of insecurity are the FFT (maybe there is a more suitable method out there?) and the C code. All advice appreciated!
NB: This code will eventually being going into iPhone project.
OnsetsDS *ods = malloc(sizeof *ods);
float* odsdata = (float*) malloc(onsetsds_memneeded(ODS_ODF_RCOMPLEX, 512, 11));
onsetsds_init(ods, odsdata, ODS_FFT_FFTW3_HC, ODS_ODF_RCOMPLEX, 512, 11, 44100);
int i;
int x;
double (*vocalData)[2] = malloc(2 * 512 * sizeof(double));
double (*doubleFFTData)[2] = malloc(2 * 512 * sizeof(double));
for (i = 0; i < vocalBuffer.numFrames; i=i+512){
bool onset;
for (x = 0; x < 512; x++){
*vocalData[x] = (double)vocalBuffer.buffer[i+x];
}
fft(512, vocalData, doubleFFTData);
float *floatFFTData = malloc(512 * sizeof(float));
int z;
for (z = 0; z < 512; z++){
floatFFTData[z] = (float)*doubleFFTData[z];
}
onset = onsetsds_process(ods, floatFFTData);
if (onset){
printf("onset --> %i\n", i);
}
}
free(ods->data); // Or free(odsdata), they point to the same thing in this case
return nil;