move param to struct

dev
xufulong 3 years ago
parent 54003bcb71
commit 61131656f8
  1. 12
      app/src/main/cpp/audio_player.cpp
  2. 13
      app/src/main/cpp/visualizer/execute_fft.c
  3. 5
      app/src/main/cpp/visualizer/execute_fft.h

@ -287,8 +287,6 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
auto *fft_filter = static_cast<filter_sys_t *>(malloc(sizeof(filter_sys_t)));
init_visualizer(fft_filter);
uint8_t *data = nullptr;
int nb_samples = 0;
auto *output = static_cast<int16_t *>(malloc(FFT_BUFFER_SIZE * sizeof(int16_t)));
//read audio frame
@ -313,12 +311,12 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
if (got_frame > 0) {
if (frame->nb_samples > 256) {
nb_samples = frame->nb_samples;
data = static_cast<uint8_t *>(malloc(frame->nb_samples * sizeof(uint8_t)));
fft_filter->nb_samples = frame->nb_samples;
fft_filter->data = static_cast<uint8_t *>(malloc(frame->nb_samples * sizeof(uint8_t)));
}
if (nb_samples == frame->nb_samples) {
memcpy(data, frame->data[0], static_cast<size_t>(frame->nb_samples));
fft_once(fft_filter, data, nb_samples, output);
if (fft_filter->nb_samples == frame->nb_samples) {
memcpy(fft_filter->data, frame->data[0], static_cast<size_t>(frame->nb_samples));
fft_once(fft_filter, output);
fft_callback(env, thiz, fft_method, output);
}

@ -203,14 +203,21 @@ int init_visualizer(filter_sys_t *p_sys)
void release_visualizer(filter_sys_t *p_filter)
{
filter_sys_t *p_sys = p_filter;
free(p_sys->p_prev_s16_buff);
if (!p_sys) return;
if (p_sys->p_prev_s16_buff) {
free(p_sys->p_prev_s16_buff);
}
free(&p_sys->wind_param);
if (p_sys->data) {
free(p_sys->data);
}
free(p_sys);
}
void fft_once(void *p_data, uint8_t *p_buffer, int nb_samples, int16_t *output)
void fft_once(void *p_data, int16_t *output)
{
filter_sys_t *p_sys = (filter_sys_t*)p_data;
int nb_samples = p_sys->nb_samples;
fft_state *p_state = NULL; /* internal FFT data */
DEFINE_WIND_CONTEXT(wind_ctx); /* internal window data */
@ -219,7 +226,7 @@ void fft_once(void *p_data, uint8_t *p_buffer, int nb_samples, int16_t *output)
float p_output[FFT_BUFFER_SIZE]; /* Raw FFT Result */
int16_t p_buffer1[FFT_BUFFER_SIZE]; /* Buffer on which we perform
the FFT (first channel) */
float *p_buffl = (float*)p_buffer; /* Original buffer */
float *p_buffl = (float*)p_sys->data; /* Original buffer */
int16_t *p_buffs; /* int16_t converted buffer */
int16_t *p_s16_buff; /* int16_t converted buffer */

@ -35,6 +35,9 @@ typedef struct
/* FFT window parameters */
window_param wind_param;
uint8_t *data;
int nb_samples;
} filter_sys_t;
static void *fft_thread(void *);
@ -45,7 +48,7 @@ block_t *filter_audio(filter_sys_t *p_sys, void *p_in_buf);
void close_visualizer(filter_sys_t *p_filter);
void fft_once(void *p_data, uint8_t *p_buffer, int nb_samples, int16_t *output);
void fft_once(void *p_data, int16_t *output);
int init_visualizer(filter_sys_t *p_sys);

Loading…
Cancel
Save