move param into struct

dev
xufulong 3 years ago
parent 61131656f8
commit 334f446a1d
  1. 8
      app/src/main/cpp/audio_player.cpp
  2. 16
      app/src/main/cpp/visualizer/execute_fft.c
  3. 3
      app/src/main/cpp/visualizer/execute_fft.h

@ -2,7 +2,7 @@
// Created by frank on 2018/2/1.
//
#include <jni.h>
#include <stdlib.h>
#include <cstdlib>
#include <unistd.h>
#ifdef __cplusplus
@ -286,8 +286,8 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
jmethodID fft_method = env->GetMethodID(player_class, "fftCallbackFromJNI", "([S)V");
auto *fft_filter = static_cast<filter_sys_t *>(malloc(sizeof(filter_sys_t)));
fft_filter->output = static_cast<int16_t *>(malloc(FFT_BUFFER_SIZE * sizeof(int16_t)));
init_visualizer(fft_filter);
auto *output = static_cast<int16_t *>(malloc(FFT_BUFFER_SIZE * sizeof(int16_t)));
//read audio frame
while (av_read_frame(pFormatCtx, packet) >= 0 && !filter_release) {
@ -316,8 +316,8 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
}
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);
fft_once(fft_filter);
fft_callback(env, thiz, fft_method, fft_filter->output);
}
ret = av_buffersrc_add_frame(audioSrcContext, frame);

@ -56,6 +56,12 @@ void close_visualizer(filter_sys_t *p_filter)
free(p_sys->p_prev_s16_buff);
free(&p_sys->wind_param);
if (p_sys->data) {
free(p_sys->data);
}
if (p_sys->output) {
free(p_sys->output);
}
free(p_sys);
}
@ -211,12 +217,14 @@ void release_visualizer(filter_sys_t *p_filter)
if (p_sys->data) {
free(p_sys->data);
}
if (p_sys->output) {
free(p_sys->output);
}
free(p_sys);
}
void fft_once(void *p_data, int16_t *output)
void fft_once(filter_sys_t *p_sys)
{
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 */
@ -289,10 +297,10 @@ void fft_once(void *p_data, int16_t *output)
fft_perform (p_buffer1, p_output, p_state);
for (i = 0; i < FFT_BUFFER_SIZE; ++i)
output[i] = p_output[i] * (2 ^ 16)
p_sys->output[i] = p_output[i] * (2 ^ 16)
/ ((FFT_BUFFER_SIZE / 2 * 32768) ^ 2);
LOGE("out[100]=%d,out[101]=%d,out[102]=%d", output[100], output[101], output[102]);
LOGE("out[100]=%d,out[101]=%d,out[102]=%d", p_sys->output[100], p_sys->output[101], p_sys->output[102]);
release:
window_close(&wind_ctx);

@ -38,6 +38,7 @@ typedef struct
uint8_t *data;
int nb_samples;
int16_t * output;
} filter_sys_t;
static void *fft_thread(void *);
@ -48,7 +49,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, int16_t *output);
void fft_once(filter_sys_t *p_sys);
int init_visualizer(filter_sys_t *p_sys);

Loading…
Cancel
Save