More improvements to gain curve
This commit is contained in:
@@ -8,8 +8,10 @@ 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 != null) {
|
||||||
if (ob.lockedInCache()) {
|
if (ob.lockedInCache()) {
|
||||||
cache.add(ob);
|
cache.add(ob);
|
||||||
} else {
|
} else {
|
||||||
@@ -19,6 +21,7 @@ public class CacheManager {
|
|||||||
ob.clearCache();
|
ob.clearCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cache.add(c);
|
cache.add(c);
|
||||||
}
|
}
|
||||||
@@ -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,8 +1909,10 @@ 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);
|
||||||
|
if (reload) {
|
||||||
refreshAllData();
|
refreshAllData();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public double[] calculateGains() {
|
public double[] calculateGains() {
|
||||||
double[] gains = new double[sampleSize];
|
double[] gains = new double[sampleSize];
|
||||||
@@ -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;
|
||||||
|
try {
|
||||||
gains[x1 + x] = y;
|
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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user