From f97025601a1481dc154be1acc7ddaebc6fc3fa81 Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Tue, 24 Aug 2021 00:10:04 +0800 Subject: [PATCH] Add: FFT data callback --- app/src/main/cpp/audio_player.cpp | 48 +++++++++++++++++++++++ app/src/main/cpp/visualizer/execute_fft.c | 3 +- app/src/main/cpp/visualizer/execute_fft.h | 6 +++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/audio_player.cpp b/app/src/main/cpp/audio_player.cpp index abeb005..f7b8020 100644 --- a/app/src/main/cpp/audio_player.cpp +++ b/app/src/main/cpp/audio_player.cpp @@ -19,6 +19,8 @@ extern "C" { #include "libavutil/opt.h" #include "ffmpeg_jni_define.h" +#include "visualizer/execute_fft.h" + #ifdef __cplusplus } #endif @@ -357,4 +359,50 @@ AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) { AUDIO_PLAYER_FUNC(void, release) { filter_release = 1; +} + +pthread_t input_thread; +filter_sys_t *p_sys; + +static void *input(void *); + +AUDIO_PLAYER_FUNC(void, openFFT) { + pthread_create(&input_thread, nullptr, input, nullptr); + + p_sys = static_cast(malloc(sizeof(filter_sys_t))); + open_visualizer(p_sys); +} + +static void fft_callback(void* arg) { + float* data = (float*) arg; + for (int i = 0; i < 3; ++i) { + LOGE(TAG, "fft data[0]=%f,data[1]=%f,data[2]=%f", data[0], data[1], data[2]); + } +} + +static void *input(void *) { + int64_t tick = 0; + size_t len = 256; + auto *data = static_cast(malloc(len * sizeof(uint8_t))); + auto *block = static_cast(malloc(sizeof(block_t))); + block->i_buffer = len; + block->p_buffer = data; + block->i_nb_samples = len; + block->i_pts = tick; + + block->fft_callback.callback = fft_callback; + + LOGE(TAG, "begin input..."); + for (int i = 0; i < 50; i++) { + for (int j = 0; j < len; j++) { + block->p_buffer[j] = i+j; + } + + filter_audio(p_sys, block); + tick += 16*1000; + usleep(200 * 1000); + } + LOGE(TAG, "finish input-_-"); +// close_visualizer(p_sys); + return nullptr; } \ No newline at end of file diff --git a/app/src/main/cpp/visualizer/execute_fft.c b/app/src/main/cpp/visualizer/execute_fft.c index 88f44ed..e099bac 100644 --- a/app/src/main/cpp/visualizer/execute_fft.c +++ b/app/src/main/cpp/visualizer/execute_fft.c @@ -200,7 +200,8 @@ static void *fft_thread(void *p_data) // vlc_tick_wait(block->i_pts + (block->i_length / 2)); // vlc_gl_Swap(gl); usleep(200*1000 /*block->i_pts + (block->i_length / 2)*/); - LOGE("height[0]=%f, height[1]=%f, height=[2]=%f", height[0], height[1], height[2]); +// LOGE("height[0]=%f, height[1]=%f, height=[2]=%f", height[0], height[1], height[2]); + block->fft_callback.callback(height); release: window_close(&wind_ctx); diff --git a/app/src/main/cpp/visualizer/execute_fft.h b/app/src/main/cpp/visualizer/execute_fft.h index 14d38cb..7bd4517 100644 --- a/app/src/main/cpp/visualizer/execute_fft.h +++ b/app/src/main/cpp/visualizer/execute_fft.h @@ -23,6 +23,10 @@ typedef int64_t vlc_tick_t; typedef struct block_t block_t; +typedef struct FFT_callback { + void (*callback)(void*); +} FFT_callback; + struct block_t { block_t *p_next; @@ -34,6 +38,8 @@ struct block_t vlc_tick_t i_pts; vlc_tick_t i_length; + + FFT_callback fft_callback; }; typedef struct