change member variable to private

dev
xufulong 3 years ago
parent 64dfc15806
commit e7ee7e78a6
  1. 6
      app/src/main/cpp/audio_player.cpp
  2. 12
      app/src/main/cpp/visualizer/frank_visualizer.cpp
  3. 6
      app/src/main/cpp/visualizer/frank_visualizer.h
  4. 10
      app/src/main/cpp/visualizer/frank_visualizer_jni.cpp

@ -311,10 +311,8 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
int nb_samples = frame->nb_samples < MAX_FFT_SIZE ? frame->nb_samples : MAX_FFT_SIZE;
if (nb_samples >= MIN_FFT_SIZE) {
mVisualizer->fft_context->nb_samples = nb_samples;
memcpy(mVisualizer->fft_context->data, frame->data[0], nb_samples);
mVisualizer->fft_run();
fft_callback(env, thiz, fft_method, mVisualizer->fft_context->output, mVisualizer->fft_context->out_samples);
int8_t *output_data = mVisualizer->fft_run(frame->data[0], nb_samples);
fft_callback(env, thiz, fft_method, output_data, mVisualizer->getOutputSample());
}
ret = av_buffersrc_add_frame(audioSrcContext, frame);

@ -158,8 +158,10 @@ FrankVisualizer::~FrankVisualizer() {
LOGE("FrankVisualizer release...");
}
void FrankVisualizer::fft_run() {
int8_t* FrankVisualizer::fft_run(uint8_t *input_buffer, int nb_samples) {
mFftLock.lock();
fft_context->nb_samples = nb_samples;
memcpy(fft_context->data, input_buffer, static_cast<size_t>(nb_samples));
filter_sys_t *p_sys = fft_context;
#ifdef FIXED_FFT
fft_fixed(p_sys);
@ -167,6 +169,14 @@ void FrankVisualizer::fft_run() {
fft_float(p_sys);
#endif
mFftLock.unlock();
return fft_context->output;
}
int FrankVisualizer::getOutputSample() {
if (fft_context) {
return fft_context->out_samples;
}
return 0;
}
int FrankVisualizer::init_visualizer() {

@ -39,13 +39,15 @@ class FrankVisualizer {
private:
std::mutex mFftLock;
filter_sys_t *fft_context = nullptr;
public:
FrankVisualizer();
~FrankVisualizer();
filter_sys_t *fft_context = nullptr;
int getOutputSample();
void fft_run();
int8_t* fft_run(uint8_t *input_buffer, int nb_samples);
int init_visualizer();

@ -63,14 +63,12 @@ VISUALIZER_FUNC(int, nativeInitVisualizer) {
VISUALIZER_FUNC(int, nativeCaptureData, jobject buffer, jint size) {
if (!buffer) return -1;
FrankVisualizer *mVisualizer = getCustomVisualizer(env, thiz);
if (!mVisualizer || !mVisualizer->fft_context) return -2;
if (!mVisualizer) return -2;
int nb_samples = size < MAX_FFT_SIZE ? size : MAX_FFT_SIZE;
if (nb_samples >= MIN_FFT_SIZE) {
mVisualizer->fft_context->nb_samples = nb_samples;
auto *direct_buffer = static_cast<uint8_t *>(env->GetDirectBufferAddress(buffer));
memcpy(mVisualizer->fft_context->data, direct_buffer, static_cast<size_t>(nb_samples));
mVisualizer->fft_run();
fft_callback(env, mVisualizer->fft_context->output, mVisualizer->fft_context->out_samples);
auto *input_buffer = static_cast<uint8_t *>(env->GetDirectBufferAddress(buffer));
int8_t *output_data = mVisualizer->fft_run(input_buffer, nb_samples);
fft_callback(env, output_data, mVisualizer->getOutputSample());
}
return 0;
}

Loading…
Cancel
Save