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 String SPHINX_MODEL = "resource:/edu/cmu/sphinx/models/en-us/en-us";
static Properties config = new Properties();
HashMap<String, EffectGroup> effects;
@@ -72,8 +74,6 @@ public class AudiobookRecorder extends JFrame {
JScrollPane mainScroll;
JDialog equaliserWindow = null;
Book book = null;
JTree bookTree;
@@ -116,7 +116,7 @@ public class AudiobookRecorder extends JFrame {
void initSphinx() {
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.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
@@ -821,7 +821,7 @@ public class AudiobookRecorder extends JFrame {
try {
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.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);
}
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) {
sampleWaveform.setPlayMarker(pos / format.getFrameSize());
int l = data.length - pos;
@@ -2121,7 +2131,6 @@ public class AudiobookRecorder extends JFrame {
play.write(data, pos, l);
}
DefaultMutableTreeNode next = s.getNextSibling();
boolean last = false;
if (next == null) {
last = true;
@@ -2860,6 +2869,9 @@ System.err.println(format);
while (effectChain.getItemCount() > 0) {
effectChain.removeItemAt(0);
}
KVPair<String, String> none = new KVPair<String, String>("none", "None");
effectChain.addItem(none);
for (String k : effects.keySet()) {
Effect e = effects.get(k);
KVPair<String, String> p = new KVPair<String, String>(k, e.toString());
@@ -2890,4 +2902,8 @@ System.err.println(format);
updateWaveform();
}
}
public String getDefaultEffectsChain() {
return defaultEffectChain;
}
}

View File

@@ -503,7 +503,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
while ((result = recognizer.getResult()) != null) {
res += result.getHypothesis();
res += " ";
System.err.println(res);
}
recognizer.stopRecognition();
@@ -520,7 +519,7 @@ System.err.println(res);
try {
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.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
@@ -925,8 +924,6 @@ System.err.println(res);
return samples;
}
public void loadFile() {
if (audioData != null) return;
@@ -963,13 +960,9 @@ System.err.println(res);
}
// 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) {
eff.init(getAudioFormat().getFrameRate());
@@ -978,12 +971,15 @@ System.err.println(res);
}
}
// 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
for (int i = 0; i < samples.length; i++) {
@@ -1031,7 +1027,7 @@ System.err.println(res);
}
public String getEffectChain() {
if (effectChain == null) return AudiobookRecorder.window.defaultEffectChain;
if (effectChain == null) return "none";
return effectChain;
}
}