Cure tree flashing on playback

This commit is contained in:
2020-01-20 16:00:29 +00:00
parent 4896ee7a65
commit e3231ec495
3 changed files with 53 additions and 20 deletions

View File

@@ -2034,10 +2034,11 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
bookTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode n = (DefaultMutableTreeNode)bookTree.getLastSelectedPathComponent();
if (n instanceof BookTreeNode) {
BookTreeNode btn = (BookTreeNode)n;
btn.onSelect();
}
if (n instanceof BookTreeNode) {
BookTreeNode btn = (BookTreeNode)n;
btn.onSelect();
}
if (n instanceof Sentence) {
Sentence s = (Sentence)n;
@@ -2531,11 +2532,17 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
int numKids = chapter.getChildCount();
int kidCount = 0;
double lastGain = -1;
double variance = Options.getInteger("audio.recording.variance") / 100d;
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
kidCount++;
dialog.setProgress(kidCount * 2000 / numKids);
Sentence snt = (Sentence)s.nextElement();
snt.normalize();
if (lastGain == -1) {
lastGain = snt.normalize();
} else {
lastGain = snt.normalize(lastGain - variance, lastGain + variance);
}
}
dialog.closeDialog();

View File

@@ -34,6 +34,7 @@ public class Options extends JDialog {
JSpinner shortSentenceGap;
JSpinner postParagraphGap;
JSpinner postSectionGap;
JSpinner maxGainVariance;
JTextField ffmpegLocation;
JComboBox<KVPair> bitRate;
JComboBox<KVPair> channels;
@@ -301,6 +302,7 @@ public class Options extends JDialog {
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"));
fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), "");
fftBlockSize = addDropdown(optionsPanel, "FFT Block size:", getFFTBlockSizes(), get("audio.recording.trim.blocksize"));
maxGainVariance = addSpinner(optionsPanel, "Maximum gain variance:", 0, 100, 1, getInteger("audio.recording.variance"), "");
addSeparator(optionsPanel);
@@ -582,6 +584,7 @@ public class Options extends JDialog {
defaultPrefs.put("catenation.post-section", "3000");
defaultPrefs.put("audio.recording.trim.fft", "10");
defaultPrefs.put("audio.recording.variance", "10");
defaultPrefs.put("path.storage", (new File(System.getProperty("user.home"), "Recordings")).toString());
defaultPrefs.put("path.archive", (new File(new File(System.getProperty("user.home"), "Recordings"),"archive")).toString());
@@ -718,6 +721,7 @@ public class Options extends JDialog {
set("editor.external", externalEditor.getText());
set("cache.size", cacheSize.getValue());
set("audio.recording.trim.fft", fftThreshold.getValue());
set("audio.recording.variance", maxGainVariance.getValue());
set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key);
set("audio.playback.blocksize", ((KVPair)playbackBlockSize.getSelectedItem()).key);

View File

@@ -350,7 +350,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
intens = null;
samples = null;
processed = true;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
public void autoTrimSamplePeak() {
@@ -407,7 +407,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
if (endOffset >= samples.length) endOffset = samples.length-1;
updateCrossings(useRaw);
processed = true;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
public String getId() {
@@ -417,7 +417,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
public void setText(String t) {
overrideText = null;
text = t;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
public String getText() {
@@ -465,7 +465,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
if (o instanceof String) {
String so = (String)o;
text = so;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
}
@@ -525,7 +525,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
if (startOffset != o) {
startOffset = o;
crossStartOffset = -1;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
}
@@ -541,7 +541,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
if (endOffset != o) {
endOffset = o;
crossEndOffset = -1;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
}
@@ -570,7 +570,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
public void doRecognition(StreamSpeechRecognizer recognizer) {
try {
setText("[recognising...]");
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
byte[] inData = getPCMData();
@@ -585,7 +585,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
recognizer.stopRecognition();
setText(res);
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
} catch (Exception e) {
e.printStackTrace();
}
@@ -621,8 +621,9 @@ public class Sentence extends BookTreeNode implements Cacheable {
}
public void setLocked(boolean l) {
if (locked == l) return;
locked = l;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
public boolean isLocked() {
@@ -724,8 +725,9 @@ public class Sentence extends BookTreeNode implements Cacheable {
}
public void setAttentionFlag(boolean f) {
if (attention == f) return;
attention = f;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
public boolean getAttentionFlag() {
@@ -787,12 +789,24 @@ public class Sentence extends BookTreeNode implements Cacheable {
return gain;
}
public void normalize() {
if (locked) return;
public double normalize(double low, double high) {
if (locked) return gain;
double max = getPeakValue(true, false);
double d = 0.708 / max;
if (d > 1d) d = 1d;
if (d < low) d = low;
if (d > high) d = high;
setGain(d);
return d;
}
public double normalize() {
if (locked) return gain;
double max = getPeakValue(true, false);
double d = 0.708 / max;
if (d > 1d) d = 1d;
setGain(d);
return d;
}
class ExternalEditor implements Runnable {
@@ -1321,11 +1335,14 @@ public class Sentence extends BookTreeNode implements Cacheable {
}
public void setEffectChain(String key) {
if ((effectChain != null) && (effectChain.equals(key))) {
return;
}
if ((effectChain != null) && (!effectChain.equals(key))) {
CacheManager.removeFromCache(this);
}
effectChain = key;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
public String getEffectChain() {
@@ -1352,7 +1369,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
}
}
postGapType = t;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
public void resetPostGap() {
@@ -1431,7 +1448,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
public void setProcessed(boolean p) {
processed = p;
AudiobookRecorder.window.bookTreeModel.reload(this);
reloadTree();
}
public void setNotes(String n) {
@@ -1446,4 +1463,9 @@ public class Sentence extends BookTreeNode implements Cacheable {
AudiobookRecorder.window.setSentenceNotes(notes);
}
void reloadTree() {
if (id.equals("room-noise")) return;
AudiobookRecorder.window.bookTreeModel.reload(this);
}
}