I am trying to implement a system so that it retrieves sound and extracts the mfcc of it. I'd like to implement my own mfcc function because librosa library wasn't implemented in C and other implementations of mfcc extractions doesn't yield the same outputs as librosa library does. So I wrote a code, however, when I would like create hanning window, program doesn't take a step further and always stays the same statement while debugging. The statement is below:
float *mul = malloc(sizeof(float)*fftsize);
The whole code is as follows:
float* hanning(int fftsize){
float *mul = malloc(sizeof(float)*fftsize);
for (int i = 0; i<fftsize; i++){
mul[i] = 0.5 * (1 - cos(2*PI*i/(fftsize-1)));
}
return mul;
}
I put an LCD code to all error handler functions in stm32f7xx_it.c file to determine which fault I'm facing, and I see that it is hard_fault.
So what's the problem? I hope the issue is explained clearly. Due to the privacy, I couldn't put here whole code. Sorry for that. Thx in advance for your response.
Edit: I am chaning malloc to normal array with a variable length array. But still it takes me to HardFault_Handler function. SCB->SHCSR returns sometimes 65535 and sometimes 1.
fftsize. It is I'll advised to hide an allocation in a function and free elsewhere. Better to pass a buffer intohanning().fftsizeon its own is no justification for dynamic memory allocation if the maximumfftsizeis known. The only advantage of using the heap is that that space can be reused for other purposes at runtime. If you are not doing that and this is the only allocation from heap, you may as well simply allocate anFFTSIZE_MAXbuffer statically since you would in any event need a heap of more thanFFTSIZE_MAX * sizeof(float)in any case.mallocis not a magic memory tree, the heap itself is statically allocated (in this case).