Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 02e85fb354 | |||
| 289834021f | |||
| 04fea4acb2 | |||
| 54739b0a75 | |||
| ea5520a729 | |||
| 0a19d8d308 | |||
| 4dbe3e23b7 | |||
| c43cfc3b69 |
@@ -1 +1 @@
|
||||
version=0.1.8
|
||||
version=0.1.9
|
||||
|
||||
@@ -31,23 +31,23 @@ public class AGC implements Effect {
|
||||
double absSampleLeft = Math.abs(samples[i][Sentence.LEFT]) * gain;
|
||||
double absSampleRight = Math.abs(samples[i][Sentence.RIGHT]) * gain;
|
||||
|
||||
double factor = 0.0d;
|
||||
|
||||
if (absSampleLeft > ceiling) {
|
||||
gain -= attack;
|
||||
if (gain < 0) gain = 0;
|
||||
factor = -attack;
|
||||
}
|
||||
|
||||
if (absSampleRight > ceiling) {
|
||||
gain -= attack;
|
||||
if (gain < 0) gain = 0;
|
||||
factor = -attack;
|
||||
}
|
||||
|
||||
if ((absSampleLeft < ceiling) && (absSampleRight < ceiling)) {
|
||||
gain += decay;
|
||||
if (gain > limit) {
|
||||
gain = limit;
|
||||
}
|
||||
factor = decay;
|
||||
}
|
||||
|
||||
gain += factor;
|
||||
if (gain > limit) gain = limit;
|
||||
|
||||
samples[i][Sentence.LEFT] *= gain;
|
||||
samples[i][Sentence.RIGHT] *= gain;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import edu.cmu.sphinx.api.*;
|
||||
import edu.cmu.sphinx.decoder.adaptation.*;
|
||||
import edu.cmu.sphinx.result.*;
|
||||
import org.w3c.dom.Node;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
public class AudiobookRecorder extends JFrame {
|
||||
|
||||
@@ -38,6 +39,11 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
String defaultEffectChain = "none";
|
||||
|
||||
public final static int IDLE = 0;
|
||||
public final static int RECORDING = 1;
|
||||
public final static int STOPPING = 2;
|
||||
public int state = IDLE;
|
||||
|
||||
MainToolBar toolBar;
|
||||
|
||||
JMenuBar menuBar;
|
||||
@@ -548,6 +554,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
int i = effectChain.getSelectedIndex();
|
||||
KVPair<String, String> p = effectChain.getItemAt(i);
|
||||
if (p == null) return;
|
||||
CacheManager.removeFromCache(selectedSentence);
|
||||
selectedSentence.setEffectChain(p.getKey());
|
||||
updateWaveform();
|
||||
}
|
||||
@@ -591,8 +598,13 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
centralPanel.getActionMap().put("startRecord", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (bookTree.isEditing()) return;
|
||||
if (!getLock()) return;
|
||||
if (bookTree.isEditing()) {
|
||||
freeLock();
|
||||
return;
|
||||
}
|
||||
if (getNoiseFloor() == 0) {
|
||||
freeLock();
|
||||
alertNoRoomNoise();
|
||||
return;
|
||||
}
|
||||
@@ -601,8 +613,13 @@ public class AudiobookRecorder extends JFrame {
|
||||
});
|
||||
centralPanel.getActionMap().put("startRecordShort", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (bookTree.isEditing()) return;
|
||||
if (!getLock()) return;
|
||||
if (bookTree.isEditing()) {
|
||||
freeLock();
|
||||
return;
|
||||
}
|
||||
if (getNoiseFloor() == 0) {
|
||||
freeLock();
|
||||
alertNoRoomNoise();
|
||||
return;
|
||||
}
|
||||
@@ -611,9 +628,14 @@ public class AudiobookRecorder extends JFrame {
|
||||
});
|
||||
centralPanel.getActionMap().put("startRecordNewPara", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (bookTree.isEditing()) return;
|
||||
if (!getLock()) return;
|
||||
if (bookTree.isEditing()) {
|
||||
freeLock();
|
||||
return;
|
||||
}
|
||||
if (getNoiseFloor() == 0) {
|
||||
alertNoRoomNoise();
|
||||
freeLock();
|
||||
return;
|
||||
}
|
||||
startRecordingNewParagraph();
|
||||
@@ -621,8 +643,13 @@ public class AudiobookRecorder extends JFrame {
|
||||
});
|
||||
centralPanel.getActionMap().put("startRecordNewSection", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (bookTree.isEditing()) return;
|
||||
if (!getLock()) return;
|
||||
if (bookTree.isEditing()) {
|
||||
freeLock();
|
||||
return;
|
||||
}
|
||||
if (getNoiseFloor() == 0) {
|
||||
freeLock();
|
||||
alertNoRoomNoise();
|
||||
return;
|
||||
}
|
||||
@@ -631,8 +658,13 @@ public class AudiobookRecorder extends JFrame {
|
||||
});
|
||||
centralPanel.getActionMap().put("startRerecord", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (bookTree.isEditing()) return;
|
||||
if (!getLock()) return;
|
||||
if (bookTree.isEditing()) {
|
||||
freeLock();
|
||||
return;
|
||||
}
|
||||
if (getNoiseFloor() == 0) {
|
||||
freeLock();
|
||||
alertNoRoomNoise();
|
||||
return;
|
||||
}
|
||||
@@ -642,7 +674,9 @@ public class AudiobookRecorder extends JFrame {
|
||||
centralPanel.getActionMap().put("stopRecord", new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (bookTree.isEditing()) return;
|
||||
stopLock();
|
||||
stopRecording();
|
||||
freeLock();
|
||||
}
|
||||
});
|
||||
centralPanel.getActionMap().put("deleteLast", new AbstractAction() {
|
||||
@@ -2668,6 +2702,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
public void loadEffectsFromFolder(File dir) {
|
||||
if (dir == null) return;
|
||||
if (!dir.exists()) return;
|
||||
File[] files = dir.listFiles();
|
||||
for (File f : files) {
|
||||
if (f.getName().endsWith(".eff")) {
|
||||
@@ -2949,4 +2984,32 @@ public class AudiobookRecorder extends JFrame {
|
||||
public String getDefaultEffectsChain() {
|
||||
return defaultEffectChain;
|
||||
}
|
||||
|
||||
public synchronized boolean getLock() {
|
||||
if (state == RECORDING) return false;
|
||||
|
||||
int counts = 0;
|
||||
while (state == STOPPING) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
counts++;
|
||||
if (counts > 100) return false;
|
||||
}
|
||||
|
||||
state = RECORDING;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void freeLock() {
|
||||
state = IDLE;
|
||||
}
|
||||
|
||||
public void stopLock() {
|
||||
state = STOPPING;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,9 +18,16 @@ public class CacheManager {
|
||||
}
|
||||
|
||||
cache.add(c);
|
||||
|
||||
System.gc();
|
||||
}
|
||||
|
||||
public static void setCacheSize(int c) {
|
||||
cacheSize = c;
|
||||
}
|
||||
|
||||
public static void removeFromCache(Cacheable c) {
|
||||
cache.remove(c);
|
||||
c.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ public class Options extends JDialog {
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
cacheSize = addSpinner(optionsPanel, "Cache size:", 0, 5000, 1, getInteger("cache.size"), "");
|
||||
cacheSize = addSpinner(optionsPanel, "Cache size:", 2, 100, 1, getInteger("cache.size"), "");
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
tabs.add("Options", new JScrollPane(optionsPanel));
|
||||
|
||||
@@ -68,7 +68,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
double[][] audioData = null;
|
||||
|
||||
// double[][] processedAudio = null;
|
||||
double[][] processedAudio = null;
|
||||
|
||||
RecordingThread recordingThread;
|
||||
|
||||
@@ -94,7 +94,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
try {
|
||||
running = true;
|
||||
recording = true;
|
||||
byte[] buf = new byte[AudiobookRecorder.window.microphone.getBufferSize()];
|
||||
byte[] buf = new byte[1024]; //AudiobookRecorder.window.microphone.getBufferSize()];
|
||||
FileOutputStream fos = new FileOutputStream(tempFile);
|
||||
int len = 0;
|
||||
AudiobookRecorder.window.microphone.flush();
|
||||
@@ -160,6 +160,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
return false;
|
||||
}
|
||||
|
||||
CacheManager.removeFromCache(this);
|
||||
|
||||
recordingThread = new RecordingThread(getTempFile(), getFile(), Options.getAudioFormat());
|
||||
|
||||
@@ -180,10 +181,10 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
}
|
||||
|
||||
CacheManager.removeFromCache(this);
|
||||
|
||||
audioData = null;
|
||||
// processedAudio = null;
|
||||
storedFormat = null;
|
||||
storedLength = -1;
|
||||
processedAudio = null;
|
||||
|
||||
if (!id.equals("room-noise")) {
|
||||
String tm = Options.get("audio.recording.trim");
|
||||
@@ -196,6 +197,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
recognise();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final int FFTBuckets = 1024;
|
||||
@@ -213,7 +215,11 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
} else {
|
||||
samples = getProcessedAudioData();
|
||||
}
|
||||
if (samples == null) return;
|
||||
if (samples == null) {
|
||||
System.err.println("Error: loading data failed!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int blocks = samples.length / 4096 + 1;
|
||||
|
||||
@@ -252,6 +258,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
block++;
|
||||
}
|
||||
|
||||
|
||||
int limit = Options.getInteger("audio.recording.trim.fft");
|
||||
|
||||
// Find first block with > 1 intensity and subtract one.
|
||||
@@ -288,7 +295,10 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
if (endOffset <= startOffset) endOffset = startOffset + 4096;
|
||||
if (endOffset < 0) endOffset = 0;
|
||||
if (endOffset >= samples.length) endOffset = samples.length;
|
||||
updateCrossings();
|
||||
updateCrossings(useRaw);
|
||||
intens = null;
|
||||
samples = null;
|
||||
System.gc();
|
||||
|
||||
}
|
||||
|
||||
@@ -343,7 +353,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
if (startOffset < 0) startOffset = 0;
|
||||
if (endOffset >= samples.length) endOffset = samples.length-1;
|
||||
updateCrossings();
|
||||
updateCrossings(useRaw);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@@ -427,19 +437,31 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
public void updateCrossings() {
|
||||
updateStartCrossing();
|
||||
updateEndCrossing();
|
||||
updateCrossings(false);
|
||||
}
|
||||
|
||||
public void updateCrossings(boolean useRaw) {
|
||||
updateStartCrossing(useRaw);
|
||||
updateEndCrossing(useRaw);
|
||||
}
|
||||
|
||||
public void updateStartCrossing() {
|
||||
updateStartCrossing(false);
|
||||
}
|
||||
|
||||
public void updateStartCrossing(boolean useRaw) {
|
||||
if (crossStartOffset == -1) {
|
||||
crossStartOffset = findNearestZeroCrossing(startOffset, 4096);
|
||||
crossStartOffset = findNearestZeroCrossing(useRaw, startOffset, 4096);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateEndCrossing() {
|
||||
updateEndCrossing(false);
|
||||
}
|
||||
|
||||
public void updateEndCrossing(boolean useRaw) {
|
||||
if (crossEndOffset == -1) {
|
||||
crossEndOffset = findNearestZeroCrossing(endOffset, 4096);
|
||||
crossEndOffset = findNearestZeroCrossing(useRaw, endOffset, 4096);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,7 +580,9 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
public void clearCache() {
|
||||
audioData = null;
|
||||
// processedAudio = null;
|
||||
processedAudio = null;
|
||||
storedFormat = null;
|
||||
storedLength = -1;
|
||||
}
|
||||
|
||||
public boolean lockedInCache() {
|
||||
@@ -566,7 +590,16 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
public int findNearestZeroCrossing(int pos, int range) {
|
||||
double[][] data = getProcessedAudioData();
|
||||
return findNearestZeroCrossing(false, pos, range);
|
||||
}
|
||||
|
||||
public int findNearestZeroCrossing(boolean useRaw, int pos, int range) {
|
||||
double[][] data = null;
|
||||
if (useRaw) {
|
||||
data = getRawAudioData();
|
||||
} else {
|
||||
data = getProcessedAudioData();
|
||||
}
|
||||
if (data == null) return 0;
|
||||
if (data.length == 0) return 0;
|
||||
|
||||
@@ -640,9 +673,18 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
public double getPeakValue() {
|
||||
return getPeakValue(false);
|
||||
}
|
||||
|
||||
public double getPeakValue(boolean useRaw) {
|
||||
double oldGain = gain;
|
||||
gain = 1.0d;
|
||||
double[][] samples = getProcessedAudioData();
|
||||
double[][] samples = null;
|
||||
if (useRaw) {
|
||||
samples = getRawAudioData();
|
||||
} else {
|
||||
samples = getProcessedAudioData();
|
||||
}
|
||||
gain = oldGain;
|
||||
if (samples == null) {
|
||||
return 0;
|
||||
@@ -930,10 +972,16 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
public void loadFile() {
|
||||
if (audioData != null) return;
|
||||
if (audioData != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
File f = getFile();
|
||||
try {
|
||||
if (!f.exists()) {
|
||||
System.err.println("TODO: Race condition: wav file doesn't exist yet");
|
||||
return;
|
||||
}
|
||||
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
||||
AudioFormat format = getAudioFormat();
|
||||
|
||||
@@ -953,6 +1001,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
audioData = samples;
|
||||
CacheManager.addToCache(this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -963,10 +1012,10 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
synchronized public double[][] getProcessedAudioData() {
|
||||
loadFile();
|
||||
// if (processedAudio != null) return processedAudio;
|
||||
if (processedAudio != null) return processedAudio;
|
||||
|
||||
if (audioData == null) return null;
|
||||
double[][] processedAudio = new double[audioData.length][2];
|
||||
processedAudio = new double[audioData.length][2];
|
||||
for (int i = 0; i < audioData.length; i++) {
|
||||
processedAudio[i][LEFT] = audioData[i][LEFT];
|
||||
processedAudio[i][RIGHT] = audioData[i][RIGHT];
|
||||
@@ -998,6 +1047,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
processedAudio[i][LEFT] *= gain;
|
||||
processedAudio[i][RIGHT] *= gain;
|
||||
}
|
||||
|
||||
return processedAudio;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,4 +63,17 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static long millis = System.currentTimeMillis();
|
||||
|
||||
public static void report(String tag) {
|
||||
long t = System.currentTimeMillis();
|
||||
long d = t - millis;
|
||||
millis = t;
|
||||
System.err.println(String.format("%10d - %10s : %8d | %8d | %8d", d, tag,
|
||||
Runtime.getRuntime().totalMemory(),
|
||||
Runtime.getRuntime().maxMemory(),
|
||||
Runtime.getRuntime().freeMemory()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user