Hello everyone.
I am trying to do some FFT on maple_mini with the kiss_fft.
The program always failes to malloc(1024*sizeof(float)),
while the maple mini has 20KB of RAM. Why?
Here is the code:
#include <math.h>
#include <stdlib.h>
#include <wirish/wirish.h>
#include "kiss_fftr.h"
#define BUF_SIZE 1024
void setup(void) {
pinMode(BOARD_LED_PIN, OUTPUT);
SerialUSB.begin();
pinMode(BOARD_BUTTON_PIN, INPUT);
while(!isButtonPressed()){
toggleLED();
delay(200);
}
kiss_fftr_cfg mycfg = kiss_fftr_alloc(BUF_SIZE, 0, NULL, NULL);
kiss_fft_scalar * rin =(kiss_fft_scalar*) malloc(BUF_SIZE * sizeof(kiss_fft_scalar));
kiss_fft_cpx * fout = (kiss_fft_cpx*) malloc((BUF_SIZE/2+1) * sizeof(kiss_fft_cpx));
if(mycfg == NULL ){
SerialUSB.println("mycfg failed.");
return;
}
if(rin == NULL){
SerialUSB.println("rin failed.");
return;
}
if(fout == NULL){
SerialUSB.println("fout failed.");
return;
}
SerialUSB.println("allocations OK.");
for(int i=0;i<BUF_SIZE;i++){
rin[i] = sin((float)i/20.0f) + 0.5*cos((float)i/30.0f);
}
unsigned long t0, t1;
t0 = micros();
kiss_fftr(mycfg, rin, fout);
t1 = micros();
SerialUSB.println(t1 - t0);
kiss_fftr_free(mycfg);
free(rin);
free(fout);
}
void loop(void) {
digitalWrite(BOARD_LED_PIN, HIGH);
delay(50);
digitalWrite(BOARD_LED_PIN, LOW);
delay(800);
}
__attribute__((constructor)) void premain() {
init();
}
int main(void) {
setup();
while (true) {
loop();
}
return 0;
}