malloc max_fft_size memory

dev
xufulong 3 years ago
parent 92f1800c43
commit 1b61ad59ed
  1. 7
      app/src/main/cpp/audio_player.cpp
  2. 20
      app/src/main/cpp/visualizer/execute_fft.cpp
  3. 3
      app/src/main/cpp/visualizer/execute_fft.h

@ -309,9 +309,10 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
}
if (got_frame > 0) {
ret = ensure_memory(fft_filter, frame->nb_samples);
if (ret == 0 && fft_filter->nb_samples == frame->nb_samples) {
memcpy(fft_filter->data, frame->data[0], static_cast<size_t>(frame->nb_samples));
int nb_samples = frame->nb_samples < MAX_FFT_SIZE ? frame->nb_samples : MAX_FFT_SIZE;
if (nb_samples >= MIN_FFT_SIZE) {
fft_filter->nb_samples = nb_samples;
memcpy(fft_filter->data, frame->data[0], nb_samples);
fft_once(fft_filter);
fft_callback(env, thiz, fft_method, fft_filter->output, fft_filter->out_samples);
}

@ -207,6 +207,8 @@ int init_visualizer(filter_sys_t *p_filter)
p_filter->out_samples = FFT_BUFFER_SIZE;
#endif
p_filter->output = (int8_t *) (malloc(p_filter->out_samples * sizeof(int8_t)));
p_filter->data_size = MAX_FFT_SIZE;
p_filter->data = (uint8_t *) (malloc(MAX_FFT_SIZE * sizeof(uint8_t)));
return 0;
}
@ -226,24 +228,6 @@ void release_visualizer(filter_sys_t *p_filter)
free(p_filter);
}
int ensure_memory(filter_sys_t *fft_filter, int nb_samples) {
if (nb_samples < MIN_FFT_SIZE) {
return -1;
}
if (nb_samples != fft_filter->nb_samples) {
if (!fft_filter->data) {
fft_filter->data_size = nb_samples;
fft_filter->data = (uint8_t *) (malloc(nb_samples * sizeof(uint8_t)));
} else if (nb_samples > fft_filter->data_size) {
fft_filter->data_size = nb_samples;
fft_filter->data = (uint8_t *) (realloc(fft_filter->data, nb_samples * sizeof(uint8_t)));
}
if (!fft_filter->data) return -1;
fft_filter->nb_samples = nb_samples;
}
return 0;
}
void fft_float(filter_sys_t *p_sys)
{
int nb_samples = p_sys->nb_samples;

@ -18,6 +18,7 @@ extern "C" {
#include "block_queue.h"
#define MIN_FFT_SIZE 128
#define MAX_FFT_SIZE 1024
#define FIXED_FFT 1
@ -54,8 +55,6 @@ int init_visualizer(filter_sys_t *p_sys);
void release_visualizer(filter_sys_t *p_sys);
int ensure_memory(filter_sys_t *fft_filter, int nb_samples);
void fft_float(filter_sys_t *p_sys);
void fft_fixed(filter_sys_t *p_sys);

Loading…
Cancel
Save