Repository navigation
Expand file tree
/
Copy pathCrossfadeCat.java
More file actions
100 lines (78 loc) · 3.11 KB
/
Copy pathCrossfadeCat.java
File metadata and controls
100 lines (78 loc) · 3.11 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
99
100
package net.sourceforge.sox;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
/**
* Concatenates two files together with a crossfade of user
* defined mClipLength.
*
* 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;
//double mClipLength = mController.getLength(mFirstFile);
}
public boolean start() throws Exception {
// find mClipLength of first file
// Obtain trimLength seconds of fade out position from the first File
double firstFileLength = mController.getLength(mFirstFile);
double trimLength = firstFileLength - mFadeLength;
String trimmedOne = mController.trimAudio(mFirstFile, trimLength, mFadeLength);
if( trimmedOne == null )
throw new IOException("audio trim did not complete: " + mFirstFile);
// 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 )
throw new IOException("audio fade did not complete: " + trimmedOne);
// Get crossfade section from the second file
String trimmedTwo = mController.trimAudio(mSecondFile, 0, mFadeLength);
if( trimmedTwo == null )
throw new IOException("audio trim did not complete: " + mSecondFile);
String fadedTwo = mController.fadeAudio(trimmedTwo, "t", mFadeLength, -1, -1);
if( fadedTwo == null )
throw new IOException("audio fade did not complete: " + trimmedTwo);
// 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 )
throw new IOException("crossfade did not complete");
// Trim off crossfade sections from originals
String trimmedThree = mController.trimAudio(mFirstFile, 0, trimLength);
if( trimmedThree == null )
throw new IOException("crossfade trim beginning did not complete");
String trimmedFour = mController.trimAudio(mSecondFile, mFadeLength, -1);
if( trimmedFour == null )
throw new IOException("crossfade trim end did not complete");
// Combine into final mix
files.clear();
files.add(trimmedThree);
files.add(crossfaded);
files.add(trimmedFour);
mFinalMix = mController.combine(files, mFinalMix);
if (mFinalMix == null)
throw new IOException("final mix did not complete");
return true;
}
}