Removed pointless garbage collection calls. Massive speedup
This commit is contained in:
@@ -1165,26 +1165,28 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
JMenuObject peak = new JMenuObject("Auto-trim all (Peak)", c, new ActionListener() {
|
JMenuObject peak = new JMenuObject("Auto-trim all (Peak)", c, new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter c = (Chapter)o.getObject();
|
Chapter chap = (Chapter)o.getObject();
|
||||||
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
||||||
if (!snt.isLocked()) {
|
|
||||||
snt.autoTrimSamplePeak();
|
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.Peak);
|
||||||
}
|
Thread nt = new Thread(t);
|
||||||
}
|
nt.start();
|
||||||
|
ed.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JMenuObject fft = new JMenuObject("Auto-trim all (FFT)", c, new ActionListener() {
|
JMenuObject fft = new JMenuObject("Auto-trim all (FFT)", c, new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter c = (Chapter)o.getObject();
|
Chapter chap = (Chapter)o.getObject();
|
||||||
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
ProgressDialog ed = new ProgressDialog("Auto-trimming " + chap.getName());
|
||||||
if (!snt.isLocked()) {
|
|
||||||
snt.autoTrimSampleFFT();
|
AutoTrimThread t = new AutoTrimThread(chap, ed, AutoTrimThread.FFT);
|
||||||
}
|
Thread nt = new Thread(t);
|
||||||
}
|
nt.start();
|
||||||
|
ed.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1329,12 +1331,16 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
JMenuObject normalizeAll = new JMenuObject("Normalize chapter", c, new ActionListener() {
|
JMenuObject normalizeAll = new JMenuObject("Normalize chapter", c, new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter c = (Chapter)o.getObject();
|
Chapter chap = (Chapter)o.getObject();
|
||||||
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
ProgressDialog ed = new ProgressDialog("Normalizing " + chap.getName());
|
||||||
snt.normalize();
|
|
||||||
}
|
NormalizeThread t = new NormalizeThread(chap, ed);
|
||||||
|
Thread nt = new Thread(t);
|
||||||
|
nt.start();
|
||||||
|
ed.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2215,6 +2221,72 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
playingThread.start();
|
playingThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NormalizeThread implements Runnable {
|
||||||
|
ProgressDialog dialog;
|
||||||
|
Chapter chapter;
|
||||||
|
|
||||||
|
public NormalizeThread(Chapter c, ProgressDialog e) {
|
||||||
|
super();
|
||||||
|
dialog = e;
|
||||||
|
chapter = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
int numKids = chapter.getChildCount();
|
||||||
|
int kidCount = 0;
|
||||||
|
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
|
||||||
|
kidCount++;
|
||||||
|
dialog.setProgress(kidCount * 2000 / numKids);
|
||||||
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
snt.normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.closeDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AutoTrimThread implements Runnable {
|
||||||
|
ProgressDialog dialog;
|
||||||
|
Chapter chapter;
|
||||||
|
int type;
|
||||||
|
|
||||||
|
public final static int FFT = 0;
|
||||||
|
public final static int Peak = 1;
|
||||||
|
|
||||||
|
public AutoTrimThread(Chapter c, ProgressDialog e, int t) {
|
||||||
|
super();
|
||||||
|
dialog = e;
|
||||||
|
chapter = c;
|
||||||
|
type = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
int numKids = chapter.getChildCount();
|
||||||
|
int kidCount = 0;
|
||||||
|
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
|
||||||
|
kidCount++;
|
||||||
|
dialog.setProgress(kidCount * 2000 / numKids);
|
||||||
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
switch (type) {
|
||||||
|
case FFT:
|
||||||
|
snt.autoTrimSampleFFT();
|
||||||
|
break;
|
||||||
|
case Peak:
|
||||||
|
snt.autoTrimSamplePeak();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.closeDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExportThread implements Runnable {
|
class ExportThread implements Runnable {
|
||||||
ProgressDialog exportDialog;
|
ProgressDialog exportDialog;
|
||||||
Chapter chapter;
|
Chapter chapter;
|
||||||
@@ -2398,6 +2470,12 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
play.write(data, 0, data.length);
|
play.write(data, 0, data.length);
|
||||||
playing = null;
|
playing = null;
|
||||||
} else {
|
} else {
|
||||||
|
play.drain();
|
||||||
|
play.stop();
|
||||||
|
play.close();
|
||||||
|
play.open(format);
|
||||||
|
play.start();
|
||||||
|
play.drain();
|
||||||
data = getRoomNoise(s.getPostGap());
|
data = getRoomNoise(s.getPostGap());
|
||||||
play.write(data, 0, data.length);
|
play.write(data, 0, data.length);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,15 +15,12 @@ public class CacheManager {
|
|||||||
} else {
|
} else {
|
||||||
if (ob instanceof Sentence) {
|
if (ob instanceof Sentence) {
|
||||||
Sentence s = (Sentence)ob;
|
Sentence s = (Sentence)ob;
|
||||||
s.debug("Normal removal from cache");
|
|
||||||
}
|
}
|
||||||
ob.clearCache();
|
ob.clearCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.add(c);
|
cache.add(c);
|
||||||
|
|
||||||
System.gc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setCacheSize(int c) {
|
public static void setCacheSize(int c) {
|
||||||
@@ -33,7 +30,6 @@ public class CacheManager {
|
|||||||
public static void removeFromCache(Cacheable c) {
|
public static void removeFromCache(Cacheable c) {
|
||||||
if (c instanceof Sentence) {
|
if (c instanceof Sentence) {
|
||||||
Sentence s = (Sentence)c;
|
Sentence s = (Sentence)c;
|
||||||
s.debug("Manual removal from cache");
|
|
||||||
}
|
}
|
||||||
cache.remove(c);
|
cache.remove(c);
|
||||||
c.clearCache();
|
c.clearCache();
|
||||||
|
|||||||
12
src/uk/co/majenko/audiobookrecorder/Debug.java
Normal file
12
src/uk/co/majenko/audiobookrecorder/Debug.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
public class Debug {
|
||||||
|
static long timestamp;
|
||||||
|
|
||||||
|
static void debug(String msg) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
long diff = now - timestamp;
|
||||||
|
timestamp = now;
|
||||||
|
System.err.println(String.format("%8d - %s", diff, msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -161,7 +161,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Start recording based purge");
|
|
||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
|
|
||||||
recordingThread = new RecordingThread(getTempFile(), getFile(), Options.getAudioFormat());
|
recordingThread = new RecordingThread(getTempFile(), getFile(), Options.getAudioFormat());
|
||||||
@@ -183,7 +182,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Stop recording based purge");
|
|
||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
|
|
||||||
if (!id.equals("room-noise")) {
|
if (!id.equals("room-noise")) {
|
||||||
@@ -224,7 +222,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
samples = getProcessedAudioData();
|
samples = getProcessedAudioData();
|
||||||
}
|
}
|
||||||
if (samples == null) {
|
if (samples == null) {
|
||||||
debug("Error: loading data failed!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +303,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
updateCrossings(useRaw);
|
updateCrossings(useRaw);
|
||||||
intens = null;
|
intens = null;
|
||||||
samples = null;
|
samples = null;
|
||||||
System.gc();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -587,7 +583,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
debug("Clearing cached data");
|
|
||||||
audioData = null;
|
audioData = null;
|
||||||
processedAudio = null;
|
processedAudio = null;
|
||||||
storedFormat = null;
|
storedFormat = null;
|
||||||
@@ -723,7 +718,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
int gint = (int)(g * 100d);
|
int gint = (int)(g * 100d);
|
||||||
int gainint = (int)(gain * 100d);
|
int gainint = (int)(gain * 100d);
|
||||||
if (gint != gainint) {
|
if (gint != gainint) {
|
||||||
debug("Gain based purge");
|
|
||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
}
|
}
|
||||||
gain = g;
|
gain = g;
|
||||||
@@ -770,7 +764,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
proc.waitFor();
|
proc.waitFor();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
debug("External editor based purge");
|
|
||||||
CacheManager.removeFromCache(Sentence.this);
|
CacheManager.removeFromCache(Sentence.this);
|
||||||
AudiobookRecorder.window.updateWaveform();
|
AudiobookRecorder.window.updateWaveform();
|
||||||
}
|
}
|
||||||
@@ -861,7 +854,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("External processor based purge");
|
|
||||||
CacheManager.removeFromCache(Sentence.this);
|
CacheManager.removeFromCache(Sentence.this);
|
||||||
AudiobookRecorder.window.updateWaveform();
|
AudiobookRecorder.window.updateWaveform();
|
||||||
}
|
}
|
||||||
@@ -905,7 +897,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Undo based purge");
|
|
||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
AudiobookRecorder.window.updateWaveform();
|
AudiobookRecorder.window.updateWaveform();
|
||||||
}
|
}
|
||||||
@@ -1080,7 +1071,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Write based purge");
|
|
||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1169,7 +1159,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
synchronized public double[][] getProcessedAudioData(boolean effectsEnabled) {
|
synchronized public double[][] getProcessedAudioData(boolean effectsEnabled) {
|
||||||
loadFile();
|
loadFile();
|
||||||
if (processedAudio != null) {
|
if (processedAudio != null) {
|
||||||
debug("Returning cached data");
|
|
||||||
return processedAudio;
|
return processedAudio;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1186,7 +1175,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
Effect eff = AudiobookRecorder.window.effects.get(def);
|
Effect eff = AudiobookRecorder.window.effects.get(def);
|
||||||
|
|
||||||
if (effectsEnabled) {
|
if (effectsEnabled) {
|
||||||
debug("Processing audio effects");
|
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
eff.init(getAudioFormat().getFrameRate());
|
eff.init(getAudioFormat().getFrameRate());
|
||||||
eff.process(processedAudio);
|
eff.process(processedAudio);
|
||||||
@@ -1204,7 +1192,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Processing done");
|
|
||||||
|
|
||||||
// Add final master gain stage
|
// Add final master gain stage
|
||||||
for (int i = 0; i < processedAudio.length; i++) {
|
for (int i = 0; i < processedAudio.length; i++) {
|
||||||
@@ -1212,7 +1199,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
processedAudio[i][RIGHT] *= gain;
|
processedAudio[i][RIGHT] *= gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Gain applied");
|
|
||||||
|
|
||||||
return processedAudio;
|
return processedAudio;
|
||||||
}
|
}
|
||||||
@@ -1272,7 +1258,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public void setEffectChain(String key) {
|
public void setEffectChain(String key) {
|
||||||
if ((effectChain != null) && (!effectChain.equals(key))) {
|
if ((effectChain != null) && (!effectChain.equals(key))) {
|
||||||
debug("Effects chain based purge");
|
|
||||||
CacheManager.removeFromCache(this);
|
CacheManager.removeFromCache(this);
|
||||||
}
|
}
|
||||||
effectChain = key;
|
effectChain = key;
|
||||||
@@ -1321,6 +1306,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void debug(String txt) {
|
public void debug(String txt) {
|
||||||
System.err.println(id + ": " + txt);
|
Debug.debug(String.format("%s: %s", id, txt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user