Move normalize chapter to queue system
This commit is contained in:
@@ -1689,12 +1689,17 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter chap = (Chapter)o.getObject();
|
Chapter chap = (Chapter)o.getObject();
|
||||||
|
|
||||||
ProgressDialog ed = new ProgressDialog("Normalizing " + chap.getName());
|
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||||
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
NormalizeThread t = new NormalizeThread(chap, ed);
|
if (!snt.isLocked()) {
|
||||||
Thread nt = new Thread(t);
|
queueJob(new SentenceJob(snt) {
|
||||||
nt.start();
|
public void run() {
|
||||||
ed.setVisible(true);
|
sentence.normalize();
|
||||||
|
sentence.autoAddPeakGainPoints();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2444,41 +2449,6 @@ public class AudiobookRecorder extends JFrame implements DocumentListener {
|
|||||||
playingThread.start();
|
playingThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
class NormalizeThread implements Runnable {
|
|
||||||
ProgressDialog dialog;
|
|
||||||
Chapter chapter;
|
|
||||||
|
|
||||||
public NormalizeThread(Chapter c, ProgressDialog e) {
|
|
||||||
super();
|
|
||||||
Debug.trace();
|
|
||||||
dialog = e;
|
|
||||||
chapter = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void run() {
|
|
||||||
Debug.trace();
|
|
||||||
|
|
||||||
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();
|
|
||||||
if (lastGain == -1) {
|
|
||||||
lastGain = snt.normalize();
|
|
||||||
} else {
|
|
||||||
lastGain = snt.normalize(lastGain - variance, lastGain + variance);
|
|
||||||
}
|
|
||||||
snt.autoAddPeakGainPoints();
|
|
||||||
}
|
|
||||||
|
|
||||||
dialog.closeDialog();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExportThread implements Runnable {
|
class ExportThread implements Runnable {
|
||||||
ProgressDialog exportDialog;
|
ProgressDialog exportDialog;
|
||||||
Chapter chapter;
|
Chapter chapter;
|
||||||
|
|||||||
@@ -803,7 +803,9 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public boolean lockedInCache() {
|
public boolean lockedInCache() {
|
||||||
Debug.trace();
|
Debug.trace();
|
||||||
return id.equals("room-noise");
|
if (id.equals("room-noise")) return true;
|
||||||
|
if (isProcessing()) return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int findNearestZeroCrossing(int pos, int range) {
|
public int findNearestZeroCrossing(int pos, int range) {
|
||||||
@@ -1497,7 +1499,12 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
eff = book.effects.get(effectChain);
|
eff = book.effects.get(effectChain);
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
eff.init(getAudioFormat().getFrameRate());
|
eff.init(getAudioFormat().getFrameRate());
|
||||||
|
// There is a chance another thread could cripple the audio data cache
|
||||||
|
// so we'll just ignore any errors here.
|
||||||
|
try {
|
||||||
eff.process(processedAudio);
|
eff.process(processedAudio);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2030,6 +2037,11 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
|
|
||||||
double peak = 0;
|
double peak = 0;
|
||||||
|
|
||||||
|
if (samples == null) {
|
||||||
|
System.err.println("Um.... no samples...?");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < samples[LEFT].length; i++) {
|
for (int i = 0; i < samples[LEFT].length; i++) {
|
||||||
if (Math.abs(samples[LEFT][i]) > peak) {
|
if (Math.abs(samples[LEFT][i]) > peak) {
|
||||||
peak = Math.abs(samples[LEFT][i]);
|
peak = Math.abs(samples[LEFT][i]);
|
||||||
@@ -2069,6 +2081,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
while (true) {
|
while (true) {
|
||||||
double[][] samples = getProcessedAudioData();
|
double[][] samples = getProcessedAudioData();
|
||||||
int pos = findBiggestPeak();
|
int pos = findBiggestPeak();
|
||||||
|
if (pos == -1) return;
|
||||||
System.err.println("Biggest peak: " + pos);
|
System.err.println("Biggest peak: " + pos);
|
||||||
if ((Math.abs(samples[LEFT][pos]) < 0.708) && (Math.abs(samples[RIGHT][pos]) < 0.708)) {
|
if ((Math.abs(samples[LEFT][pos]) < 0.708) && (Math.abs(samples[RIGHT][pos]) < 0.708)) {
|
||||||
System.err.println("Not a peak!");
|
System.err.println("Not a peak!");
|
||||||
@@ -2090,8 +2103,15 @@ public class Sentence extends BookTreeNode implements Cacheable {
|
|||||||
addGainPoint(pos, 1d);
|
addGainPoint(pos, 1d);
|
||||||
addGainPoint(end, 1d);
|
addGainPoint(end, 1d);
|
||||||
|
|
||||||
|
double val = 1d;
|
||||||
|
|
||||||
while (isClipping(start, end)) {
|
while (isClipping(start, end)) {
|
||||||
adjustGainPoint(pos, -0.05);
|
adjustGainPoint(pos, -0.05);
|
||||||
|
val -= 0.05d;
|
||||||
|
if (val < 0.04d) {
|
||||||
|
System.err.println("Aborting: gain too low");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user