More improvements to gain curve

This commit is contained in:
2020-09-01 19:02:43 +01:00
parent 16380a9752
commit 9c58276119
2 changed files with 41 additions and 9 deletions
@@ -8,15 +8,18 @@ public class CacheManager {
static int cacheSize = 10; static int cacheSize = 10;
public static void addToCache(Cacheable c) { public static void addToCache(Cacheable c) {
Debug.trace();
while (cache.size() >= cacheSize) { while (cache.size() >= cacheSize) {
Cacheable ob = cache.remove(0); Cacheable ob = cache.remove(0);
if (ob.lockedInCache()) { if (ob != null) {
cache.add(ob); if (ob.lockedInCache()) {
} else { cache.add(ob);
if (ob instanceof Sentence) { } else {
Sentence s = (Sentence)ob; if (ob instanceof Sentence) {
Sentence s = (Sentence)ob;
}
ob.clearCache();
} }
ob.clearCache();
} }
} }
@@ -28,6 +31,7 @@ public class CacheManager {
} }
public static void removeFromCache(Cacheable c) { public static void removeFromCache(Cacheable c) {
Debug.trace();
if (c instanceof Sentence) { if (c instanceof Sentence) {
Sentence s = (Sentence)c; Sentence s = (Sentence)c;
} }
@@ -978,12 +978,22 @@ public class Sentence extends BookTreeNode implements Cacheable {
int targetLow = Options.getInteger("audio.recording.rms.low"); int targetLow = Options.getInteger("audio.recording.rms.low");
int targetHigh = Options.getInteger("audio.recording.rms.high"); int targetHigh = Options.getInteger("audio.recording.rms.high");
long ts = System.currentTimeMillis();
while ((int)getRMS() < targetLow) { while ((int)getRMS() < targetLow) {
if (System.currentTimeMillis() - ts > 10000) {
System.err.println("Aborted gain boost: took too long");
return gain;
}
setGain(gain + 0.1); setGain(gain + 0.1);
if (gain >= 10.0d) break; if (gain >= 10.0d) break;
} }
ts = System.currentTimeMillis();
while ((int)getRMS() > targetHigh) { while ((int)getRMS() > targetHigh) {
if (System.currentTimeMillis() - ts > 10000) {
System.err.println("Aborted gain cut: took too long");
return gain;
}
setGain(gain - 0.1); setGain(gain - 0.1);
} }
@@ -1887,6 +1897,10 @@ public class Sentence extends BookTreeNode implements Cacheable {
} }
public void adjustGainPoint(Integer loc, Double adj) { public void adjustGainPoint(Integer loc, Double adj) {
adjustGainPoint(loc, adj, true);
}
public void adjustGainPoint(Integer loc, Double adj, boolean reload) {
if (gainPoints == null) { if (gainPoints == null) {
gainPoints = new TreeMap<Integer, Double>(); gainPoints = new TreeMap<Integer, Double>();
return; return;
@@ -1895,7 +1909,9 @@ public class Sentence extends BookTreeNode implements Cacheable {
if (gp == null) return; if (gp == null) return;
gp += adj; gp += adj;
gainPoints.put(loc, gp); gainPoints.put(loc, gp);
refreshAllData(); if (reload) {
refreshAllData();
}
} }
public double[] calculateGains() { public double[] calculateGains() {
@@ -1920,7 +1936,10 @@ public class Sentence extends BookTreeNode implements Cacheable {
double ystep = diff / (double)range; double ystep = diff / (double)range;
for (int x = 0; x < range; x++) { for (int x = 0; x < range; x++) {
y += ystep; y += ystep;
gains[x1 + x] = y; try {
gains[x1 + x] = y;
} catch (Exception ex) {
}
} }
x1 = x2; x1 = x2;
} }
@@ -2095,7 +2114,15 @@ public class Sentence extends BookTreeNode implements Cacheable {
} }
public void autoAddPeakGainPoints() { public void autoAddPeakGainPoints() {
long ts = System.currentTimeMillis();
while (true) { while (true) {
if (System.currentTimeMillis() - ts > 10000) {
System.err.println("Terminated: running too long!");
return;
}
processedAudio = null;
double[][] samples = getProcessedAudioData(); double[][] samples = getProcessedAudioData();
int pos = findBiggestPeak(); int pos = findBiggestPeak();
if (pos == -1) return; if (pos == -1) return;
@@ -2136,12 +2163,13 @@ public class Sentence extends BookTreeNode implements Cacheable {
double val = 1d; double val = 1d;
while (isClipping(pos - 10, pos + 10)) { while (isClipping(pos - 10, pos + 10)) {
adjustGainPoint(pos, -0.05); adjustGainPoint(pos, -0.05, false);
val -= 0.05d; val -= 0.05d;
if (val < 0.1d) { if (val < 0.1d) {
System.err.println("Aborting: gain too low"); System.err.println("Aborting: gain too low");
break; break;
} }
processedAudio = null; // Force a refresh
} }
System.err.println("Result: " + gainPoints.get(pos)); System.err.println("Result: " + gainPoints.get(pos));
try { try {