change type from short to byte

dev
xufulong 3 years ago
parent ec2d447925
commit 448d3c200f
  1. 10
      app/src/main/cpp/audio_player.cpp
  2. 4
      app/src/main/cpp/visualizer/execute_fft.c
  3. 2
      app/src/main/cpp/visualizer/execute_fft.h
  4. 4
      app/src/main/java/com/frank/ffmpeg/AudioPlayer.java
  5. 8
      app/src/main/java/com/frank/ffmpeg/activity/EqualizerActivity.kt

@ -34,7 +34,7 @@ int filter_again = 0;
int filter_release = 0;
const char *filter_desc = "superequalizer=6b=4:8b=5:10b=5";
void fft_callback(JNIEnv *jniEnv, jobject thiz, jmethodID fft_method, int16_t* arg, int samples);
void fft_callback(JNIEnv *jniEnv, jobject thiz, jmethodID fft_method, int8_t* arg, int samples);
int init_volume_filter(AVFilterGraph **graph, AVFilterContext **src, AVFilterContext **sink,
uint64_t channel_layout, AVSampleFormat inputFormat, int sample_rate) {
@ -283,7 +283,7 @@ AUDIO_PLAYER_FUNC(void, play, jstring input_jstr, jstring filter_jstr) {
// goto end;
}
jmethodID fft_method = env->GetMethodID(player_class, "fftCallbackFromJNI", "([S)V");
jmethodID fft_method = env->GetMethodID(player_class, "fftCallbackFromJNI", "([B)V");
auto *fft_filter = static_cast<filter_sys_t *>(malloc(sizeof(filter_sys_t)));
init_visualizer(fft_filter);
@ -377,9 +377,9 @@ AUDIO_PLAYER_FUNC(void, release) {
filter_release = 1;
}
void fft_callback(JNIEnv *jniEnv, jobject thiz, jmethodID fft_method, int16_t * arg, int samples) {
jshortArray dataArray = jniEnv->NewShortArray(samples);
jniEnv->SetShortArrayRegion(dataArray, 0, samples, arg);
void fft_callback(JNIEnv *jniEnv, jobject thiz, jmethodID fft_method, int8_t * arg, int samples) {
jbyteArray dataArray = jniEnv->NewByteArray(samples);
jniEnv->SetByteArrayRegion(dataArray, 0, samples, arg);
jniEnv->CallVoidMethod(thiz, fft_method, dataArray);
jniEnv->DeleteLocalRef(dataArray);
}

@ -317,8 +317,10 @@ void fft_once(filter_sys_t *p_sys)
fft_perform (p_buffer1, p_output, p_state);
for (i = 0; i < out_samples; ++i) {
p_sys->output[i] = p_output[i] * (2 ^ 16)
int16_t temp = p_output[i] * (2 ^ 16)
/ ((out_samples / 2 * 32768) ^ 2);
p_sys->output[i] = temp & 0xFF;
}
release:

@ -32,7 +32,7 @@ typedef struct
uint8_t *data;
int data_size;
int nb_samples;
int16_t * output;
int8_t * output;
int out_samples;
} filter_sys_t;

@ -63,14 +63,14 @@ public class AudioPlayer {
private OnFFTCallback onFFTCallback;
public interface OnFFTCallback {
void onFFT(short[] data);
void onFFT(byte[] data);
}
public void setOnFftCallback(OnFFTCallback onFFTCallback) {
this.onFFTCallback = onFFTCallback;
}
public void fftCallbackFromJNI(short[] data) {
public void fftCallbackFromJNI(byte[] data) {
if (data != null && onFFTCallback != null) {
onFFTCallback.onFFT(data);
}

@ -34,12 +34,11 @@ class EqualizerActivity : BaseActivity(), OnSeeBarListener {
private val selectBandList = IntArray(bandsList.size)
private val minEQLevel = 0
private val fftData = ByteArray(256)
private var filterThread: Thread? = null
private var mAudioPlayer: AudioPlayer? = null
private var visualizerView: VisualizerView? = null
private var equalizerAdapter: EqualizerAdapter? = null
private var audioPath = Environment.getExternalStorageDirectory().path + "/know_play.mp3"
private var audioPath = Environment.getExternalStorageDirectory().path + "/boy.mp3"
override val layoutId: Int
get() = R.layout.activity_equalizer
@ -93,10 +92,7 @@ class EqualizerActivity : BaseActivity(), OnSeeBarListener {
mAudioPlayer = AudioPlayer()
mAudioPlayer?.setOnFftCallback {
if (visualizerView != null && it != null) {
for (i in it.indices) {
fftData[i] = (it[i]).toByte()
}
visualizerView!!.post { visualizerView!!.setWaveData(fftData) }
visualizerView!!.post { visualizerView!!.setWaveData(it) }
}
}
}

Loading…
Cancel
Save