|
|
@ -34,6 +34,10 @@ int filter_again = 0; |
|
|
|
int filter_release = 0; |
|
|
|
int filter_release = 0; |
|
|
|
const char *filter_desc = "superequalizer=6b=4:8b=5:10b=5"; |
|
|
|
const char *filter_desc = "superequalizer=6b=4:8b=5:10b=5"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JavaVM *java_vm; |
|
|
|
|
|
|
|
jobject jni_object; |
|
|
|
|
|
|
|
jmethodID fft_method; |
|
|
|
|
|
|
|
|
|
|
|
static void fft_callback(void* arg); |
|
|
|
static void fft_callback(void* arg); |
|
|
|
|
|
|
|
|
|
|
|
int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterContext **sink, |
|
|
|
int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterContext **sink, |
|
|
@ -280,9 +284,19 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
ret = init_equalizer_filter(filter_desc, codecCtx, &audioFilterGraph, &audioSrcContext, &audioSinkContext); |
|
|
|
ret = init_equalizer_filter(filter_desc, codecCtx, &audioFilterGraph, &audioSrcContext, &audioSinkContext); |
|
|
|
if (ret < 0) { |
|
|
|
if (ret < 0) { |
|
|
|
LOGE(TAG, "Unable to init filter graph:%d", ret); |
|
|
|
LOGE(TAG, "Unable to init filter graph:%d", ret); |
|
|
|
goto end; |
|
|
|
// goto end;
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env->GetJavaVM(&java_vm); |
|
|
|
|
|
|
|
jni_object = env->NewGlobalRef(thiz); |
|
|
|
|
|
|
|
fft_method = env->GetMethodID(player_class, "fftCallbackFromJNI", "([I)V"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filter_sys_t *fft_filter = static_cast<filter_sys_t *>(malloc(sizeof(filter_sys_t))); |
|
|
|
|
|
|
|
open_visualizer(fft_filter); |
|
|
|
|
|
|
|
auto *block = static_cast<block_t *>(malloc(sizeof(block_t))); |
|
|
|
|
|
|
|
block->i_nb_samples = 0; |
|
|
|
|
|
|
|
block->fft_callback.callback = fft_callback; |
|
|
|
|
|
|
|
|
|
|
|
//read audio frame
|
|
|
|
//read audio frame
|
|
|
|
while (av_read_frame(pFormatCtx, packet) >= 0 && !filter_release) { |
|
|
|
while (av_read_frame(pFormatCtx, packet) >= 0 && !filter_release) { |
|
|
|
if (packet->stream_index != audio_stream_idx) { |
|
|
|
if (packet->stream_index != audio_stream_idx) { |
|
|
@ -303,6 +317,19 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (got_frame > 0) { |
|
|
|
if (got_frame > 0) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (block->i_nb_samples == 0 && frame->nb_samples > 100) { |
|
|
|
|
|
|
|
auto *data = static_cast<uint8_t *>(malloc(frame->nb_samples * sizeof(uint8_t))); |
|
|
|
|
|
|
|
block->p_buffer = data; |
|
|
|
|
|
|
|
block->i_nb_samples = static_cast<unsigned int>(frame->nb_samples); |
|
|
|
|
|
|
|
LOGE(TAG, "frame->nb_samples=%d", frame->nb_samples); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (block->i_nb_samples == frame->nb_samples) { |
|
|
|
|
|
|
|
LOGE(TAG, "start frame->nb_samples=%d", frame->nb_samples); |
|
|
|
|
|
|
|
memcpy(block->p_buffer, frame->data[0], static_cast<size_t>(frame->nb_samples)); |
|
|
|
|
|
|
|
filter_audio(fft_filter, block); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ret = av_buffersrc_add_frame(audioSrcContext, frame); |
|
|
|
ret = av_buffersrc_add_frame(audioSrcContext, frame); |
|
|
|
if (ret < 0) { |
|
|
|
if (ret < 0) { |
|
|
|
LOGE(TAG, "Error add the frame to the filter graph:%d", ret); |
|
|
|
LOGE(TAG, "Error add the frame to the filter graph:%d", ret); |
|
|
@ -376,10 +403,15 @@ AUDIO_PLAYER_FUNC(void, openFFT) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void fft_callback(void* arg) { |
|
|
|
static void fft_callback(void* arg) { |
|
|
|
float* data = (float*) 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]);
|
|
|
|
LOGE(TAG, "fft data[0]=%f,data[1]=%f,data[2]=%f", data[0], data[1], data[2]); |
|
|
|
|
|
|
|
} |
|
|
|
JNIEnv *jniEnv = nullptr; |
|
|
|
|
|
|
|
java_vm->AttachCurrentThread(&jniEnv, nullptr); |
|
|
|
|
|
|
|
jintArray dataArray = jniEnv->NewIntArray(/*20*/256); |
|
|
|
|
|
|
|
jniEnv->SetIntArrayRegion(dataArray, 0, /*20*/256, (int*)arg); |
|
|
|
|
|
|
|
jniEnv->CallVoidMethod(jni_object, fft_method, dataArray); |
|
|
|
|
|
|
|
java_vm->DetachCurrentThread(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void *input(void *) { |
|
|
|
static void *input(void *) { |
|
|
|