Make effects two-layerd

This commit is contained in:
2019-07-20 23:03:05 +01:00
parent ebf961449a
commit 7545e33d2f
2 changed files with 36 additions and 24 deletions

View File

@@ -31,6 +31,8 @@ public class AudiobookRecorder extends JFrame {
public static final int PLAYBACK_CHUNK_SIZE = 256; // Was 1024 public static final int PLAYBACK_CHUNK_SIZE = 256; // Was 1024
public static final String SPHINX_MODEL = "resource:/edu/cmu/sphinx/models/en-us/en-us";
static Properties config = new Properties(); static Properties config = new Properties();
HashMap<String, EffectGroup> effects; HashMap<String, EffectGroup> effects;
@@ -72,8 +74,6 @@ public class AudiobookRecorder extends JFrame {
JScrollPane mainScroll; JScrollPane mainScroll;
JDialog equaliserWindow = null;
Book book = null; Book book = null;
JTree bookTree; JTree bookTree;
@@ -116,7 +116,7 @@ public class AudiobookRecorder extends JFrame {
void initSphinx() { void initSphinx() {
sphinxConfig = new Configuration(); sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us"); sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict"); sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin"); sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
@@ -821,7 +821,7 @@ public class AudiobookRecorder extends JFrame {
try { try {
Configuration sphinxConfig = new Configuration(); Configuration sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us"); sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict"); sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin"); sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
@@ -2114,6 +2114,16 @@ public class AudiobookRecorder extends JFrame {
play.write(data, 0, data.length); play.write(data, 0, data.length);
} }
data = s.getPCMData(); data = s.getPCMData();
DefaultMutableTreeNode next = s.getNextSibling();
if (next != null) {
Thread t = new Thread(new Runnable() {
public void run() {
Sentence ns = (Sentence)next;
ns.loadFile(); // Cache it
}
});
t.start();
}
for (int pos = 0; pos < data.length; pos += PLAYBACK_CHUNK_SIZE) { for (int pos = 0; pos < data.length; pos += PLAYBACK_CHUNK_SIZE) {
sampleWaveform.setPlayMarker(pos / format.getFrameSize()); sampleWaveform.setPlayMarker(pos / format.getFrameSize());
int l = data.length - pos; int l = data.length - pos;
@@ -2121,7 +2131,6 @@ public class AudiobookRecorder extends JFrame {
play.write(data, pos, l); play.write(data, pos, l);
} }
DefaultMutableTreeNode next = s.getNextSibling();
boolean last = false; boolean last = false;
if (next == null) { if (next == null) {
last = true; last = true;
@@ -2860,6 +2869,9 @@ System.err.println(format);
while (effectChain.getItemCount() > 0) { while (effectChain.getItemCount() > 0) {
effectChain.removeItemAt(0); effectChain.removeItemAt(0);
} }
KVPair<String, String> none = new KVPair<String, String>("none", "None");
effectChain.addItem(none);
for (String k : effects.keySet()) { for (String k : effects.keySet()) {
Effect e = effects.get(k); Effect e = effects.get(k);
KVPair<String, String> p = new KVPair<String, String>(k, e.toString()); KVPair<String, String> p = new KVPair<String, String>(k, e.toString());
@@ -2890,4 +2902,8 @@ System.err.println(format);
updateWaveform(); updateWaveform();
} }
} }
public String getDefaultEffectsChain() {
return defaultEffectChain;
}
} }

View File

@@ -503,7 +503,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
while ((result = recognizer.getResult()) != null) { while ((result = recognizer.getResult()) != null) {
res += result.getHypothesis(); res += result.getHypothesis();
res += " "; res += " ";
System.err.println(res);
} }
recognizer.stopRecognition(); recognizer.stopRecognition();
@@ -520,7 +519,7 @@ System.err.println(res);
try { try {
Configuration sphinxConfig = new Configuration(); Configuration sphinxConfig = new Configuration();
sphinxConfig.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us"); sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict"); sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin"); sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
@@ -925,8 +924,6 @@ System.err.println(res);
return samples; return samples;
} }
public void loadFile() { public void loadFile() {
if (audioData != null) return; if (audioData != null) return;
@@ -963,28 +960,27 @@ System.err.println(res);
} }
// Add processing in here. // Add processing in here.
if (effectChain == null) effectChain = AudiobookRecorder.window.defaultEffectChain;
Effect eff = AudiobookRecorder.window.effects.get(effectChain);
if (eff == null) {
effectChain = AudiobookRecorder.window.defaultEffectChain;
eff = AudiobookRecorder.window.effects.get(effectChain);
}
String def = AudiobookRecorder.window.getDefaultEffectsChain();
Effect eff = AudiobookRecorder.window.effects.get(def);
if (eff != null) { if (eff != null) {
eff.init(getAudioFormat().getFrameRate()); eff.init(getAudioFormat().getFrameRate());
for (int i = 0; i < samples.length; i++) { for (int i = 0; i < samples.length; i++) {
samples[i] = eff.process(samples[i]); samples[i] = eff.process(samples[i]);
} }
} }
// Cuts out the computer hum.
// Biquad bq = new Biquad(Biquad.Notch, 140d/44100d, 20.0d, -50);
// DelayLine dl = new DelayLine();
// dl.addDelayLine(2205, 0.8);
// dl.addDelayLine(4410, 0.4);
// dl.addDelayLine(6615, 0.2);
if (effectChain != null) {
eff = AudiobookRecorder.window.effects.get(effectChain);
if (eff != null) {
eff.init(getAudioFormat().getFrameRate());
for (int i = 0; i < samples.length; i++) {
samples[i] = eff.process(samples[i]);
}
}
}
// Add final master gain stage // Add final master gain stage
for (int i = 0; i < samples.length; i++) { for (int i = 0; i < samples.length; i++) {
samples[i] = samples[i] * gain; samples[i] = samples[i] * gain;
@@ -1031,7 +1027,7 @@ System.err.println(res);
} }
public String getEffectChain() { public String getEffectChain() {
if (effectChain == null) return AudiobookRecorder.window.defaultEffectChain; if (effectChain == null) return "none";
return effectChain; return effectChain;
} }
} }