Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| babd3d2052 | |||
| 9464839b4d | |||
| bcf7875414 | |||
| 732894a0fb | |||
| 146bf5a3c2 | |||
| b05bfde094 | |||
| 37d372b8f5 | |||
| c01fee3b73 | |||
| c907e735c6 | |||
| 7545e33d2f | |||
| ebf961449a | |||
| 45d6882527 | |||
| 2ec370ad61 |
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
Normal file
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
Normal file
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
Normal file
Binary file not shown.
@@ -1 +1 @@
|
|||||||
version=0.1.6
|
version=0.1.8
|
||||||
|
|||||||
@@ -25,27 +25,36 @@ public class AGC implements Effect {
|
|||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double process(double sample) {
|
public void process(double[][] samples) {
|
||||||
double absSample = Math.abs(sample) * gain;
|
gain = 1d;
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
double absSampleLeft = Math.abs(samples[i][Sentence.LEFT]) * gain;
|
||||||
|
double absSampleRight = Math.abs(samples[i][Sentence.RIGHT]) * gain;
|
||||||
|
|
||||||
if (absSample > ceiling) {
|
if (absSampleLeft > ceiling) {
|
||||||
gain -= attack;
|
gain -= attack;
|
||||||
if (gain < 0) gain = 0;
|
if (gain < 0) gain = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (absSample < ceiling) {
|
if (absSampleRight > ceiling) {
|
||||||
|
gain -= attack;
|
||||||
|
if (gain < 0) gain = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((absSampleLeft < ceiling) && (absSampleRight < ceiling)) {
|
||||||
gain += decay;
|
gain += decay;
|
||||||
if (gain > limit) {
|
if (gain > limit) {
|
||||||
gain = limit;
|
gain = limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sample *= gain;
|
samples[i][Sentence.LEFT] *= gain;
|
||||||
|
samples[i][Sentence.RIGHT] *= gain;
|
||||||
return sample;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(double sr) {
|
public void init(double sr) {
|
||||||
|
gain = 1d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump() {
|
public void dump() {
|
||||||
|
|||||||
@@ -19,8 +19,11 @@ public class Amplifier implements Effect {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double process(double sample) {
|
public void process(double[][] samples) {
|
||||||
return sample * gain;
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
samples[i][Sentence.LEFT] *= gain;
|
||||||
|
samples[i][Sentence.RIGHT] *= gain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getGain() {
|
public double getGain() {
|
||||||
|
|||||||
@@ -20,15 +20,21 @@ import javax.imageio.*;
|
|||||||
import org.w3c.dom.*;
|
import org.w3c.dom.*;
|
||||||
import javax.xml.parsers.*;
|
import javax.xml.parsers.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import edu.cmu.sphinx.api.*;
|
||||||
|
import edu.cmu.sphinx.decoder.adaptation.*;
|
||||||
|
import edu.cmu.sphinx.result.*;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
public class AudiobookRecorder extends JFrame {
|
public class AudiobookRecorder extends JFrame {
|
||||||
|
|
||||||
// Settings - tweakable
|
// Settings - tweakable
|
||||||
|
|
||||||
public static final int PLAYBACK_CHUNK_SIZE = 256; // Was 1024
|
public static final int PLAYBACK_CHUNK_SIZE = 16384;
|
||||||
|
|
||||||
|
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;
|
TreeMap<String, EffectGroup> effects;
|
||||||
|
|
||||||
String defaultEffectChain = "none";
|
String defaultEffectChain = "none";
|
||||||
|
|
||||||
@@ -68,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;
|
||||||
@@ -88,6 +92,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
JSpinner gainPercent;
|
JSpinner gainPercent;
|
||||||
JCheckBox locked;
|
JCheckBox locked;
|
||||||
JCheckBox attention;
|
JCheckBox attention;
|
||||||
|
JCheckBox rawAudio;
|
||||||
|
|
||||||
JButtonSpacePlay reprocessAudioFFT;
|
JButtonSpacePlay reprocessAudioFFT;
|
||||||
JButtonSpacePlay reprocessAudioPeak;
|
JButtonSpacePlay reprocessAudioPeak;
|
||||||
@@ -101,19 +106,32 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
SourceDataLine play = null;
|
SourceDataLine play = null;
|
||||||
|
|
||||||
public HavenQueue havenQueue = new HavenQueue();
|
|
||||||
|
|
||||||
|
|
||||||
public TargetDataLine microphone = null;
|
public TargetDataLine microphone = null;
|
||||||
public AudioInputStream microphoneStream = null;
|
public AudioInputStream microphoneStream = null;
|
||||||
|
|
||||||
|
public Configuration sphinxConfig;
|
||||||
|
public StreamSpeechRecognizer recognizer;
|
||||||
|
|
||||||
public static AudiobookRecorder window;
|
public static AudiobookRecorder window;
|
||||||
|
|
||||||
|
void initSphinx() {
|
||||||
|
sphinxConfig = new Configuration();
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
try {
|
||||||
|
recognizer = new StreamSpeechRecognizer(sphinxConfig);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void buildToolbar(Container ob) {
|
void buildToolbar(Container ob) {
|
||||||
toolBar = new MainToolBar(this);
|
toolBar = new MainToolBar(this);
|
||||||
toolBar.addSeparator();
|
toolBar.addSeparator();
|
||||||
toolBar.add(Box.createHorizontalGlue());
|
toolBar.add(Box.createHorizontalGlue());
|
||||||
toolBar.add(havenQueue);
|
|
||||||
ob.add(toolBar, BorderLayout.NORTH);
|
ob.add(toolBar, BorderLayout.NORTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +299,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
window = this;
|
window = this;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String clsname = "com.jtattoo.plaf.hifi.HiFiLookAndFeel";
|
String clsname = "com.jtattoo.plaf.hifi.HiFiLookAndFeel";
|
||||||
UIManager.setLookAndFeel(clsname);
|
UIManager.setLookAndFeel(clsname);
|
||||||
|
|
||||||
@@ -295,8 +314,6 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
Method mth = cls.getMethod("setCurrentTheme", cArg);
|
Method mth = cls.getMethod("setCurrentTheme", cArg);
|
||||||
mth.invoke(cls, p);
|
mth.invoke(cls, p);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -440,6 +457,11 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
controlsLeft.add(reprocessAudioPeak);
|
controlsLeft.add(reprocessAudioPeak);
|
||||||
controlsLeft.add(normalizeAudio);
|
controlsLeft.add(normalizeAudio);
|
||||||
|
|
||||||
|
rawAudio = new JCheckBox("Raw Audio");
|
||||||
|
rawAudio.setFocusable(false);
|
||||||
|
|
||||||
|
controlsTop.add(rawAudio);
|
||||||
|
|
||||||
locked = new JCheckBox("Phrase locked");
|
locked = new JCheckBox("Phrase locked");
|
||||||
locked.setFocusable(false);
|
locked.setFocusable(false);
|
||||||
|
|
||||||
@@ -562,6 +584,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released D"), "deleteLast");
|
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released D"), "deleteLast");
|
||||||
|
|
||||||
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("SPACE"), "startStopPlayback");
|
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("SPACE"), "startStopPlayback");
|
||||||
|
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK), "startPlaybackFrom");
|
||||||
|
|
||||||
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("E"), "startRerecord");
|
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("E"), "startRerecord");
|
||||||
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released E"), "stopRecord");
|
centralPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released E"), "stopRecord");
|
||||||
@@ -640,6 +663,15 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
centralPanel.getActionMap().put("startPlaybackFrom", new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (bookTree.isEditing()) return;
|
||||||
|
if (playing == null) {
|
||||||
|
playFromSelectedSentence();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mainScroll = new JScrollPane();
|
mainScroll = new JScrollPane();
|
||||||
centralPanel.add(mainScroll, BorderLayout.CENTER);
|
centralPanel.add(mainScroll, BorderLayout.CENTER);
|
||||||
|
|
||||||
@@ -721,7 +753,6 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
prefs.setProperty("chapter.close.pre-gap", Options.get("catenation.pre-chapter"));
|
prefs.setProperty("chapter.close.pre-gap", Options.get("catenation.pre-chapter"));
|
||||||
prefs.setProperty("chapter.close.post-gap", Options.get("catenation.post-chapter"));
|
prefs.setProperty("chapter.close.post-gap", Options.get("catenation.post-chapter"));
|
||||||
|
|
||||||
loadEffects();
|
|
||||||
buildBook(prefs);
|
buildBook(prefs);
|
||||||
|
|
||||||
Options.set("path.last-book", book.getName());
|
Options.set("path.last-book", book.getName());
|
||||||
@@ -784,6 +815,42 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BatchConversionThread implements Runnable {
|
||||||
|
Chapter chapter;
|
||||||
|
|
||||||
|
public BatchConversionThread(Chapter c) {
|
||||||
|
chapter = c;
|
||||||
|
}
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Configuration sphinxConfig = new Configuration();
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
sphinxConfig.setSampleRate((int)(book.getAudioFormat().getSampleRate() / 4f));
|
||||||
|
|
||||||
|
StreamSpeechRecognizer recognizer;
|
||||||
|
|
||||||
|
recognizer = new StreamSpeechRecognizer(sphinxConfig);
|
||||||
|
|
||||||
|
|
||||||
|
for (Enumeration s = chapter.children(); s.hasMoreElements();) {
|
||||||
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
|
if (!snt.isLocked()) {
|
||||||
|
if (snt.getId().equals(snt.getText())) {
|
||||||
|
snt.doRecognition(recognizer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
void treePopup(MouseEvent e) {
|
void treePopup(MouseEvent e) {
|
||||||
|
|
||||||
@@ -805,7 +872,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Sentence s = (Sentence)o.getObject();
|
Sentence s = (Sentence)o.getObject();
|
||||||
if (!s.isLocked()) {
|
if (!s.isLocked()) {
|
||||||
havenQueue.submit(s);
|
s.recognise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1115,12 +1182,9 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JMenuObject o = (JMenuObject)e.getSource();
|
JMenuObject o = (JMenuObject)e.getSource();
|
||||||
Chapter c = (Chapter)o.getObject();
|
Chapter c = (Chapter)o.getObject();
|
||||||
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
BatchConversionThread r = new BatchConversionThread(c);
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Thread t = new Thread(r);
|
||||||
if (snt.getId().equals(snt.getText())) {
|
t.start();
|
||||||
havenQueue.submit(snt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1624,7 +1688,6 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
prefs.loadFromXML(fis);
|
prefs.loadFromXML(fis);
|
||||||
|
|
||||||
File r = f.getParentFile();
|
File r = f.getParentFile();
|
||||||
loadEffects();
|
|
||||||
|
|
||||||
buildBook(prefs);
|
buildBook(prefs);
|
||||||
|
|
||||||
@@ -1656,6 +1719,8 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
book.setComment(prefs.getProperty("book.comment"));
|
book.setComment(prefs.getProperty("book.comment"));
|
||||||
book.setACX(prefs.getProperty("book.acx"));
|
book.setACX(prefs.getProperty("book.acx"));
|
||||||
|
|
||||||
|
loadEffects();
|
||||||
|
|
||||||
defaultEffectChain = prefs.getProperty("audio.effect.default");
|
defaultEffectChain = prefs.getProperty("audio.effect.default");
|
||||||
if (defaultEffectChain == null) {
|
if (defaultEffectChain == null) {
|
||||||
defaultEffectChain = "none";
|
defaultEffectChain = "none";
|
||||||
@@ -1689,6 +1754,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
InputMap im = bookTree.getInputMap(JComponent.WHEN_FOCUSED);
|
InputMap im = bookTree.getInputMap(JComponent.WHEN_FOCUSED);
|
||||||
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "startStopPlayback");
|
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "startStopPlayback");
|
||||||
|
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK), "startPlaybackFrom");
|
||||||
|
|
||||||
roomNoise = new Sentence("room-noise", "Room Noise");
|
roomNoise = new Sentence("room-noise", "Room Noise");
|
||||||
|
|
||||||
@@ -1882,14 +1948,14 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
public double getNoiseFloor() {
|
public double getNoiseFloor() {
|
||||||
if (roomNoise == null) return 0;
|
if (roomNoise == null) return 0;
|
||||||
double[] samples = roomNoise.getDoubleAudioData();
|
double[][] samples = roomNoise.getDoubleAudioData();
|
||||||
if (samples == null) {
|
if (samples == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
double ms = 0;
|
double ms = 0;
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
if (Math.abs(samples[i]) > ms) {
|
if (Math.abs((samples[i][Sentence.LEFT] + samples[i][Sentence.RIGHT]) / 2d) > ms) {
|
||||||
ms = Math.abs(samples[i]);
|
ms = Math.abs((samples[i][Sentence.LEFT] + samples[i][Sentence.RIGHT]) / 2d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1940,7 +2006,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
AudioFormat sampleformat = s.getAudioFormat();
|
AudioFormat sampleformat = s.getAudioFormat();
|
||||||
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 1, true, false);
|
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false);
|
||||||
|
|
||||||
play = AudioSystem.getSourceDataLine(format, Options.getPlaybackMixer());
|
play = AudioSystem.getSourceDataLine(format, Options.getPlaybackMixer());
|
||||||
play.open(format);
|
play.open(format);
|
||||||
@@ -2034,7 +2100,7 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
AudioFormat sampleformat = s.getAudioFormat();
|
AudioFormat sampleformat = s.getAudioFormat();
|
||||||
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 1, true, false);
|
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false);
|
||||||
play = AudioSystem.getSourceDataLine(format, Options.getPlaybackMixer());
|
play = AudioSystem.getSourceDataLine(format, Options.getPlaybackMixer());
|
||||||
play.open(format);
|
play.open(format);
|
||||||
play.start();
|
play.start();
|
||||||
@@ -2053,6 +2119,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.getProcessedAudioData(); // 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;
|
||||||
@@ -2060,7 +2136,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;
|
||||||
@@ -2142,7 +2217,6 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
public boolean enableMicrophone() {
|
public boolean enableMicrophone() {
|
||||||
AudioFormat format = Options.getAudioFormat();
|
AudioFormat format = Options.getAudioFormat();
|
||||||
System.err.println(format);
|
|
||||||
|
|
||||||
Mixer.Info mixer = Options.getRecordingMixer();
|
Mixer.Info mixer = Options.getRecordingMixer();
|
||||||
|
|
||||||
@@ -2575,12 +2649,16 @@ System.err.println(format);
|
|||||||
|
|
||||||
public void updateWaveform() {
|
public void updateWaveform() {
|
||||||
if (selectedSentence != null) {
|
if (selectedSentence != null) {
|
||||||
|
if (rawAudio.isSelected()) {
|
||||||
|
sampleWaveform.setData(selectedSentence.getRawAudioData());
|
||||||
|
} else {
|
||||||
sampleWaveform.setData(selectedSentence.getDoubleAudioData());
|
sampleWaveform.setData(selectedSentence.getDoubleAudioData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void loadEffects() {
|
public void loadEffects() {
|
||||||
effects = new HashMap<String,EffectGroup>();
|
effects = new TreeMap<String,EffectGroup>();
|
||||||
loadEffectsFromFolder(new File(Options.get("path.storage"), "System"));
|
loadEffectsFromFolder(new File(Options.get("path.storage"), "System"));
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
loadEffectsFromFolder(new File(Options.get("path.storage"), book.getName()));
|
loadEffectsFromFolder(new File(Options.get("path.storage"), book.getName()));
|
||||||
@@ -2636,11 +2714,21 @@ System.err.println(format);
|
|||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
group.addEffect(eff);
|
group.addEffect(eff);
|
||||||
}
|
}
|
||||||
|
} else if (e.getTagName().equals("pan")) {
|
||||||
|
Effect eff = (Effect)loadPan(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
} else if (e.getTagName().equals("amplifier")) {
|
} else if (e.getTagName().equals("amplifier")) {
|
||||||
Effect eff = (Effect)loadAmplifier(e);
|
Effect eff = (Effect)loadAmplifier(e);
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
group.addEffect(eff);
|
group.addEffect(eff);
|
||||||
}
|
}
|
||||||
|
} else if (e.getTagName().equals("chain")) {
|
||||||
|
Effect eff = (Effect)loadChain(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
} else if (e.getTagName().equals("group")) {
|
} else if (e.getTagName().equals("group")) {
|
||||||
Effect eff = (Effect)loadEffectGroup(e);
|
Effect eff = (Effect)loadEffectGroup(e);
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
@@ -2700,6 +2788,9 @@ System.err.println(format);
|
|||||||
DelayLine line = new DelayLine();
|
DelayLine line = new DelayLine();
|
||||||
|
|
||||||
NodeList list = root.getChildNodes();
|
NodeList list = root.getChildNodes();
|
||||||
|
if (Utils.s2b(root.getAttribute("wetonly"))) {
|
||||||
|
line.setWetOnly(true);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < list.getLength(); i++) {
|
for (int i = 0; i < list.getLength(); i++) {
|
||||||
Node n = list.item(i);
|
Node n = list.item(i);
|
||||||
@@ -2708,7 +2799,9 @@ System.err.println(format);
|
|||||||
if (e.getTagName().equals("delay")) {
|
if (e.getTagName().equals("delay")) {
|
||||||
int samples = Utils.s2i(e.getAttribute("samples"));
|
int samples = Utils.s2i(e.getAttribute("samples"));
|
||||||
double gain = Utils.s2d(e.getAttribute("gain"));
|
double gain = Utils.s2d(e.getAttribute("gain"));
|
||||||
DelayLineStore store = line.addDelayLine(samples, gain);
|
double pan = Utils.s2d(e.getAttribute("pan"));
|
||||||
|
DelayLineStore store = line.addDelayLine(samples, gain, pan);
|
||||||
|
|
||||||
|
|
||||||
NodeList inner = e.getChildNodes();
|
NodeList inner = e.getChildNodes();
|
||||||
for (int j = 0; j < inner.getLength(); j++) {
|
for (int j = 0; j < inner.getLength(); j++) {
|
||||||
@@ -2726,11 +2819,21 @@ System.err.println(format);
|
|||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
store.addEffect(eff);
|
store.addEffect(eff);
|
||||||
}
|
}
|
||||||
|
} else if (ie.getTagName().equals("pan")) {
|
||||||
|
Effect eff = (Effect)loadPan(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
} else if (ie.getTagName().equals("amplifier")) {
|
} else if (ie.getTagName().equals("amplifier")) {
|
||||||
Effect eff = (Effect)loadAmplifier(ie);
|
Effect eff = (Effect)loadAmplifier(ie);
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
store.addEffect(eff);
|
store.addEffect(eff);
|
||||||
}
|
}
|
||||||
|
} else if (ie.getTagName().equals("chain")) {
|
||||||
|
Effect eff = (Effect)loadChain(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
} else if (ie.getTagName().equals("group")) {
|
} else if (ie.getTagName().equals("group")) {
|
||||||
Effect eff = (Effect)loadEffectGroup(ie);
|
Effect eff = (Effect)loadEffectGroup(ie);
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
@@ -2766,6 +2869,16 @@ System.err.println(format);
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Chain loadChain(Element root) {
|
||||||
|
Chain c = new Chain(root.getAttribute("src"));
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pan loadPan(Element root) {
|
||||||
|
Pan p = new Pan(Utils.s2d(root.getAttribute("pan")));
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
public Clipping loadClipping(Element root) {
|
public Clipping loadClipping(Element root) {
|
||||||
Clipping c = new Clipping(Utils.s2d(root.getAttribute("clip")));
|
Clipping c = new Clipping(Utils.s2d(root.getAttribute("clip")));
|
||||||
return c;
|
return c;
|
||||||
@@ -2799,6 +2912,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());
|
||||||
@@ -2829,4 +2945,8 @@ System.err.println(format);
|
|||||||
updateWaveform();
|
updateWaveform();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDefaultEffectsChain() {
|
||||||
|
return defaultEffectChain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ public class Biquad implements Effect {
|
|||||||
int type;
|
int type;
|
||||||
double a0, a1, a2, b1, b2;
|
double a0, a1, a2, b1, b2;
|
||||||
double Fc, Q, peakGain;
|
double Fc, Q, peakGain;
|
||||||
double z1, z2;
|
double lz1, lz2;
|
||||||
|
double rz1, rz2;
|
||||||
double sampleFrequency;
|
double sampleFrequency;
|
||||||
|
|
||||||
public Biquad() {
|
public Biquad() {
|
||||||
@@ -45,15 +46,19 @@ public class Biquad implements Effect {
|
|||||||
Fc = 440d;
|
Fc = 440d;
|
||||||
Q = 0.707d;
|
Q = 0.707d;
|
||||||
peakGain = 0.0d;
|
peakGain = 0.0d;
|
||||||
z1 = 0.0d;
|
lz1 = 0.0d;
|
||||||
z2 = 0.0d;
|
lz2 = 0.0d;
|
||||||
|
rz1 = 0.0d;
|
||||||
|
rz2 = 0.0d;
|
||||||
sampleFrequency = 44100d;
|
sampleFrequency = 44100d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
||||||
setBiquad(type, Fc, Q, peakGainDB);
|
setBiquad(type, Fc, Q, peakGainDB);
|
||||||
z1 = 0.0;
|
lz1 = 0.0;
|
||||||
z2 = 0.0;
|
lz2 = 0.0;
|
||||||
|
rz1 = 0.0;
|
||||||
|
rz2 = 0.0;
|
||||||
sampleFrequency = 44100d;
|
sampleFrequency = 44100d;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,17 +89,33 @@ public class Biquad implements Effect {
|
|||||||
setPeakGain(peakGainDB);
|
setPeakGain(peakGainDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double process(double in) {
|
public void process(double[][] samples) {
|
||||||
double out = in * a0 + z1;
|
lz1 = 0d;
|
||||||
z1 = in * a1 + z2 - b1 * out;
|
lz2 = 0d;
|
||||||
z2 = in * a2 - b2 * out;
|
rz1 = 0d;
|
||||||
return out;
|
rz2 = 0d;
|
||||||
|
for (double[] in : samples) {
|
||||||
|
double lout = in[Sentence.LEFT] * a0 + lz1;
|
||||||
|
|
||||||
|
lz1 = in[Sentence.LEFT] * a1 + lz2 - b1 * lout;
|
||||||
|
lz2 = in[Sentence.LEFT] * a2 - b2 * lout;
|
||||||
|
|
||||||
|
double rout = in[Sentence.RIGHT] * a0 + rz1;
|
||||||
|
|
||||||
|
rz1 = in[Sentence.RIGHT] * a1 + rz2 - b1 * rout;
|
||||||
|
rz2 = in[Sentence.RIGHT] * a2 - b2 * rout;
|
||||||
|
|
||||||
|
in[Sentence.LEFT] = lout;
|
||||||
|
in[Sentence.RIGHT] = rout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(double sf) {
|
public void init(double sf) {
|
||||||
sampleFrequency = sf;
|
sampleFrequency = sf;
|
||||||
z1 = 0d;
|
lz1 = 0d;
|
||||||
z2 = 0d;
|
lz2 = 0d;
|
||||||
|
rz1 = 0d;
|
||||||
|
rz2 = 0d;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
|||||||
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s.getEffectChain() != null) {
|
||||||
|
if (!s.getEffectChain().equals("none")) {
|
||||||
|
icn.add(Overlays.filter, OverlayIcon.BOTTOM_RIGHT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret.setIcon(icn);
|
ret.setIcon(icn);
|
||||||
|
|
||||||
} else if (value instanceof Chapter) {
|
} else if (value instanceof Chapter) {
|
||||||
|
|||||||
58
src/uk/co/majenko/audiobookrecorder/Chain.java
Normal file
58
src/uk/co/majenko/audiobookrecorder/Chain.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Chain implements Effect {
|
||||||
|
String target;
|
||||||
|
|
||||||
|
public Chain(String t) {
|
||||||
|
target = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chain() {
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(double[][] samples) {
|
||||||
|
if (target != null) {
|
||||||
|
Effect t = AudiobookRecorder.window.effects.get(target);
|
||||||
|
if (t != null) {
|
||||||
|
t.process(samples);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarget(String t) {
|
||||||
|
target = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "Chain to " + target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dump() {
|
||||||
|
System.out.println(toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(double sf) {
|
||||||
|
if (target != null) {
|
||||||
|
Effect t = AudiobookRecorder.window.effects.get(target);
|
||||||
|
if (t != null) {
|
||||||
|
t.init(sf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -122,7 +122,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
|
|
||||||
|
|
||||||
AudioFormat sampleformat = AudiobookRecorder.window.roomNoise.getAudioFormat();
|
AudioFormat sampleformat = AudiobookRecorder.window.roomNoise.getAudioFormat();
|
||||||
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 1, true, false);
|
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false);
|
||||||
byte[] data;
|
byte[] data;
|
||||||
|
|
||||||
int fullLength = 0;
|
int fullLength = 0;
|
||||||
|
|||||||
@@ -19,10 +19,13 @@ public class Clipping implements Effect {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double process(double sample) {
|
public void process(double[][] samples) {
|
||||||
if (sample > clip) return clip;
|
for (double[] sample : samples) {
|
||||||
if (sample < -clip) return -clip;
|
if (sample[Sentence.LEFT] > clip) sample[Sentence.LEFT] = clip;
|
||||||
return sample;
|
if (sample[Sentence.LEFT] < -clip) sample[Sentence.LEFT] = -clip;
|
||||||
|
if (sample[Sentence.RIGHT] > clip) sample[Sentence.RIGHT] = clip;
|
||||||
|
if (sample[Sentence.RIGHT] < -clip) sample[Sentence.RIGHT] = -clip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getClip() {
|
public double getClip() {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ public class DelayLine implements Effect {
|
|||||||
|
|
||||||
ArrayList<DelayLineStore> delayLines;
|
ArrayList<DelayLineStore> delayLines;
|
||||||
|
|
||||||
|
boolean wetOnly = false;
|
||||||
|
|
||||||
public DelayLine() {
|
public DelayLine() {
|
||||||
delayLines = new ArrayList<DelayLineStore>();
|
delayLines = new ArrayList<DelayLineStore>();
|
||||||
}
|
}
|
||||||
@@ -14,23 +16,70 @@ public class DelayLine implements Effect {
|
|||||||
return "Delay Line (" + delayLines.size() + " lines)";
|
return "Delay Line (" + delayLines.size() + " lines)";
|
||||||
}
|
}
|
||||||
|
|
||||||
public double process(double sample) {
|
public void process(double[][] samples) {
|
||||||
double s = sample;
|
double[][] savedSamples = new double[samples.length][2];
|
||||||
for (DelayLineStore d : delayLines) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
double echo = d.pass(sample);
|
savedSamples[i][Sentence.LEFT] = samples[i][Sentence.LEFT];
|
||||||
s = mix(s, echo);
|
savedSamples[i][Sentence.RIGHT] = samples[i][Sentence.RIGHT];
|
||||||
|
}
|
||||||
|
if (wetOnly) {
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
samples[i][Sentence.LEFT] = 0d;
|
||||||
|
samples[i][Sentence.RIGHT] = 0d;
|
||||||
}
|
}
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double mix(double a, double b) {
|
double[][] subSamples = new double[samples.length][2];
|
||||||
if ((a < 0) && (b < 0)) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
return (a + b) - (a * b);
|
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
||||||
|
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
||||||
}
|
}
|
||||||
if ((a > 0) && (b > 0)) {
|
for (DelayLineStore d : delayLines) {
|
||||||
return (a + b) - (a * b);
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
||||||
|
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
||||||
}
|
}
|
||||||
return a + b;
|
|
||||||
|
d.process(subSamples);
|
||||||
|
|
||||||
|
for (int i = 0; i < subSamples.length; i++) {
|
||||||
|
int off = i + d.getSamples();
|
||||||
|
if ((off < samples.length) && (off > 0)) {
|
||||||
|
|
||||||
|
double[] ns = mix(samples[off], subSamples[i]);
|
||||||
|
samples[off][Sentence.LEFT] = ns[Sentence.LEFT];
|
||||||
|
samples[off][Sentence.RIGHT] = ns[Sentence.RIGHT];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double[] mix(double[] a, double[] b) {
|
||||||
|
double[] out = new double[2];
|
||||||
|
|
||||||
|
if ((a[Sentence.LEFT] < 0) && (b[Sentence.LEFT] < 0)) {
|
||||||
|
out[Sentence.LEFT] = (a[Sentence.LEFT] + b[Sentence.LEFT]) - (a[Sentence.LEFT] * b[Sentence.LEFT]);
|
||||||
|
} else if ((a[Sentence.LEFT] > 0) && (b[Sentence.LEFT] > 0)) {
|
||||||
|
out[Sentence.LEFT] = (a[Sentence.LEFT] + b[Sentence.LEFT]) - (a[Sentence.LEFT] * b[Sentence.LEFT]);
|
||||||
|
} else {
|
||||||
|
out[Sentence.LEFT] = a[Sentence.LEFT] + b[Sentence.LEFT];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((a[Sentence.RIGHT] < 0) && (b[Sentence.RIGHT] < 0)) {
|
||||||
|
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
||||||
|
} else if ((a[Sentence.RIGHT] > 0) && (b[Sentence.RIGHT] > 0)) {
|
||||||
|
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
||||||
|
} else {
|
||||||
|
out[Sentence.RIGHT] = a[Sentence.RIGHT] + b[Sentence.RIGHT];
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DelayLineStore addDelayLine(int samples, double gain, double pan) {
|
||||||
|
DelayLineStore s = new DelayLineStore(samples, gain, pan);
|
||||||
|
delayLines.add(s);
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DelayLineStore addDelayLine(int samples, double gain) {
|
public DelayLineStore addDelayLine(int samples, double gain) {
|
||||||
@@ -60,5 +109,7 @@ public class DelayLine implements Effect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setWetOnly(boolean b) {
|
||||||
|
wetOnly = b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,42 +4,46 @@ import java.util.concurrent.ArrayBlockingQueue;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class DelayLineStore {
|
public class DelayLineStore {
|
||||||
ArrayBlockingQueue<Double> fifo;
|
|
||||||
double gain;
|
double gain;
|
||||||
int numSamples;
|
int numSamples;
|
||||||
|
double pan;
|
||||||
|
|
||||||
ArrayList<Effect> effects;
|
ArrayList<Effect> effects;
|
||||||
|
|
||||||
public DelayLineStore(int s, double g) {
|
public DelayLineStore(int s, double g, double p) {
|
||||||
fifo = new ArrayBlockingQueue<Double>(s);
|
|
||||||
for (int i = 0; i < s; i++) {
|
|
||||||
fifo.add(0d);
|
|
||||||
}
|
|
||||||
numSamples = s;
|
numSamples = s;
|
||||||
gain = g;
|
gain = g;
|
||||||
|
pan = p;
|
||||||
effects = new ArrayList<Effect>();
|
effects = new ArrayList<Effect>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double pass(double s) {
|
public DelayLineStore(int s, double g) {
|
||||||
try {
|
numSamples = s;
|
||||||
|
gain = g;
|
||||||
|
pan = 0d;
|
||||||
|
effects = new ArrayList<Effect>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(double[][] samples) {
|
||||||
for (Effect e : effects) {
|
for (Effect e : effects) {
|
||||||
s = e.process(s);
|
e.process(samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (double[] sample : samples) {
|
||||||
|
sample[Sentence.LEFT] *= gain;
|
||||||
|
sample[Sentence.RIGHT] *= gain;
|
||||||
|
|
||||||
|
if (pan < 0) {
|
||||||
|
double p = 1 + pan;
|
||||||
|
sample[Sentence.RIGHT] *= p;
|
||||||
|
} else {
|
||||||
|
double p = 1 - pan;
|
||||||
|
sample[Sentence.LEFT] *= p;
|
||||||
}
|
}
|
||||||
double v = s * gain;
|
|
||||||
double t = fifo.poll();
|
|
||||||
fifo.add(v);
|
|
||||||
return t;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return 0d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSamples(int s) {
|
public void setSamples(int s) {
|
||||||
fifo = new ArrayBlockingQueue<Double>(s);
|
|
||||||
for (int i = 0; i < s; i++) {
|
|
||||||
fifo.add(0d);
|
|
||||||
}
|
|
||||||
numSamples = s;
|
numSamples = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,13 +59,6 @@ public class DelayLineStore {
|
|||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void purge() {
|
|
||||||
fifo.clear();
|
|
||||||
for (int i = 0; i < numSamples; i++) {
|
|
||||||
fifo.add(0d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEffect(Effect e) {
|
public void addEffect(Effect e) {
|
||||||
effects.add(e);
|
effects.add(e);
|
||||||
}
|
}
|
||||||
@@ -70,7 +67,6 @@ public class DelayLineStore {
|
|||||||
for (Effect e : effects) {
|
for (Effect e : effects) {
|
||||||
e.init(sf);
|
e.init(sf);
|
||||||
}
|
}
|
||||||
purge();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump() {
|
public void dump() {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package uk.co.majenko.audiobookrecorder;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public interface Effect {
|
public interface Effect {
|
||||||
public double process(double sample);
|
public void process(double[][] samples);
|
||||||
public String getName();
|
public String getName();
|
||||||
public ArrayList<Effect> getChildEffects();
|
public ArrayList<Effect> getChildEffects();
|
||||||
public void dump();
|
public void dump();
|
||||||
|
|||||||
@@ -16,12 +16,10 @@ public class EffectGroup implements Effect {
|
|||||||
effects = new ArrayList<Effect>();
|
effects = new ArrayList<Effect>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double process(double sample) {
|
public void process(double[][] samples) {
|
||||||
double out = sample;
|
|
||||||
for (Effect e : effects) {
|
for (Effect e : effects) {
|
||||||
out = e.process(out);
|
e.process(samples);
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String n) {
|
public void setName(String n) {
|
||||||
|
|||||||
@@ -1,83 +0,0 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.Timer;
|
|
||||||
|
|
||||||
public class HavenQueue extends JPanel {
|
|
||||||
ConcurrentLinkedQueue<Sentence> sentenceList = new ConcurrentLinkedQueue<Sentence>();
|
|
||||||
|
|
||||||
Timer timer = new Timer();
|
|
||||||
|
|
||||||
Sentence currentSentence = null;
|
|
||||||
|
|
||||||
JLabel count;
|
|
||||||
|
|
||||||
public HavenQueue() {
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
count = new JLabel("Haven queue: 0");
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
add(count, BorderLayout.CENTER);
|
|
||||||
|
|
||||||
count.setOpaque(false);
|
|
||||||
setOpaque(false);
|
|
||||||
count.setForeground(Color.WHITE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processQueue() {
|
|
||||||
|
|
||||||
count.setText("Haven queue: " + sentenceList.size());
|
|
||||||
|
|
||||||
if (currentSentence == null) {
|
|
||||||
// Grab a new sentence to process.
|
|
||||||
currentSentence = sentenceList.poll();
|
|
||||||
|
|
||||||
if (currentSentence != null) {
|
|
||||||
if (!currentSentence.postHavenData()) { // Failed. Add to the end of the queue and wait a bit
|
|
||||||
submit(currentSentence);
|
|
||||||
currentSentence = null;
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentSentence != null) {
|
|
||||||
currentSentence.processPendingHaven();
|
|
||||||
int status = currentSentence.getHavenStatus();
|
|
||||||
switch (status) {
|
|
||||||
case 0: // Um... not running...?
|
|
||||||
currentSentence = null;
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
return;
|
|
||||||
case 1: // Still processing...
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
|
||||||
return;
|
|
||||||
case 2: // Finished
|
|
||||||
currentSentence = null;
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
return;
|
|
||||||
case 3: // Failed
|
|
||||||
currentSentence = null;
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void submit(Sentence s) {
|
|
||||||
s.setOverrideText("[queued...]");
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(s);
|
|
||||||
sentenceList.add(s);
|
|
||||||
count.setText("Haven queue: " + sentenceList.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -22,7 +22,8 @@ public class LFO implements Effect {
|
|||||||
phase = p;
|
phase = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double process(double sample) {
|
public void process(double[][] samples) {
|
||||||
|
for (double[] sample : samples) {
|
||||||
double v = Math.sin(phase);
|
double v = Math.sin(phase);
|
||||||
phase += sampleStep;
|
phase += sampleStep;
|
||||||
if (phase > (Math.PI * 2d)) {
|
if (phase > (Math.PI * 2d)) {
|
||||||
@@ -37,9 +38,9 @@ public class LFO implements Effect {
|
|||||||
v *= depth;
|
v *= depth;
|
||||||
|
|
||||||
// Apply it to the sample
|
// Apply it to the sample
|
||||||
sample += (sample * v);
|
sample[Sentence.LEFT] += (sample[Sentence.LEFT] * v);
|
||||||
|
sample[Sentence.RIGHT] += (sample[Sentence.RIGHT] * v);
|
||||||
return sample;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() { return "Low Frequency Oscillator (" + frequency + " Hz, " + (depth * 100d) + "%)"; }
|
public String getName() { return "Low Frequency Oscillator (" + frequency + " Hz, " + (depth * 100d) + "%)"; }
|
||||||
|
|||||||
@@ -44,8 +44,6 @@ public class Options extends JDialog {
|
|||||||
JSpinner etherealAttenuation;
|
JSpinner etherealAttenuation;
|
||||||
JSpinner etherealOffset;
|
JSpinner etherealOffset;
|
||||||
|
|
||||||
JTextField havenApiKey;
|
|
||||||
|
|
||||||
JTextField externalEditor;
|
JTextField externalEditor;
|
||||||
|
|
||||||
JTextArea startupScript;
|
JTextArea startupScript;
|
||||||
@@ -325,8 +323,7 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
enableParsing = addCheckBox(optionsPanel, "Enable automatic speech-to-text submission", getBoolean("process.haven.auto"));
|
enableParsing = addCheckBox(optionsPanel, "Enable automatic sphinx speech-to-text (**SLOW**)", getBoolean("process.sphinx"));
|
||||||
havenApiKey = addTextField(optionsPanel, "Haven OnDemand API Key", get("process.haven.apikey"));
|
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
@@ -584,9 +581,7 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
defaultPrefs.put("audio.export.bitrate", "256000");
|
defaultPrefs.put("audio.export.bitrate", "256000");
|
||||||
defaultPrefs.put("audio.export.samplerate", "44100");
|
defaultPrefs.put("audio.export.samplerate", "44100");
|
||||||
|
|
||||||
defaultPrefs.put("process.sphinx", "false");
|
defaultPrefs.put("process.sphinx", "false");
|
||||||
defaultPrefs.put("process.haven.apikey", "");
|
|
||||||
|
|
||||||
defaultPrefs.put("editor.external", "");
|
defaultPrefs.put("editor.external", "");
|
||||||
|
|
||||||
@@ -710,7 +705,6 @@ public class Options extends JDialog {
|
|||||||
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
||||||
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
||||||
set("process.sphinx", enableParsing.isSelected());
|
set("process.sphinx", enableParsing.isSelected());
|
||||||
set("process.haven.apikey", havenApiKey.getText());
|
|
||||||
set("editor.external", externalEditor.getText());
|
set("editor.external", externalEditor.getText());
|
||||||
set("cache.size", cacheSize.getValue());
|
set("cache.size", cacheSize.getValue());
|
||||||
set("audio.recording.trim.fft", fftThreshold.getValue());
|
set("audio.recording.trim.fft", fftThreshold.getValue());
|
||||||
@@ -781,9 +775,10 @@ public class Options extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static KVPair[] getTrimMethods() {
|
public static KVPair[] getTrimMethods() {
|
||||||
KVPair[] pairs = new KVPair[2];
|
KVPair[] pairs = new KVPair[3];
|
||||||
pairs[0] = new KVPair<String, String>("peak", "Peak Amplitude");
|
pairs[0] = new KVPair<String, String>("none", "None");
|
||||||
pairs[1] = new KVPair<String, String>("fft", "FFT Analysis");
|
pairs[1] = new KVPair<String, String>("peak", "Peak Amplitude");
|
||||||
|
pairs[2] = new KVPair<String, String>("fft", "FFT Analysis");
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
52
src/uk/co/majenko/audiobookrecorder/Pan.java
Normal file
52
src/uk/co/majenko/audiobookrecorder/Pan.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Pan implements Effect {
|
||||||
|
double pan;
|
||||||
|
public Pan() {
|
||||||
|
pan = 0.0d;
|
||||||
|
}
|
||||||
|
public Pan(double p) {
|
||||||
|
pan = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "Pan (" + pan + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(double[][] samples) {
|
||||||
|
for (double[] sample : samples) {
|
||||||
|
if (pan < 0) {
|
||||||
|
double p = 1 + pan;
|
||||||
|
sample[Sentence.RIGHT] *= p;
|
||||||
|
} else {
|
||||||
|
double p = 1 - pan;
|
||||||
|
sample[Sentence.LEFT] *= p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getPan() {
|
||||||
|
return pan;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPan(double p) {
|
||||||
|
pan = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dump() {
|
||||||
|
System.out.println(toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(double sf) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
|
||||||
|
|
||||||
public class Sample {
|
|
||||||
double left;
|
|
||||||
double right;
|
|
||||||
|
|
||||||
public Sample(double m) {
|
|
||||||
left = m;
|
|
||||||
right = m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sample(double l, double r) {
|
|
||||||
left = l;
|
|
||||||
right = r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getLeft() {
|
|
||||||
return left;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getRight() {
|
|
||||||
return right;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getMono() {
|
|
||||||
return (left + right) / 2.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -21,6 +21,10 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import edu.cmu.sphinx.api.*;
|
||||||
|
import edu.cmu.sphinx.decoder.adaptation.*;
|
||||||
|
import edu.cmu.sphinx.result.*;
|
||||||
|
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
@@ -49,25 +53,22 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
double gain = 1.0d;
|
double gain = 1.0d;
|
||||||
|
|
||||||
String havenJobId = "";
|
|
||||||
|
|
||||||
// 0: Not processed
|
|
||||||
// 1: Submitted
|
|
||||||
// 2: Procesisng finished
|
|
||||||
// 3: Processing failed
|
|
||||||
int havenStatus = 0;
|
|
||||||
|
|
||||||
String overrideText = null;
|
String overrideText = null;
|
||||||
|
|
||||||
public void setOverrideText(String s) { overrideText = s; }
|
public void setOverrideText(String s) { overrideText = s; }
|
||||||
public String getOverrideText() { return overrideText; }
|
public String getOverrideText() { return overrideText; }
|
||||||
|
|
||||||
|
public static final int LEFT = 0;
|
||||||
|
public static final int RIGHT = 1;
|
||||||
|
|
||||||
TargetDataLine line;
|
TargetDataLine line;
|
||||||
AudioInputStream inputStream;
|
AudioInputStream inputStream;
|
||||||
AudioFormat storedFormat = null;
|
AudioFormat storedFormat = null;
|
||||||
double storedLength = -1d;
|
double storedLength = -1d;
|
||||||
|
|
||||||
double[] audioData = null;
|
double[][] audioData = null;
|
||||||
|
|
||||||
|
// double[][] processedAudio = null;
|
||||||
|
|
||||||
RecordingThread recordingThread;
|
RecordingThread recordingThread;
|
||||||
|
|
||||||
@@ -137,7 +138,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Sentence() {
|
public Sentence() {
|
||||||
super("");
|
super("");
|
||||||
id = UUID.randomUUID().toString();
|
id = UUID.randomUUID().toString();
|
||||||
@@ -176,63 +176,43 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
try {
|
try {
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
audioData = null;
|
audioData = null;
|
||||||
|
// processedAudio = null;
|
||||||
storedFormat = null;
|
storedFormat = null;
|
||||||
storedLength = -1;
|
storedLength = -1;
|
||||||
|
|
||||||
if (!id.equals("room-noise")) {
|
if (!id.equals("room-noise")) {
|
||||||
String tm = Options.get("audio.recording.trim");
|
String tm = Options.get("audio.recording.trim");
|
||||||
if (tm.equals("peak")) {
|
if (tm.equals("peak")) {
|
||||||
autoTrimSamplePeak();
|
autoTrimSamplePeak(true);
|
||||||
} else if (tm.equals("fft")) {
|
} else if (tm.equals("fft")) {
|
||||||
autoTrimSampleFFT();
|
autoTrimSampleFFT(true);
|
||||||
}
|
}
|
||||||
if (Options.getBoolean("process.haven.auto")) {
|
if (Options.getBoolean("process.sphinx")) {
|
||||||
recognise();
|
recognise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int FFTBuckets = 1024;
|
public static final int FFTBuckets = 1024;
|
||||||
|
|
||||||
public double[][] getFFTProfile() {
|
|
||||||
double[] real = new double[FFTBuckets];
|
|
||||||
double[] imag = new double[FFTBuckets];
|
|
||||||
|
|
||||||
double[] samples = getProcessedAudioData();
|
|
||||||
int slices = (samples.length / FFTBuckets) + 1;
|
|
||||||
|
|
||||||
double[][] out = new double[slices][];
|
|
||||||
|
|
||||||
int slice = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < samples.length; i += FFTBuckets) {
|
|
||||||
for (int j = 0; j < FFTBuckets; j++) {
|
|
||||||
if (i + j < samples.length) {
|
|
||||||
real[j] = samples[i+j];
|
|
||||||
imag[j] = 0;
|
|
||||||
} else {
|
|
||||||
real[j] = 0;
|
|
||||||
imag[j] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out[slice++] = FFT.fft(real, imag, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void autoTrimSampleFFT() {
|
public void autoTrimSampleFFT() {
|
||||||
|
autoTrimSampleFFT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void autoTrimSampleFFT(boolean useRaw) {
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
double[] samples = getProcessedAudioData();
|
double[][] samples;
|
||||||
|
if (useRaw) {
|
||||||
|
samples = getRawAudioData();
|
||||||
|
} else {
|
||||||
|
samples = getProcessedAudioData();
|
||||||
|
}
|
||||||
if (samples == null) return;
|
if (samples == null) return;
|
||||||
|
|
||||||
int blocks = samples.length / 4096 + 1;
|
int blocks = samples.length / 4096 + 1;
|
||||||
@@ -246,7 +226,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
for (int j = 0; j < 4096; j++) {
|
for (int j = 0; j < 4096; j++) {
|
||||||
if (i + j < samples.length) {
|
if (i + j < samples.length) {
|
||||||
real[j] = samples[i+j];
|
real[j] = (samples[i+j][LEFT] + samples[i+j][RIGHT]) / 2d;
|
||||||
imag[j] = 0;
|
imag[j] = 0;
|
||||||
} else {
|
} else {
|
||||||
real[j] = 0;
|
real[j] = 0;
|
||||||
@@ -313,9 +293,18 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void autoTrimSamplePeak() {
|
public void autoTrimSamplePeak() {
|
||||||
|
autoTrimSamplePeak(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void autoTrimSamplePeak(boolean useRaw) {
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
double[] samples = getProcessedAudioData();
|
double[][] samples;
|
||||||
|
if (useRaw) {
|
||||||
|
samples = getRawAudioData();
|
||||||
|
} else {
|
||||||
|
samples = getProcessedAudioData();
|
||||||
|
}
|
||||||
if (samples == null) return;
|
if (samples == null) return;
|
||||||
double noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
double noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
||||||
noiseFloor *= 1.1;
|
noiseFloor *= 1.1;
|
||||||
@@ -323,7 +312,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
// Find start
|
// Find start
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
startOffset = i;
|
startOffset = i;
|
||||||
if (Math.abs(samples[i]) > noiseFloor) {
|
if (Math.abs((samples[i][LEFT] + samples[i][RIGHT])/2d) > noiseFloor) {
|
||||||
startOffset --;
|
startOffset --;
|
||||||
if (startOffset < 0) startOffset = 0;
|
if (startOffset < 0) startOffset = 0;
|
||||||
break;
|
break;
|
||||||
@@ -338,7 +327,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
for (int i = samples.length-1; i >= 0; i--) {
|
for (int i = samples.length-1; i >= 0; i--) {
|
||||||
endOffset = i;
|
endOffset = i;
|
||||||
if (Math.abs(samples[i]) > noiseFloor) {
|
if (Math.abs((samples[i][LEFT] + samples[i][RIGHT])/2d) > noiseFloor) {
|
||||||
endOffset ++;
|
endOffset ++;
|
||||||
if (endOffset >= samples.length-1) endOffset = samples.length-1;
|
if (endOffset >= samples.length-1) endOffset = samples.length-1;
|
||||||
break;
|
break;
|
||||||
@@ -396,7 +385,11 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return text;
|
if (effectChain == null) return text;
|
||||||
|
if (effectChain.equals("none")) return text;
|
||||||
|
Effect e = AudiobookRecorder.window.effects.get(effectChain);
|
||||||
|
if (e == null) return text;
|
||||||
|
return text + " (" + e.toString() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRecording() {
|
public boolean isRecording() {
|
||||||
@@ -494,8 +487,57 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void doRecognition(StreamSpeechRecognizer recognizer) {
|
||||||
|
try {
|
||||||
|
setText("[recognising...]");
|
||||||
|
AudiobookRecorder.window.bookTreeModel.reload(this);
|
||||||
|
|
||||||
|
byte[] inData = getPCMData();
|
||||||
|
|
||||||
|
ByteArrayInputStream bas = new ByteArrayInputStream(inData);
|
||||||
|
recognizer.startRecognition(bas);
|
||||||
|
SpeechResult result;
|
||||||
|
String res = "";
|
||||||
|
while ((result = recognizer.getResult()) != null) {
|
||||||
|
res += result.getHypothesis();
|
||||||
|
res += " ";
|
||||||
|
}
|
||||||
|
recognizer.stopRecognition();
|
||||||
|
|
||||||
|
setText(res);
|
||||||
|
AudiobookRecorder.window.bookTreeModel.reload(this);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void recognise() {
|
public void recognise() {
|
||||||
AudiobookRecorder.window.havenQueue.submit(Sentence.this);
|
Thread t = new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Configuration sphinxConfig = new Configuration();
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
AudioInputStream s = AudioSystem.getAudioInputStream(getFile());
|
||||||
|
AudioFormat format = getAudioFormat();
|
||||||
|
|
||||||
|
sphinxConfig.setSampleRate((int)(format.getSampleRate()));
|
||||||
|
|
||||||
|
StreamSpeechRecognizer recognizer;
|
||||||
|
|
||||||
|
recognizer = new StreamSpeechRecognizer(sphinxConfig);
|
||||||
|
|
||||||
|
doRecognition(recognizer);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocked(boolean l) {
|
public void setLocked(boolean l) {
|
||||||
@@ -516,6 +558,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
audioData = null;
|
audioData = null;
|
||||||
|
// processedAudio = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean lockedInCache() {
|
public boolean lockedInCache() {
|
||||||
@@ -523,7 +566,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int findNearestZeroCrossing(int pos, int range) {
|
public int findNearestZeroCrossing(int pos, int range) {
|
||||||
double[] data = getProcessedAudioData();
|
double[][] data = getProcessedAudioData();
|
||||||
if (data == null) return 0;
|
if (data == null) return 0;
|
||||||
if (data.length == 0) return 0;
|
if (data.length == 0) return 0;
|
||||||
|
|
||||||
@@ -533,19 +576,19 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
int backwards = pos;
|
int backwards = pos;
|
||||||
int forwards = pos;
|
int forwards = pos;
|
||||||
|
|
||||||
double backwardsPrev = data[backwards];
|
double backwardsPrev = (data[backwards][LEFT] + data[backwards][RIGHT]) / 2d;
|
||||||
double forwardsPrev = data[forwards];
|
double forwardsPrev = (data[forwards][LEFT] + data[forwards][RIGHT]) / 2d;
|
||||||
|
|
||||||
while (backwards > 0 || forwards < data.length-2) {
|
while (backwards > 0 || forwards < data.length-2) {
|
||||||
|
|
||||||
if (forwards < data.length-2) forwards++;
|
if (forwards < data.length-2) forwards++;
|
||||||
if (backwards > 0) backwards--;
|
if (backwards > 0) backwards--;
|
||||||
|
|
||||||
if (backwardsPrev >= 0 && data[backwards] < 0) { // Found one!
|
if (backwardsPrev >= 0 && ((data[backwards][LEFT] + data[backwards][RIGHT]) / 2d) < 0) { // Found one!
|
||||||
return backwards;
|
return backwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (forwardsPrev < 0 && data[forwards] >= 0) {
|
if (forwardsPrev < 0 && ((data[forwards][LEFT] + data[forwards][RIGHT]) / 2d) >= 0) {
|
||||||
return forwards;
|
return forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,8 +597,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
backwardsPrev = data[backwards];
|
backwardsPrev = (data[backwards][LEFT] + data[backwards][RIGHT]) / 2d;
|
||||||
forwardsPrev = data[forwards];
|
forwardsPrev = (data[forwards][LEFT] + data[forwards][RIGHT]) / 2d;
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
@@ -596,149 +639,18 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return attention;
|
return attention;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHavenJobId() {
|
|
||||||
return havenJobId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHavenJobId(String i) {
|
|
||||||
havenJobId = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHavenStatus() {
|
|
||||||
return havenStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHavenStatus(int i) {
|
|
||||||
havenStatus = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public boolean postHavenData() {
|
|
||||||
String apiKey = Options.get("process.haven.apikey");
|
|
||||||
if (apiKey == null || apiKey.equals("")) return false;
|
|
||||||
|
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
||||||
|
|
||||||
setOverrideText("[submitting...]");
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
|
||||||
|
|
||||||
try {
|
|
||||||
HttpPost httppost = new HttpPost("https://api.havenondemand.com/1/api/async/recognizespeech/v2?apikey=" + apiKey);
|
|
||||||
|
|
||||||
FileBody bin = new FileBody(getFile());
|
|
||||||
StringBody language = new StringBody("en-GB");
|
|
||||||
|
|
||||||
HttpEntity reqEntity = MultipartEntityBuilder.create()
|
|
||||||
.addPart("language_model", language)
|
|
||||||
.addPart("file", bin)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
httppost.setEntity(reqEntity);
|
|
||||||
|
|
||||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
|
||||||
try {
|
|
||||||
if (response.getStatusLine().getStatusCode() != 200) {
|
|
||||||
System.err.println("Error posting data: " + response.getStatusLine().getStatusCode());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpEntity resEntity = response.getEntity();
|
|
||||||
if (resEntity != null) {
|
|
||||||
JSONObject obj = new JSONObject(EntityUtils.toString(resEntity));
|
|
||||||
havenJobId = obj.getString("jobID");
|
|
||||||
System.err.println("Submitted new Haven OnDemand job #" + havenJobId);
|
|
||||||
havenStatus = 1;
|
|
||||||
}
|
|
||||||
EntityUtils.consume(resEntity);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
// eddec91c-6018-4dcd-bd8d-5e96b23e334c --form "language_model=en-US" --form "file=@3e67460c-f298-4e2c-a412-d375d489e1b3.wav"
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processPendingHaven() {
|
|
||||||
if (havenStatus != 1) return;
|
|
||||||
|
|
||||||
|
|
||||||
String apiKey = Options.get("process.haven.apikey");
|
|
||||||
if (apiKey == null || apiKey.equals("")) return;
|
|
||||||
|
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
HttpPost httppost = new HttpPost("https://api.havenondemand.com/1/job/status/" + havenJobId + "?apikey=" + apiKey);
|
|
||||||
|
|
||||||
HttpEntity reqEntity = MultipartEntityBuilder.create().build();
|
|
||||||
httppost.setEntity(reqEntity);
|
|
||||||
|
|
||||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
|
||||||
try {
|
|
||||||
if (response.getStatusLine().getStatusCode() != 200) {
|
|
||||||
havenStatus = 3;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpEntity resEntity = response.getEntity();
|
|
||||||
if (resEntity != null) {
|
|
||||||
JSONObject obj = new JSONObject(EntityUtils.toString(resEntity));
|
|
||||||
|
|
||||||
System.err.println(havenJobId + ": " + obj.getString("status"));
|
|
||||||
|
|
||||||
if (obj.getString("status").equals("finished")) {
|
|
||||||
havenStatus = 2;
|
|
||||||
JSONArray textItems = obj.getJSONArray("actions").getJSONObject(0).getJSONObject("result").getJSONArray("items");
|
|
||||||
|
|
||||||
StringBuilder out = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < textItems.length(); i++) {
|
|
||||||
out.append(textItems.getJSONObject(i).getString("text"));
|
|
||||||
out.append(" ");
|
|
||||||
}
|
|
||||||
String result = out.toString();
|
|
||||||
setText(result.trim());
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
System.err.println(result);
|
|
||||||
} else if (obj.getString("status").equals("queued")) {
|
|
||||||
havenStatus = 1;
|
|
||||||
setOverrideText("[processing...]");
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
} else {
|
|
||||||
text = id;
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
havenStatus = 3;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EntityUtils.consume(resEntity);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getPeakValue() {
|
public double getPeakValue() {
|
||||||
double oldGain = gain;
|
double oldGain = gain;
|
||||||
gain = 1.0d;
|
gain = 1.0d;
|
||||||
double[] samples = getProcessedAudioData();
|
double[][] samples = getProcessedAudioData();
|
||||||
gain = oldGain;
|
gain = oldGain;
|
||||||
if (samples == null) {
|
if (samples == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
double ms = 0;
|
double ms = 0;
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
if (Math.abs(samples[i]) > ms) {
|
if (Math.abs((samples[i][LEFT] + samples[i][RIGHT]) / 2d) > ms) {
|
||||||
ms = Math.abs(samples[i]);
|
ms = Math.abs((samples[i][LEFT] + samples[i][RIGHT]) / 2d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ms;
|
return ms;
|
||||||
@@ -756,9 +668,12 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
public void setGain(double g) {
|
public void setGain(double g) {
|
||||||
if (g <= 0.0001d) g = 1.0d;
|
if (g <= 0.0001d) g = 1.0d;
|
||||||
if (g == gain) return;
|
if (g == gain) return;
|
||||||
gain = g;
|
|
||||||
|
if (gain != g) {
|
||||||
clearCache();
|
clearCache();
|
||||||
}
|
}
|
||||||
|
gain = g;
|
||||||
|
}
|
||||||
|
|
||||||
public double getGain() {
|
public double getGain() {
|
||||||
return gain;
|
return gain;
|
||||||
@@ -938,19 +853,18 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
AudiobookRecorder.window.updateWaveform();
|
AudiobookRecorder.window.updateWaveform();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] getDoubleDataS16LE(AudioInputStream s, AudioFormat format) throws IOException {
|
public double[][] getDoubleDataS16LE(AudioInputStream s, AudioFormat format) throws IOException {
|
||||||
long len = s.getFrameLength();
|
long len = s.getFrameLength();
|
||||||
int frameSize = format.getFrameSize();
|
int frameSize = format.getFrameSize();
|
||||||
int chans = format.getChannels();
|
int chans = format.getChannels();
|
||||||
int bytes = frameSize / chans;
|
int bytes = frameSize / chans;
|
||||||
|
|
||||||
byte[] frame = new byte[frameSize];
|
byte[] frame = new byte[frameSize];
|
||||||
double[] samples = new double[(int)len];
|
double[][] samples = new double[(int)len][2];
|
||||||
|
|
||||||
for (long fno = 0; fno < len; fno++) {
|
for (long fno = 0; fno < len; fno++) {
|
||||||
|
|
||||||
s.read(frame);
|
s.read(frame);
|
||||||
int sample = 0;
|
|
||||||
if (chans == 2) { // Stereo
|
if (chans == 2) { // Stereo
|
||||||
int ll = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
int ll = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||||
int lh = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
int lh = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||||
@@ -960,27 +874,29 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
int right = (rh << 8) | rl;
|
int right = (rh << 8) | rl;
|
||||||
if ((left & 0x8000) == 0x8000) left |= 0xFFFF0000;
|
if ((left & 0x8000) == 0x8000) left |= 0xFFFF0000;
|
||||||
if ((right & 0x8000) == 0x8000) right |= 0xFFFF0000;
|
if ((right & 0x8000) == 0x8000) right |= 0xFFFF0000;
|
||||||
sample = (left + right) / 2;
|
samples[(int)fno][LEFT] = (double)left / 32768d;
|
||||||
|
samples[(int)fno][RIGHT] = (double)right / 32768d;
|
||||||
} else {
|
} else {
|
||||||
int l = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
int l = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||||
int h = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
int h = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||||
sample = (h << 8) | l;
|
int mono = (h << 8) | l;
|
||||||
if ((sample & 0x8000) == 0x8000) sample |= 0xFFFF0000;
|
if ((mono & 0x8000) == 0x8000) mono |= 0xFFFF0000;
|
||||||
|
samples[(int)fno][LEFT] = (double)mono / 32768d;
|
||||||
|
samples[(int)fno][RIGHT] = (double)mono / 32768d;
|
||||||
}
|
}
|
||||||
samples[(int)fno] = (double)sample / 32768d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] getDoubleDataS24LE(AudioInputStream s, AudioFormat format) throws IOException {
|
public double[][] getDoubleDataS24LE(AudioInputStream s, AudioFormat format) throws IOException {
|
||||||
long len = s.getFrameLength();
|
long len = s.getFrameLength();
|
||||||
int frameSize = format.getFrameSize();
|
int frameSize = format.getFrameSize();
|
||||||
int chans = format.getChannels();
|
int chans = format.getChannels();
|
||||||
int bytes = frameSize / chans;
|
int bytes = frameSize / chans;
|
||||||
|
|
||||||
byte[] frame = new byte[frameSize];
|
byte[] frame = new byte[frameSize];
|
||||||
double[] samples = new double[(int)len];
|
double[][] samples = new double[(int)len][2];
|
||||||
|
|
||||||
for (long fno = 0; fno < len; fno++) {
|
for (long fno = 0; fno < len; fno++) {
|
||||||
|
|
||||||
@@ -997,22 +913,22 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
int right = (rh << 16) | (rm << 8) | rl;
|
int right = (rh << 16) | (rm << 8) | rl;
|
||||||
if ((left & 0x800000) == 0x800000) left |= 0xFF000000;
|
if ((left & 0x800000) == 0x800000) left |= 0xFF000000;
|
||||||
if ((right & 0x800000) == 0x800000) right |= 0xFF000000;
|
if ((right & 0x800000) == 0x800000) right |= 0xFF000000;
|
||||||
sample = (left + right) / 2;
|
samples[(int)fno][LEFT] = (double)left / 8388608d;
|
||||||
|
samples[(int)fno][RIGHT] = (double)right / 8388608d;
|
||||||
} else {
|
} else {
|
||||||
int l = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
int l = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||||
int m = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
int m = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||||
int h = frame[2] >= 0 ? frame[2] : 256 + frame[2];
|
int h = frame[2] >= 0 ? frame[2] : 256 + frame[2];
|
||||||
sample = (h << 16) | (m << 8) | l;
|
int mono = (h << 16) | (m << 8) | l;
|
||||||
if ((sample & 0x800000) == 0x800000) sample |= 0xFF000000;
|
if ((mono & 0x800000) == 0x800000) mono |= 0xFF000000;
|
||||||
|
samples[(int)fno][LEFT] = (double)mono / 8388608d;
|
||||||
|
samples[(int)fno][RIGHT] = (double)mono / 8388608d;
|
||||||
}
|
}
|
||||||
samples[(int)fno] = (double)sample / 8388608d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void loadFile() {
|
public void loadFile() {
|
||||||
if (audioData != null) return;
|
if (audioData != null) return;
|
||||||
|
|
||||||
@@ -1021,7 +937,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
||||||
AudioFormat format = getAudioFormat();
|
AudioFormat format = getAudioFormat();
|
||||||
|
|
||||||
double[] samples = null;
|
double[][] samples = null;
|
||||||
|
|
||||||
switch (format.getSampleSizeInBits()) {
|
switch (format.getSampleSizeInBits()) {
|
||||||
case 16:
|
case 16:
|
||||||
@@ -1040,84 +956,101 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] getProcessedAudioData() {
|
synchronized public double[][] getRawAudioData() {
|
||||||
loadFile();
|
loadFile();
|
||||||
|
return audioData;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized public double[][] getProcessedAudioData() {
|
||||||
|
loadFile();
|
||||||
|
// if (processedAudio != null) return processedAudio;
|
||||||
|
|
||||||
if (audioData == null) return null;
|
if (audioData == null) return null;
|
||||||
double[] samples = new double[audioData.length];
|
double[][] processedAudio = new double[audioData.length][2];
|
||||||
for (int i = 0; i < audioData.length; i++) {
|
for (int i = 0; i < audioData.length; i++) {
|
||||||
samples[i] = audioData[i];
|
processedAudio[i][LEFT] = audioData[i][LEFT];
|
||||||
|
processedAudio[i][RIGHT] = audioData[i][RIGHT];
|
||||||
}
|
}
|
||||||
// Add processing in here.
|
// Add processing in here.
|
||||||
|
|
||||||
if (effectChain == null) effectChain = AudiobookRecorder.window.defaultEffectChain;
|
|
||||||
|
|
||||||
Effect eff = AudiobookRecorder.window.effects.get(effectChain);
|
String def = AudiobookRecorder.window.getDefaultEffectsChain();
|
||||||
if (eff == null) {
|
Effect eff = AudiobookRecorder.window.effects.get(def);
|
||||||
effectChain = AudiobookRecorder.window.defaultEffectChain;
|
|
||||||
eff = AudiobookRecorder.window.effects.get(effectChain);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eff != null) {
|
if (eff != null) {
|
||||||
eff.init(getAudioFormat().getFrameRate());
|
eff.init(getAudioFormat().getFrameRate());
|
||||||
for (int i = 0; i < samples.length; i++) {
|
eff.process(processedAudio);
|
||||||
samples[i] = eff.process(samples[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cuts out the computer hum.
|
if (effectChain != null) {
|
||||||
// Biquad bq = new Biquad(Biquad.Notch, 140d/44100d, 20.0d, -50);
|
// Don't double up the default chain
|
||||||
// DelayLine dl = new DelayLine();
|
if (!effectChain.equals(def)) {
|
||||||
// dl.addDelayLine(2205, 0.8);
|
eff = AudiobookRecorder.window.effects.get(effectChain);
|
||||||
// dl.addDelayLine(4410, 0.4);
|
if (eff != null) {
|
||||||
// dl.addDelayLine(6615, 0.2);
|
eff.init(getAudioFormat().getFrameRate());
|
||||||
|
eff.process(processedAudio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add final master gain stage
|
// Add final master gain stage
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < processedAudio.length; i++) {
|
||||||
samples[i] = samples[i] * gain;
|
processedAudio[i][LEFT] *= gain;
|
||||||
|
processedAudio[i][RIGHT] *= gain;
|
||||||
}
|
}
|
||||||
return samples;
|
return processedAudio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] getDoubleAudioData() {
|
public double[][] getDoubleAudioData() {
|
||||||
return getProcessedAudioData();
|
return getProcessedAudioData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double[] getCroppedAudioData() {
|
public double[][] getCroppedAudioData() {
|
||||||
double[] inSamples = getDoubleAudioData();
|
double[][] inSamples = getDoubleAudioData();
|
||||||
if (inSamples == null) return null;
|
if (inSamples == null) return null;
|
||||||
updateCrossings();
|
updateCrossings();
|
||||||
|
|
||||||
int length = crossEndOffset - crossStartOffset;
|
int length = crossEndOffset - crossStartOffset;
|
||||||
|
|
||||||
double[] samples = new double[length];
|
double[][] samples = new double[length][2];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
samples[i] = inSamples[crossStartOffset + i];
|
samples[i][LEFT] = inSamples[crossStartOffset + i][LEFT];
|
||||||
|
samples[i][RIGHT] = inSamples[crossStartOffset + i][RIGHT];
|
||||||
}
|
}
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getPCMData() {
|
public byte[] getPCMData() {
|
||||||
double[] croppedData = getCroppedAudioData();
|
double[][] croppedData = getCroppedAudioData();
|
||||||
if (croppedData == null) return null;
|
if (croppedData == null) return null;
|
||||||
int length = croppedData.length;
|
int length = croppedData.length;
|
||||||
byte[] pcmData = new byte[length * 2];
|
byte[] pcmData = new byte[length * 4];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
double sd = croppedData[i] * 32768d;
|
double sd = croppedData[i][LEFT] * 32768d;
|
||||||
int si = (int)sd;
|
int si = (int)sd;
|
||||||
if (si > 32767) si = 32767;
|
if (si > 32767) si = 32767;
|
||||||
if (si < -32768) si = -32768;
|
if (si < -32768) si = -32768;
|
||||||
pcmData[i * 2] = (byte)(si & 0xFF);
|
pcmData[i * 4] = (byte)(si & 0xFF);
|
||||||
pcmData[(i * 2) + 1] = (byte)((si & 0xFF00) >> 8);
|
pcmData[(i * 4) + 1] = (byte)((si & 0xFF00) >> 8);
|
||||||
|
sd = croppedData[i][RIGHT] * 32768d;
|
||||||
|
si = (int)sd;
|
||||||
|
if (si > 32767) si = 32767;
|
||||||
|
if (si < -32768) si = -32768;
|
||||||
|
pcmData[(i * 4) + 2] = (byte)(si & 0xFF);
|
||||||
|
pcmData[(i * 4) + 3] = (byte)((si & 0xFF00) >> 8);
|
||||||
}
|
}
|
||||||
return pcmData;
|
return pcmData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEffectChain(String key) {
|
public void setEffectChain(String key) {
|
||||||
|
if ((effectChain != null) && (!effectChain.equals(key))) {
|
||||||
|
clearCache();
|
||||||
|
}
|
||||||
effectChain = key;
|
effectChain = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEffectChain() {
|
public String getEffectChain() {
|
||||||
if (effectChain == null) return AudiobookRecorder.window.defaultEffectChain;
|
if (effectChain == null) return "none";
|
||||||
return effectChain;
|
return effectChain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import javax.sound.sampled.*;
|
|||||||
|
|
||||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
||||||
|
|
||||||
double[] samples = null;
|
double[][] samples = null;
|
||||||
|
|
||||||
int leftMarker = 0;
|
int leftMarker = 0;
|
||||||
int rightMarker = 0;
|
int rightMarker = 0;
|
||||||
@@ -92,7 +92,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
double lmax = 0;
|
double lmax = 0;
|
||||||
|
|
||||||
for (int o = 0; o < step; o++) {
|
for (int o = 0; o < step; o++) {
|
||||||
double sample = samples[offset + (n * step) + o];
|
double sample = (samples[offset + (n * step) + o][Sentence.LEFT] + samples[offset + (n * step) + o][Sentence.RIGHT]) / 2d;
|
||||||
if (sample >= 0) {
|
if (sample >= 0) {
|
||||||
have += sample;
|
have += sample;
|
||||||
hcnt++;
|
hcnt++;
|
||||||
@@ -189,7 +189,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(double[] s) {
|
public void setData(double[][] s) {
|
||||||
samples = s;
|
samples = s;
|
||||||
playMarker = 0;
|
playMarker = 0;
|
||||||
repaint();
|
repaint();
|
||||||
|
|||||||
Reference in New Issue
Block a user