Add: FFT data callback

dev
xufuji456 3 years ago
parent 4114651e59
commit f97025601a
  1. 48
      app/src/main/cpp/audio_player.cpp
  2. 3
      app/src/main/cpp/visualizer/execute_fft.c
  3. 6
      app/src/main/cpp/visualizer/execute_fft.h

@ -19,6 +19,8 @@ extern "C" {
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "ffmpeg_jni_define.h" #include "ffmpeg_jni_define.h"
#include "visualizer/execute_fft.h"
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@ -357,4 +359,50 @@ AUDIO_PLAYER_FUNC(void, again, jstring filter_jstr) {
AUDIO_PLAYER_FUNC(void, release) { AUDIO_PLAYER_FUNC(void, release) {
filter_release = 1; 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<filter_sys_t *>(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<uint8_t *>(malloc(len * sizeof(uint8_t)));
auto *block = static_cast<block_t *>(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;
} }

@ -200,7 +200,8 @@ static void *fft_thread(void *p_data)
// vlc_tick_wait(block->i_pts + (block->i_length / 2)); // vlc_tick_wait(block->i_pts + (block->i_length / 2));
// vlc_gl_Swap(gl); // vlc_gl_Swap(gl);
usleep(200*1000 /*block->i_pts + (block->i_length / 2)*/); 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: release:
window_close(&wind_ctx); window_close(&wind_ctx);

@ -23,6 +23,10 @@ typedef int64_t vlc_tick_t;
typedef struct block_t block_t; typedef struct block_t block_t;
typedef struct FFT_callback {
void (*callback)(void*);
} FFT_callback;
struct block_t struct block_t
{ {
block_t *p_next; block_t *p_next;
@ -34,6 +38,8 @@ struct block_t
vlc_tick_t i_pts; vlc_tick_t i_pts;
vlc_tick_t i_length; vlc_tick_t i_length;
FFT_callback fft_callback;
}; };
typedef struct typedef struct

Loading…
Cancel
Save