void FFT_Task(void *arg)
{
static int8_t i2s_readraw_buff[1024];
size_t bytesread;
int16_t *buffptr;
int16_t *samples_sc16 = (int16_t *)i2s_readraw_buff;
float *samples_fc32 = (float *)calloc(SAMPLES_NUM, sizeof(float));
double data = 0;
i2s_init();
while (1)
{
if (fft_en == 1)
{
i2s_read(I2S_NUM_0, (char *)i2s_readraw_buff, SAMPLES_NUM * 2, &bytesread, (100 / portTICK_RATE_MS));
fft_config_t *real_fft_plan = fft_init(512, FFT_REAL, FFT_FORWARD, NULL, NULL);
buffptr = (int16_t *)i2s_readraw_buff;
for (uint16_t count_n = 0; count_n < real_fft_plan->size; count_n++)
{
real_fft_plan->input[count_n] = (float)map(buffptr[count_n], INT16_MIN, INT16_MAX, -1000, 1000);
}
fft_execute(real_fft_plan);
for (uint16_t count_n = 1; count_n < CANVAS_HEIGHT; count_n++)
{
data = sqrt(real_fft_plan->output[2 * count_n] * real_fft_plan->output[2 * count_n] + real_fft_plan->output[2 * count_n + 1] * real_fft_plan->output[2 * count_n + 1]);
fft_dis_buff[CANVAS_HEIGHT - count_n] = map(data, 0, 2000, 0, CANVAS_HEIGHT);
}
fft_destroy(real_fft_plan);
for (uint16_t count_y = 0; count_y < CANVAS_HEIGHT;)
{
lv_chart_set_next(chart_fft, series_fft, fft_dis_buff[count_y]);
count_y += 5;
}
}
else
{
i2s_driver_uninstall(I2S_NUM_0);
vTaskDelete(NULL);
}
}
}