Repository navigation
Expand file tree
/
Copy pathCrossfadeCat.java
More file actions
98 lines (79 loc) · 2.66 KB
/
Copy pathCrossfadeCat.java
File metadata and controls
98 lines (79 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package net.sourceforge.sox;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import android.util.Log;
/**
* Concatenates two files together with a crossfade of user
* defined length.
*
* It is a Java port of the scripts/crossfade_cat.sh script
* in the sox source tree.
*
* Original script by Kester Clegg, with modifications by Chris
* Bagwell.
*
* @author Abel Luck
*
*/
// TODO make runnable?
public class CrossfadeCat {
private final static String TAG = "SOX-XFADE";
private SoxController mController;
private String mFirstFile;
private String mSecondFile;
private double mFadeLength;
private String mFinalMix;
public CrossfadeCat(SoxController controller, String firstFile, String secondFile, double fadeLength, String outFile) {
mController = controller;
mFirstFile = firstFile;
mSecondFile = secondFile;
mFadeLength = fadeLength;
mFinalMix = outFile;
}
public boolean start() throws IOException {
// find length of first file
double length = mController.getLength(mFirstFile);
double trimLength = length - mFadeLength;
// Obtain trimLength seconds of fade out position from the first File
String trimmedOne = mController.trimAudio(mFirstFile, trimLength, mFadeLength);
if( trimmedOne == null )
return abort();
// We assume a fade out is needed (i.e., firstFile doesn't already fade out)
String fadedOne = mController.fadeAudio(trimmedOne, "t", 0, mFadeLength, mFadeLength);
if( fadedOne == null )
return abort();
// Get crossfade section from the second file
String trimmedTwo = mController.trimAudio(mSecondFile, 0, mFadeLength);
if( trimmedTwo == null )
return abort();
String fadedTwo = mController.fadeAudio(trimmedTwo, "t", mFadeLength, -1, -1);
if( fadedTwo == null )
return abort();
// Mix crossfaded files together at full volume
ArrayList<String> files = new ArrayList<String>();
files.add(fadedOne);
files.add(fadedTwo);
String crossfaded = new File(mFirstFile).getCanonicalPath() + "-x-" + new File(mSecondFile).getName() +".wav";
crossfaded = mController.combineMix(files, crossfaded);
if( crossfaded == null )
return abort();
// Trim off crossfade sections from originals
String trimmedThree = mController.trimAudio(mFirstFile, 0, trimLength);
if( trimmedThree == null )
return abort();
String trimmedFour = mController.trimAudio(mSecondFile, mFadeLength, -1);
if( trimmedFour == null )
return abort();
// Combine into final mix
files.clear();
files.add(trimmedThree);
files.add(crossfaded);
files.add(trimmedFour);
mFinalMix = mController.combine(files, mFinalMix);
return true;
}
private boolean abort() {
return false;
}
}