From ccc10ed69f111b3beea9e65331211ebf6590a321 Mon Sep 17 00:00:00 2001 From: xufuji456 <839789740@qq.com> Date: Tue, 8 Jun 2021 23:56:04 +0800 Subject: [PATCH] add the echo effect --- .../ffmpeg/activity/AudioHandleActivity.kt | 9 ++++++++- .../java/com/frank/ffmpeg/util/FFmpegUtil.java | 18 ++++++++++++++++++ .../main/res/layout/activity_audio_handle.xml | 10 +++++++++- app/src/main/res/values-en/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt index 3a3e0fb..d49ceef 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/AudioHandleActivity.kt @@ -102,7 +102,8 @@ class AudioHandleActivity : BaseActivity() { R.id.btn_play_opensl, R.id.btn_audio_encode, R.id.btn_pcm_concat, - R.id.btn_audio_speed + R.id.btn_audio_speed, + R.id.btn_audio_echo ) } @@ -220,6 +221,12 @@ class AudioHandleActivity : BaseActivity() { val speedPath = PATH + File.separator + "speed.mp3" commandLine = FFmpegUtil.changeAudioSpeed(srcFile, speedPath, speed) } + R.id.btn_audio_echo//setting echo effect + -> { + val echo = 1000 // echo effect, range from 0 to 90000 + val echoPath = PATH + File.separator + "echo.mp3" + commandLine = FFmpegUtil.audioEcho(srcFile, echo, echoPath) + } else -> { } } diff --git a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java index 1edd382..eb1b8f4 100644 --- a/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java +++ b/app/src/main/java/com/frank/ffmpeg/util/FFmpegUtil.java @@ -85,6 +85,24 @@ public class FFmpegUtil { } //mixing formula: value = sample1 + sample2 - (sample1 * sample2 / (pow(2, 16-1) - 1)) + /** + * Set echo and delay effect + * + * @param inputPath input file + * @param delay delay to play + * @param outputPath output file + * @return mix success or not + */ + public static String[] audioEcho(String inputPath, int delay, String outputPath) { + // in_gain (0, 1], Default is 0.6 + // out_gain (0, 1], Default is 0.3 + // delays (0 - 90000]. Default is 1000 + // decays (0 - 1.0]. Default is 0.5 + String echoCmd = "ffmpeg -i %s -af aecho=0.8:0.8:%d:0.5 %s"; + echoCmd = String.format(Locale.getDefault(), echoCmd, inputPath, delay, outputPath); + return echoCmd.split(" "); + } + /** * mux audio and video together * diff --git a/app/src/main/res/layout/activity_audio_handle.xml b/app/src/main/res/layout/activity_audio_handle.xml index 898ec92..962b4f9 100644 --- a/app/src/main/res/layout/activity_audio_handle.xml +++ b/app/src/main/res/layout/activity_audio_handle.xml @@ -65,7 +65,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/pcm_concat" - android:layout_marginTop="10dp" /> + android:layout_marginTop="10dp" + android:visibility="gone"/>