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

View File

@@ -8,15 +8,18 @@ public class CacheManager {
static int cacheSize = 10;
public static void addToCache(Cacheable c) {
Debug.trace();
while (cache.size() >= cacheSize) {
Cacheable ob = cache.remove(0);
if (ob.lockedInCache()) {
cache.add(ob);
} else {
if (ob instanceof Sentence) {
Sentence s = (Sentence)ob;
if (ob != null) {
if (ob.lockedInCache()) {
cache.add(ob);
} else {
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) {
Debug.trace();
if (c instanceof Sentence) {
Sentence s = (Sentence)c;
}

View File

@@ -978,12 +978,22 @@ public class Sentence extends BookTreeNode implements Cacheable {
int targetLow = Options.getInteger("audio.recording.rms.low");
int targetHigh = Options.getInteger("audio.recording.rms.high");
long ts = System.currentTimeMillis();
while ((int)getRMS() < targetLow) {
if (System.currentTimeMillis() - ts > 10000) {
System.err.println("Aborted gain boost: took too long");
return gain;
}
setGain(gain + 0.1);
if (gain >= 10.0d) break;
}
ts = System.currentTimeMillis();
while ((int)getRMS() > targetHigh) {
if (System.currentTimeMillis() - ts > 10000) {
System.err.println("Aborted gain cut: took too long");
return gain;
}
setGain(gain - 0.1);
}
@@ -1887,6 +1897,10 @@ public class Sentence extends BookTreeNode implements Cacheable {
}
public void adjustGainPoint(Integer loc, Double adj) {
adjustGainPoint(loc, adj, true);
}
public void adjustGainPoint(Integer loc, Double adj, boolean reload) {
if (gainPoints == null) {
gainPoints = new TreeMap<Integer, Double>();
return;
@@ -1895,7 +1909,9 @@ public class Sentence extends BookTreeNode implements Cacheable {
if (gp == null) return;
gp += adj;
gainPoints.put(loc, gp);
refreshAllData();
if (reload) {
refreshAllData();
}
}
public double[] calculateGains() {
@@ -1920,7 +1936,10 @@ public class Sentence extends BookTreeNode implements Cacheable {
double ystep = diff / (double)range;
for (int x = 0; x < range; x++) {
y += ystep;
gains[x1 + x] = y;
try {
gains[x1 + x] = y;
} catch (Exception ex) {
}
}
x1 = x2;
}
@@ -2095,7 +2114,15 @@ public class Sentence extends BookTreeNode implements Cacheable {
}
public void autoAddPeakGainPoints() {
long ts = System.currentTimeMillis();
while (true) {
if (System.currentTimeMillis() - ts > 10000) {
System.err.println("Terminated: running too long!");
return;
}
processedAudio = null;
double[][] samples = getProcessedAudioData();
int pos = findBiggestPeak();
if (pos == -1) return;
@@ -2136,12 +2163,13 @@ public class Sentence extends BookTreeNode implements Cacheable {
double val = 1d;
while (isClipping(pos - 10, pos + 10)) {
adjustGainPoint(pos, -0.05);
adjustGainPoint(pos, -0.05, false);
val -= 0.05d;
if (val < 0.1d) {
System.err.println("Aborting: gain too low");
break;
}
processedAudio = null; // Force a refresh
}
System.err.println("Result: " + gainPoints.get(pos));
try {