|
23 | 23 | import linc.com.library.callback.OnListComplete; |
24 | 24 | import linc.com.library.types.Duration; |
25 | 25 | import linc.com.library.types.Echo; |
| 26 | +import linc.com.library.types.Pitch; |
26 | 27 |
|
27 | 28 | import static linc.com.library.Constant.AUDIO_TOOL_LOCAL_EFFECT_REVERB; |
28 | 29 | import static linc.com.library.Constant.AUDIO_TOOL_LOCAL_JOIN_FILE; |
@@ -206,27 +207,51 @@ public AudioTool changeAudioSpeed(float xSpeed, @Nullable OnFileComplete onCompl |
206 | 207 |
|
207 | 208 | /** |
208 | 209 | * @param sampleRate audio sample rate |
209 | | - * @param pitch audio pitch value |
210 | | - * @param tempo audio speed value |
| 210 | + * @param deltaRate audio custom rate value |
| 211 | + * @param deltaTempo audio custom tempo value |
211 | 212 | * @param onCompleteCallback lambda with result audio |
212 | 213 | */ |
213 | | - public AudioTool changeAudioPitch(int sampleRate, float pitch, float tempo, @Nullable OnFileComplete onCompleteCallback) throws IOException { |
214 | | - tempo = Limiter.limit(0.5f, 2, tempo); |
| 214 | + public AudioTool changeAudioPitch(int sampleRate, float deltaRate, float deltaTempo, @Nullable OnFileComplete onCompleteCallback) throws IOException { |
| 215 | + deltaTempo = Limiter.limit(-12f, 12f, deltaTempo); |
| 216 | + deltaRate = Limiter.limit(-12f, 12f, deltaRate); |
| 217 | + |
215 | 218 | String command = String.format(Locale.US, |
216 | | - "-y -i %s -filter_complex asetrate=%d*%f^(-10/12),atempo=%f^(-10/12)", |
217 | | - audio.getPath(), sampleRate, pitch, tempo |
| 219 | + "-y -i %s -filter_complex asetrate=%d*2^(%f/12),atempo=1/2^(%f/12)", |
| 220 | + audio.getPath(), sampleRate, deltaRate, deltaTempo |
218 | 221 | ); |
219 | 222 | FFmpegExecutor.executeCommandWithBuffer(command, audio); |
220 | 223 | onResultFile(onCompleteCallback); |
221 | 224 | return this; |
222 | 225 | } |
223 | 226 |
|
224 | 227 | /** |
225 | | - * @param bass audio bass |
226 | | - * @param width audio bass width |
227 | | - * @param frequency audio frequency |
| 228 | + * @param sampleRate audio sample rate |
| 229 | + * @param pitch audio semitone value |
| 230 | + * @param onCompleteCallback lambda with result audio |
| 231 | + */ |
| 232 | + public AudioTool changeAudioPitch(int sampleRate, float pitch, @Nullable OnFileComplete onCompleteCallback) throws IOException { |
| 233 | + changeAudioPitch(sampleRate, pitch, pitch, onCompleteCallback); |
| 234 | + return this; |
| 235 | + } |
| 236 | + |
| 237 | + /** |
| 238 | + * @param sampleRate audio sample rate |
| 239 | + * @param pitchValue audio semitone value |
| 240 | + * @param pitch pitch type: UP or DOWN |
228 | 241 | * @param onCompleteCallback lambda with result audio |
229 | 242 | */ |
| 243 | + public AudioTool changeAudioPitch(int sampleRate, float pitchValue, Pitch pitch, @Nullable OnFileComplete onCompleteCallback) throws IOException { |
| 244 | + pitchValue = pitch == Pitch.UP ? Math.abs(pitchValue) : -Math.abs(pitchValue); |
| 245 | + changeAudioPitch(sampleRate, pitchValue, pitchValue, onCompleteCallback); |
| 246 | + return this; |
| 247 | + } |
| 248 | + |
| 249 | + /** |
| 250 | + * @param bass audio bass |
| 251 | + * @param width audio bass width |
| 252 | + * @param frequency audio frequency |
| 253 | + * @param onCompleteCallback lambda with result audio |
| 254 | + */ |
230 | 255 | public AudioTool changeAudioBass(float bass, float width, int frequency, @Nullable OnFileComplete onCompleteCallback) throws IOException { |
231 | 256 | bass = Limiter.limit(-20f, 20f, bass); |
232 | 257 | width = Limiter.limit(0f, 1f, width); |
|
0 commit comments