Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| babd3d2052 | |||
| 9464839b4d | |||
| bcf7875414 | |||
| 732894a0fb | |||
| 146bf5a3c2 | |||
| b05bfde094 | |||
| 37d372b8f5 | |||
| c01fee3b73 | |||
| c907e735c6 | |||
| 7545e33d2f | |||
| ebf961449a | |||
| 45d6882527 | |||
| 2ec370ad61 | |||
| 63d5c4af8e | |||
| 9619fd574e | |||
| adeb42070d | |||
| d207d246bf |
7
ExampleFilters/alien.eff
Normal file
7
ExampleFilters/alien.eff
Normal file
@@ -0,0 +1,7 @@
|
||||
<effect name="Alien">
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||
<lfo frequency="100" depth="0.5" />
|
||||
</effect>
|
||||
@@ -1,5 +1,7 @@
|
||||
<effect name="Big Echo">
|
||||
<biquad type="notch" fc="140" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<delayline>
|
||||
<delay samples="22000" gain="0.2" pan="-0.3">
|
||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<effect name="Cut Computer Hum">
|
||||
<biquad type="notch" fc="140" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||
</effect>
|
||||
|
||||
7
ExampleFilters/cuthumagc.eff
Normal file
7
ExampleFilters/cuthumagc.eff
Normal file
@@ -0,0 +1,7 @@
|
||||
<effect name="Cut Computer Hum (with AGC)">
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||
<agc ceiling="0.666" limit="1" attack="0.1" decay="0.01" />
|
||||
</effect>
|
||||
@@ -1,21 +1,23 @@
|
||||
<effect name="Ethereal Voice">
|
||||
<biquad type="notch" fc="140" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<amplifier gain="0.1" />
|
||||
<delayline>
|
||||
<delay samples="4000" gain="1.0" pan="-0.3">
|
||||
<delay samples="2000" gain="1.0" pan="-0.3">
|
||||
<biquad type="highpass" fc="400" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="8000" gain="1.5" pan="0.3">
|
||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||
<delay samples="4000" gain="1.1" pan="0.3">
|
||||
<biquad type="highpass" fc="800" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="12000" gain="2.0" pan="-0.5">
|
||||
<biquad type="highpass" fc="200" q="1" gain="0" />
|
||||
<delay samples="8000" gain="1.2" pan="-0.5">
|
||||
<biquad type="highpass" fc="1000" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="16000" gain="3.0" pan="0.5">
|
||||
<biquad type="highpass" fc="100" q="1" gain="0" />
|
||||
<delay samples="10000" gain="1.3" pan="0.5">
|
||||
<biquad type="highpass" fc="1500" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="20000" gain="15.0" pan="0" />
|
||||
<delay samples="12000" gain="15.0" pan="0" />
|
||||
</delayline>
|
||||
<biquad type="lowshelf" fc="1000" q="2.2" gain="-10" />
|
||||
<biquad type="lowshelf" fc="2000" q="2.2" gain="-10" />
|
||||
<amplifier gain="1.5" />
|
||||
</effect>
|
||||
|
||||
18
ExampleFilters/largeroom.eff
Normal file
18
ExampleFilters/largeroom.eff
Normal file
@@ -0,0 +1,18 @@
|
||||
<effect name="Large Room (quiet)">
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||
<delayline>
|
||||
<delay samples="5500" gain="0.2" pan="-0.3">
|
||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="11000" gain="0.05" pan="0.3">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="16500" gain="0.01" pan="0.0">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
</delayline>
|
||||
<amplifier gain="0.3" />
|
||||
</effect>
|
||||
18
ExampleFilters/largeroomloud.eff
Normal file
18
ExampleFilters/largeroomloud.eff
Normal file
@@ -0,0 +1,18 @@
|
||||
<effect name="Large Room (loud)">
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||
<delayline>
|
||||
<delay samples="5500" gain="0.2" pan="-0.3">
|
||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="11000" gain="0.05" pan="0.3">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="16500" gain="0.01" pan="0.0">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
</delayline>
|
||||
<amplifier gain="0.9" />
|
||||
</effect>
|
||||
@@ -1,5 +1,7 @@
|
||||
<effect name="Telephone">
|
||||
<biquad type="notch" fc="140" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<biquad type="lowshelf" fc="400" q="10" gain="-20" />
|
||||
<biquad type="highshelf" fc="8000" q="10" gain="-20" />
|
||||
<delayline>
|
||||
|
||||
14
ExampleFilters/radio.eff
Normal file
14
ExampleFilters/radio.eff
Normal file
@@ -0,0 +1,14 @@
|
||||
<effect name="Radio">
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<amplifier gain="0.1" />
|
||||
<biquad type="peak" fc="1000" q="10" gain="45" />
|
||||
<lfo frequency="5000" depth="0.3" />
|
||||
<clipping clip="0.3" />
|
||||
<biquad type="highshelf" fc="8000" q="1" gain="-20" />
|
||||
<delayline>
|
||||
<delay samples="100" gain="0.7" />
|
||||
<delay samples="200" gain="0.5" />
|
||||
</delayline>
|
||||
</effect>
|
||||
@@ -1,5 +1,7 @@
|
||||
<effect name="Robotic">
|
||||
<biquad type="notch" fc="140" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||
<biquad type="lowshelf" fc="100" q="2" gain="-20" />
|
||||
<delayline>
|
||||
<delay samples="400" gain="1" pan="-0.3" />
|
||||
|
||||
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.5
|
||||
version=0.1.8
|
||||
|
||||
@@ -14,6 +14,7 @@ public class AGC implements Effect {
|
||||
attack = a;
|
||||
decay = d;
|
||||
limit = l;
|
||||
gain = 1d;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -24,27 +25,36 @@ public class AGC implements Effect {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public double process(double sample) {
|
||||
double absSample = Math.abs(sample) * gain;
|
||||
public void process(double[][] samples) {
|
||||
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) {
|
||||
gain -= attack;
|
||||
if (gain < 0) gain = 0;
|
||||
}
|
||||
|
||||
if (absSample < ceiling) {
|
||||
gain += decay;
|
||||
if (gain > limit) {
|
||||
gain = limit;
|
||||
if (absSampleLeft > ceiling) {
|
||||
gain -= attack;
|
||||
if (gain < 0) gain = 0;
|
||||
}
|
||||
|
||||
if (absSampleRight > ceiling) {
|
||||
gain -= attack;
|
||||
if (gain < 0) gain = 0;
|
||||
}
|
||||
|
||||
if ((absSampleLeft < ceiling) && (absSampleRight < ceiling)) {
|
||||
gain += decay;
|
||||
if (gain > limit) {
|
||||
gain = limit;
|
||||
}
|
||||
}
|
||||
|
||||
samples[i][Sentence.LEFT] *= gain;
|
||||
samples[i][Sentence.RIGHT] *= gain;
|
||||
}
|
||||
|
||||
sample *= gain;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
public void init(double sr) {
|
||||
gain = 1d;
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
|
||||
@@ -19,8 +19,11 @@ public class Amplifier implements Effect {
|
||||
return null;
|
||||
}
|
||||
|
||||
public double process(double sample) {
|
||||
return sample * gain;
|
||||
public void process(double[][] samples) {
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
samples[i][Sentence.LEFT] *= gain;
|
||||
samples[i][Sentence.RIGHT] *= gain;
|
||||
}
|
||||
}
|
||||
|
||||
public double getGain() {
|
||||
|
||||
@@ -20,15 +20,21 @@ import javax.imageio.*;
|
||||
import org.w3c.dom.*;
|
||||
import javax.xml.parsers.*;
|
||||
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 {
|
||||
|
||||
// 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();
|
||||
HashMap<String, EffectGroup> effects;
|
||||
TreeMap<String, EffectGroup> effects;
|
||||
|
||||
String defaultEffectChain = "none";
|
||||
|
||||
@@ -68,8 +74,6 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
JScrollPane mainScroll;
|
||||
|
||||
JDialog equaliserWindow = null;
|
||||
|
||||
Book book = null;
|
||||
|
||||
JTree bookTree;
|
||||
@@ -88,6 +92,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
JSpinner gainPercent;
|
||||
JCheckBox locked;
|
||||
JCheckBox attention;
|
||||
JCheckBox rawAudio;
|
||||
|
||||
JButtonSpacePlay reprocessAudioFFT;
|
||||
JButtonSpacePlay reprocessAudioPeak;
|
||||
@@ -101,19 +106,32 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
SourceDataLine play = null;
|
||||
|
||||
public HavenQueue havenQueue = new HavenQueue();
|
||||
|
||||
|
||||
public TargetDataLine microphone = null;
|
||||
public AudioInputStream microphoneStream = null;
|
||||
|
||||
public Configuration sphinxConfig;
|
||||
public StreamSpeechRecognizer recognizer;
|
||||
|
||||
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) {
|
||||
toolBar = new MainToolBar(this);
|
||||
toolBar.addSeparator();
|
||||
toolBar.add(Box.createHorizontalGlue());
|
||||
toolBar.add(havenQueue);
|
||||
ob.add(toolBar, BorderLayout.NORTH);
|
||||
}
|
||||
|
||||
@@ -281,6 +299,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
window = this;
|
||||
|
||||
try {
|
||||
|
||||
String clsname = "com.jtattoo.plaf.hifi.HiFiLookAndFeel";
|
||||
UIManager.setLookAndFeel(clsname);
|
||||
|
||||
@@ -295,8 +314,6 @@ public class AudiobookRecorder extends JFrame {
|
||||
Method mth = cls.getMethod("setCurrentTheme", cArg);
|
||||
mth.invoke(cls, p);
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -440,6 +457,11 @@ public class AudiobookRecorder extends JFrame {
|
||||
controlsLeft.add(reprocessAudioPeak);
|
||||
controlsLeft.add(normalizeAudio);
|
||||
|
||||
rawAudio = new JCheckBox("Raw Audio");
|
||||
rawAudio.setFocusable(false);
|
||||
|
||||
controlsTop.add(rawAudio);
|
||||
|
||||
locked = new JCheckBox("Phrase locked");
|
||||
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("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("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();
|
||||
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.post-gap", Options.get("catenation.post-chapter"));
|
||||
|
||||
loadEffects();
|
||||
buildBook(prefs);
|
||||
|
||||
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")
|
||||
void treePopup(MouseEvent e) {
|
||||
|
||||
@@ -805,7 +872,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
JMenuObject o = (JMenuObject)e.getSource();
|
||||
Sentence s = (Sentence)o.getObject();
|
||||
if (!s.isLocked()) {
|
||||
havenQueue.submit(s);
|
||||
s.recognise();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1115,12 +1182,9 @@ public class AudiobookRecorder extends JFrame {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JMenuObject o = (JMenuObject)e.getSource();
|
||||
Chapter c = (Chapter)o.getObject();
|
||||
for (Enumeration s = c.children(); s.hasMoreElements();) {
|
||||
Sentence snt = (Sentence)s.nextElement();
|
||||
if (snt.getId().equals(snt.getText())) {
|
||||
havenQueue.submit(snt);
|
||||
}
|
||||
}
|
||||
BatchConversionThread r = new BatchConversionThread(c);
|
||||
Thread t = new Thread(r);
|
||||
t.start();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1624,7 +1688,6 @@ public class AudiobookRecorder extends JFrame {
|
||||
prefs.loadFromXML(fis);
|
||||
|
||||
File r = f.getParentFile();
|
||||
loadEffects();
|
||||
|
||||
buildBook(prefs);
|
||||
|
||||
@@ -1656,6 +1719,8 @@ public class AudiobookRecorder extends JFrame {
|
||||
book.setComment(prefs.getProperty("book.comment"));
|
||||
book.setACX(prefs.getProperty("book.acx"));
|
||||
|
||||
loadEffects();
|
||||
|
||||
defaultEffectChain = prefs.getProperty("audio.effect.default");
|
||||
if (defaultEffectChain == null) {
|
||||
defaultEffectChain = "none";
|
||||
@@ -1689,6 +1754,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
InputMap im = bookTree.getInputMap(JComponent.WHEN_FOCUSED);
|
||||
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");
|
||||
|
||||
@@ -1882,14 +1948,14 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
public double getNoiseFloor() {
|
||||
if (roomNoise == null) return 0;
|
||||
double[] samples = roomNoise.getDoubleAudioData();
|
||||
double[][] samples = roomNoise.getDoubleAudioData();
|
||||
if (samples == null) {
|
||||
return 0;
|
||||
}
|
||||
double ms = 0;
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
if (Math.abs(samples[i]) > ms) {
|
||||
ms = Math.abs(samples[i]);
|
||||
if (Math.abs((samples[i][Sentence.LEFT] + samples[i][Sentence.RIGHT]) / 2d) > ms) {
|
||||
ms = Math.abs((samples[i][Sentence.LEFT] + samples[i][Sentence.RIGHT]) / 2d);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1916,7 +1982,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
public void run() {
|
||||
roomNoise.stopRecording();
|
||||
centralPanel.setFlash(false);
|
||||
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
|
||||
statusLabel.setText("Noise floor: " + getNoiseFloorDB() + "dB");
|
||||
}
|
||||
}, 5000); // 5 seconds of recording
|
||||
}
|
||||
@@ -1940,7 +2006,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
try {
|
||||
|
||||
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.open(format);
|
||||
@@ -2034,7 +2100,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
try {
|
||||
|
||||
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.open(format);
|
||||
play.start();
|
||||
@@ -2053,6 +2119,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.getProcessedAudioData(); // 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;
|
||||
@@ -2060,7 +2136,6 @@ public class AudiobookRecorder extends JFrame {
|
||||
play.write(data, pos, l);
|
||||
}
|
||||
|
||||
DefaultMutableTreeNode next = s.getNextSibling();
|
||||
boolean last = false;
|
||||
if (next == null) {
|
||||
last = true;
|
||||
@@ -2106,6 +2181,8 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
if (roomNoise == null) return null;
|
||||
|
||||
roomNoise.setEffectChain(defaultEffectChain);
|
||||
|
||||
int len = roomNoise.getSampleSize();
|
||||
if (len == 0) return null;
|
||||
|
||||
@@ -2140,7 +2217,6 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
public boolean enableMicrophone() {
|
||||
AudioFormat format = Options.getAudioFormat();
|
||||
System.err.println(format);
|
||||
|
||||
Mixer.Info mixer = Options.getRecordingMixer();
|
||||
|
||||
@@ -2573,12 +2649,16 @@ System.err.println(format);
|
||||
|
||||
public void updateWaveform() {
|
||||
if (selectedSentence != null) {
|
||||
sampleWaveform.setData(selectedSentence.getDoubleAudioData());
|
||||
if (rawAudio.isSelected()) {
|
||||
sampleWaveform.setData(selectedSentence.getRawAudioData());
|
||||
} else {
|
||||
sampleWaveform.setData(selectedSentence.getDoubleAudioData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadEffects() {
|
||||
effects = new HashMap<String,EffectGroup>();
|
||||
effects = new TreeMap<String,EffectGroup>();
|
||||
loadEffectsFromFolder(new File(Options.get("path.storage"), "System"));
|
||||
if (book != null) {
|
||||
loadEffectsFromFolder(new File(Options.get("path.storage"), book.getName()));
|
||||
@@ -2634,11 +2714,21 @@ System.err.println(format);
|
||||
if (eff != null) {
|
||||
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")) {
|
||||
Effect eff = (Effect)loadAmplifier(e);
|
||||
if (eff != null) {
|
||||
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")) {
|
||||
Effect eff = (Effect)loadEffectGroup(e);
|
||||
if (eff != null) {
|
||||
@@ -2654,6 +2744,11 @@ System.err.println(format);
|
||||
if (eff != null) {
|
||||
group.addEffect(eff);
|
||||
}
|
||||
} else if (e.getTagName().equals("clipping")) {
|
||||
Effect eff = (Effect)loadClipping(e);
|
||||
if (eff != null) {
|
||||
group.addEffect(eff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2693,6 +2788,9 @@ System.err.println(format);
|
||||
DelayLine line = new DelayLine();
|
||||
|
||||
NodeList list = root.getChildNodes();
|
||||
if (Utils.s2b(root.getAttribute("wetonly"))) {
|
||||
line.setWetOnly(true);
|
||||
}
|
||||
|
||||
for (int i = 0; i < list.getLength(); i++) {
|
||||
Node n = list.item(i);
|
||||
@@ -2701,7 +2799,9 @@ System.err.println(format);
|
||||
if (e.getTagName().equals("delay")) {
|
||||
int samples = Utils.s2i(e.getAttribute("samples"));
|
||||
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();
|
||||
for (int j = 0; j < inner.getLength(); j++) {
|
||||
@@ -2719,11 +2819,21 @@ System.err.println(format);
|
||||
if (eff != null) {
|
||||
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")) {
|
||||
Effect eff = (Effect)loadAmplifier(ie);
|
||||
if (eff != null) {
|
||||
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")) {
|
||||
Effect eff = (Effect)loadEffectGroup(ie);
|
||||
if (eff != null) {
|
||||
@@ -2739,6 +2849,11 @@ System.err.println(format);
|
||||
if (eff != null) {
|
||||
store.addEffect(eff);
|
||||
}
|
||||
} else if (ie.getTagName().equals("clipping")) {
|
||||
Effect eff = (Effect)loadClipping(ie);
|
||||
if (eff != null) {
|
||||
store.addEffect(eff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2754,6 +2869,21 @@ System.err.println(format);
|
||||
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) {
|
||||
Clipping c = new Clipping(Utils.s2d(root.getAttribute("clip")));
|
||||
return c;
|
||||
}
|
||||
|
||||
public LFO loadLFO(Element root) {
|
||||
double f = Utils.s2d(root.getAttribute("frequency"));
|
||||
double d = Utils.s2d(root.getAttribute("depth"));
|
||||
@@ -2782,6 +2912,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());
|
||||
@@ -2812,4 +2945,8 @@ System.err.println(format);
|
||||
updateWaveform();
|
||||
}
|
||||
}
|
||||
|
||||
public String getDefaultEffectsChain() {
|
||||
return defaultEffectChain;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@ public class Biquad implements Effect {
|
||||
int type;
|
||||
double a0, a1, a2, b1, b2;
|
||||
double Fc, Q, peakGain;
|
||||
double z1, z2;
|
||||
double lz1, lz2;
|
||||
double rz1, rz2;
|
||||
double sampleFrequency;
|
||||
|
||||
public Biquad() {
|
||||
@@ -45,15 +46,19 @@ public class Biquad implements Effect {
|
||||
Fc = 440d;
|
||||
Q = 0.707d;
|
||||
peakGain = 0.0d;
|
||||
z1 = 0.0d;
|
||||
z2 = 0.0d;
|
||||
lz1 = 0.0d;
|
||||
lz2 = 0.0d;
|
||||
rz1 = 0.0d;
|
||||
rz2 = 0.0d;
|
||||
sampleFrequency = 44100d;
|
||||
}
|
||||
|
||||
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
||||
setBiquad(type, Fc, Q, peakGainDB);
|
||||
z1 = 0.0;
|
||||
z2 = 0.0;
|
||||
lz1 = 0.0;
|
||||
lz2 = 0.0;
|
||||
rz1 = 0.0;
|
||||
rz2 = 0.0;
|
||||
sampleFrequency = 44100d;
|
||||
}
|
||||
|
||||
@@ -84,17 +89,33 @@ public class Biquad implements Effect {
|
||||
setPeakGain(peakGainDB);
|
||||
}
|
||||
|
||||
public double process(double in) {
|
||||
double out = in * a0 + z1;
|
||||
z1 = in * a1 + z2 - b1 * out;
|
||||
z2 = in * a2 - b2 * out;
|
||||
return out;
|
||||
public void process(double[][] samples) {
|
||||
lz1 = 0d;
|
||||
lz2 = 0d;
|
||||
rz1 = 0d;
|
||||
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) {
|
||||
sampleFrequency = sf;
|
||||
z1 = 0d;
|
||||
z2 = 0d;
|
||||
lz1 = 0d;
|
||||
lz2 = 0d;
|
||||
rz1 = 0d;
|
||||
rz2 = 0d;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,12 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
||||
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);
|
||||
|
||||
} 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 format = new AudioFormat(sampleformat.getSampleRate(), 16, 1, true, false);
|
||||
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false);
|
||||
byte[] data;
|
||||
|
||||
int fullLength = 0;
|
||||
|
||||
49
src/uk/co/majenko/audiobookrecorder/Clipping.java
Normal file
49
src/uk/co/majenko/audiobookrecorder/Clipping.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Clipping implements Effect {
|
||||
double clip;
|
||||
public Clipping() {
|
||||
clip = 1.0d;
|
||||
}
|
||||
public Clipping(double g) {
|
||||
clip = g;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Clipping (" + clip + ")";
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (double[] sample : samples) {
|
||||
if (sample[Sentence.LEFT] > clip) sample[Sentence.LEFT] = clip;
|
||||
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() {
|
||||
return clip;
|
||||
}
|
||||
|
||||
public void setClip(double g) {
|
||||
clip = g;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ public class DelayLine implements Effect {
|
||||
|
||||
ArrayList<DelayLineStore> delayLines;
|
||||
|
||||
boolean wetOnly = false;
|
||||
|
||||
public DelayLine() {
|
||||
delayLines = new ArrayList<DelayLineStore>();
|
||||
}
|
||||
@@ -14,23 +16,70 @@ public class DelayLine implements Effect {
|
||||
return "Delay Line (" + delayLines.size() + " lines)";
|
||||
}
|
||||
|
||||
public double process(double sample) {
|
||||
double s = sample;
|
||||
for (DelayLineStore d : delayLines) {
|
||||
double echo = d.pass(sample);
|
||||
s = mix(s, echo);
|
||||
public void process(double[][] samples) {
|
||||
double[][] savedSamples = new double[samples.length][2];
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
savedSamples[i][Sentence.LEFT] = samples[i][Sentence.LEFT];
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
double[][] subSamples = new double[samples.length][2];
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
||||
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
||||
}
|
||||
for (DelayLineStore d : delayLines) {
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
||||
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
double mix(double a, double b) {
|
||||
if ((a < 0) && (b < 0)) {
|
||||
return (a + b) - (a * b);
|
||||
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 > 0) && (b > 0)) {
|
||||
return (a + b) - (a * b);
|
||||
|
||||
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 a + b;
|
||||
|
||||
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) {
|
||||
@@ -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;
|
||||
|
||||
public class DelayLineStore {
|
||||
ArrayBlockingQueue<Double> fifo;
|
||||
double gain;
|
||||
int numSamples;
|
||||
double pan;
|
||||
|
||||
ArrayList<Effect> effects;
|
||||
|
||||
public DelayLineStore(int s, double g) {
|
||||
fifo = new ArrayBlockingQueue<Double>(s);
|
||||
for (int i = 0; i < s; i++) {
|
||||
fifo.add(0d);
|
||||
}
|
||||
public DelayLineStore(int s, double g, double p) {
|
||||
numSamples = s;
|
||||
gain = g;
|
||||
pan = p;
|
||||
effects = new ArrayList<Effect>();
|
||||
}
|
||||
|
||||
public double pass(double s) {
|
||||
try {
|
||||
for (Effect e : effects) {
|
||||
s = e.process(s);
|
||||
}
|
||||
double v = s * gain;
|
||||
double t = fifo.poll();
|
||||
fifo.add(v);
|
||||
return t;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
public DelayLineStore(int s, double g) {
|
||||
numSamples = s;
|
||||
gain = g;
|
||||
pan = 0d;
|
||||
effects = new ArrayList<Effect>();
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (Effect e : effects) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
return 0d;
|
||||
}
|
||||
|
||||
public void setSamples(int s) {
|
||||
fifo = new ArrayBlockingQueue<Double>(s);
|
||||
for (int i = 0; i < s; i++) {
|
||||
fifo.add(0d);
|
||||
}
|
||||
numSamples = s;
|
||||
}
|
||||
|
||||
@@ -55,13 +59,6 @@ public class DelayLineStore {
|
||||
return gain;
|
||||
}
|
||||
|
||||
public void purge() {
|
||||
fifo.clear();
|
||||
for (int i = 0; i < numSamples; i++) {
|
||||
fifo.add(0d);
|
||||
}
|
||||
}
|
||||
|
||||
public void addEffect(Effect e) {
|
||||
effects.add(e);
|
||||
}
|
||||
@@ -70,7 +67,6 @@ public class DelayLineStore {
|
||||
for (Effect e : effects) {
|
||||
e.init(sf);
|
||||
}
|
||||
purge();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package uk.co.majenko.audiobookrecorder;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface Effect {
|
||||
public double process(double sample);
|
||||
public void process(double[][] samples);
|
||||
public String getName();
|
||||
public ArrayList<Effect> getChildEffects();
|
||||
public void dump();
|
||||
|
||||
@@ -16,12 +16,10 @@ public class EffectGroup implements Effect {
|
||||
effects = new ArrayList<Effect>();
|
||||
}
|
||||
|
||||
public double process(double sample) {
|
||||
double out = sample;
|
||||
public void process(double[][] samples) {
|
||||
for (Effect e : effects) {
|
||||
out = e.process(out);
|
||||
e.process(samples);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
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,24 +22,25 @@ public class LFO implements Effect {
|
||||
phase = p;
|
||||
}
|
||||
|
||||
public double process(double sample) {
|
||||
double v = Math.sin(phase);
|
||||
phase += sampleStep;
|
||||
if (phase > (Math.PI * 2d)) {
|
||||
phase -= (Math.PI * 2d);
|
||||
}
|
||||
public void process(double[][] samples) {
|
||||
for (double[] sample : samples) {
|
||||
double v = Math.sin(phase);
|
||||
phase += sampleStep;
|
||||
if (phase > (Math.PI * 2d)) {
|
||||
phase -= (Math.PI * 2d);
|
||||
}
|
||||
|
||||
// // Make it between 0 and 1.
|
||||
// v = 1d + v;
|
||||
// v /= 2d;
|
||||
|
||||
// Multiply it by the gain factor
|
||||
v *= depth;
|
||||
// Multiply it by the gain factor
|
||||
v *= depth;
|
||||
|
||||
// Apply it to the sample
|
||||
sample += (sample * v);
|
||||
|
||||
return sample;
|
||||
// Apply it to the sample
|
||||
sample[Sentence.LEFT] += (sample[Sentence.LEFT] * v);
|
||||
sample[Sentence.RIGHT] += (sample[Sentence.RIGHT] * v);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() { return "Low Frequency Oscillator (" + frequency + " Hz, " + (depth * 100d) + "%)"; }
|
||||
|
||||
@@ -44,8 +44,6 @@ public class Options extends JDialog {
|
||||
JSpinner etherealAttenuation;
|
||||
JSpinner etherealOffset;
|
||||
|
||||
JTextField havenApiKey;
|
||||
|
||||
JTextField externalEditor;
|
||||
|
||||
JTextArea startupScript;
|
||||
@@ -325,8 +323,7 @@ public class Options extends JDialog {
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
enableParsing = addCheckBox(optionsPanel, "Enable automatic speech-to-text submission", getBoolean("process.haven.auto"));
|
||||
havenApiKey = addTextField(optionsPanel, "Haven OnDemand API Key", get("process.haven.apikey"));
|
||||
enableParsing = addCheckBox(optionsPanel, "Enable automatic sphinx speech-to-text (**SLOW**)", getBoolean("process.sphinx"));
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
@@ -584,9 +581,7 @@ public class Options extends JDialog {
|
||||
|
||||
defaultPrefs.put("audio.export.bitrate", "256000");
|
||||
defaultPrefs.put("audio.export.samplerate", "44100");
|
||||
|
||||
defaultPrefs.put("process.sphinx", "false");
|
||||
defaultPrefs.put("process.haven.apikey", "");
|
||||
|
||||
defaultPrefs.put("editor.external", "");
|
||||
|
||||
@@ -710,7 +705,6 @@ public class Options extends JDialog {
|
||||
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
||||
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
||||
set("process.sphinx", enableParsing.isSelected());
|
||||
set("process.haven.apikey", havenApiKey.getText());
|
||||
set("editor.external", externalEditor.getText());
|
||||
set("cache.size", cacheSize.getValue());
|
||||
set("audio.recording.trim.fft", fftThreshold.getValue());
|
||||
@@ -781,9 +775,10 @@ public class Options extends JDialog {
|
||||
}
|
||||
|
||||
public static KVPair[] getTrimMethods() {
|
||||
KVPair[] pairs = new KVPair[2];
|
||||
pairs[0] = new KVPair<String, String>("peak", "Peak Amplitude");
|
||||
pairs[1] = new KVPair<String, String>("fft", "FFT Analysis");
|
||||
KVPair[] pairs = new KVPair[3];
|
||||
pairs[0] = new KVPair<String, String>("none", "None");
|
||||
pairs[1] = new KVPair<String, String>("peak", "Peak Amplitude");
|
||||
pairs[2] = new KVPair<String, String>("fft", "FFT Analysis");
|
||||
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.util.EntityUtils;
|
||||
|
||||
import edu.cmu.sphinx.api.*;
|
||||
import edu.cmu.sphinx.decoder.adaptation.*;
|
||||
import edu.cmu.sphinx.result.*;
|
||||
|
||||
import org.json.*;
|
||||
|
||||
import java.util.Timer;
|
||||
@@ -49,25 +53,22 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
double gain = 1.0d;
|
||||
|
||||
String havenJobId = "";
|
||||
|
||||
// 0: Not processed
|
||||
// 1: Submitted
|
||||
// 2: Procesisng finished
|
||||
// 3: Processing failed
|
||||
int havenStatus = 0;
|
||||
|
||||
String overrideText = null;
|
||||
|
||||
public void setOverrideText(String s) { overrideText = s; }
|
||||
public String getOverrideText() { return overrideText; }
|
||||
|
||||
public static final int LEFT = 0;
|
||||
public static final int RIGHT = 1;
|
||||
|
||||
TargetDataLine line;
|
||||
AudioInputStream inputStream;
|
||||
AudioFormat storedFormat = null;
|
||||
double storedLength = -1d;
|
||||
|
||||
double[] audioData = null;
|
||||
double[][] audioData = null;
|
||||
|
||||
// double[][] processedAudio = null;
|
||||
|
||||
RecordingThread recordingThread;
|
||||
|
||||
@@ -137,7 +138,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Sentence() {
|
||||
super("");
|
||||
id = UUID.randomUUID().toString();
|
||||
@@ -176,63 +176,43 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
audioData = null;
|
||||
// processedAudio = null;
|
||||
storedFormat = null;
|
||||
storedLength = -1;
|
||||
|
||||
if (!id.equals("room-noise")) {
|
||||
String tm = Options.get("audio.recording.trim");
|
||||
if (tm.equals("peak")) {
|
||||
autoTrimSamplePeak();
|
||||
autoTrimSamplePeak(true);
|
||||
} else if (tm.equals("fft")) {
|
||||
autoTrimSampleFFT();
|
||||
autoTrimSampleFFT(true);
|
||||
}
|
||||
if (Options.getBoolean("process.haven.auto")) {
|
||||
if (Options.getBoolean("process.sphinx")) {
|
||||
recognise();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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() {
|
||||
autoTrimSampleFFT(false);
|
||||
}
|
||||
|
||||
public void autoTrimSampleFFT() {
|
||||
public void autoTrimSampleFFT(boolean useRaw) {
|
||||
crossStartOffset = -1;
|
||||
crossEndOffset = -1;
|
||||
double[] samples = getProcessedAudioData();
|
||||
double[][] samples;
|
||||
if (useRaw) {
|
||||
samples = getRawAudioData();
|
||||
} else {
|
||||
samples = getProcessedAudioData();
|
||||
}
|
||||
if (samples == null) return;
|
||||
|
||||
int blocks = samples.length / 4096 + 1;
|
||||
@@ -246,7 +226,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
for (int j = 0; j < 4096; j++) {
|
||||
if (i + j < samples.length) {
|
||||
real[j] = samples[i+j];
|
||||
real[j] = (samples[i+j][LEFT] + samples[i+j][RIGHT]) / 2d;
|
||||
imag[j] = 0;
|
||||
} else {
|
||||
real[j] = 0;
|
||||
@@ -313,9 +293,18 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
public void autoTrimSamplePeak() {
|
||||
autoTrimSamplePeak(false);
|
||||
}
|
||||
|
||||
public void autoTrimSamplePeak(boolean useRaw) {
|
||||
crossStartOffset = -1;
|
||||
crossEndOffset = -1;
|
||||
double[] samples = getProcessedAudioData();
|
||||
double[][] samples;
|
||||
if (useRaw) {
|
||||
samples = getRawAudioData();
|
||||
} else {
|
||||
samples = getProcessedAudioData();
|
||||
}
|
||||
if (samples == null) return;
|
||||
double noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
||||
noiseFloor *= 1.1;
|
||||
@@ -323,7 +312,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
// Find start
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
startOffset = i;
|
||||
if (Math.abs(samples[i]) > noiseFloor) {
|
||||
if (Math.abs((samples[i][LEFT] + samples[i][RIGHT])/2d) > noiseFloor) {
|
||||
startOffset --;
|
||||
if (startOffset < 0) startOffset = 0;
|
||||
break;
|
||||
@@ -338,7 +327,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
for (int i = samples.length-1; i >= 0; i--) {
|
||||
endOffset = i;
|
||||
if (Math.abs(samples[i]) > noiseFloor) {
|
||||
if (Math.abs((samples[i][LEFT] + samples[i][RIGHT])/2d) > noiseFloor) {
|
||||
endOffset ++;
|
||||
if (endOffset >= samples.length-1) endOffset = samples.length-1;
|
||||
break;
|
||||
@@ -396,7 +385,11 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -494,8 +487,57 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
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() {
|
||||
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) {
|
||||
@@ -516,6 +558,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
public void clearCache() {
|
||||
audioData = null;
|
||||
// processedAudio = null;
|
||||
}
|
||||
|
||||
public boolean lockedInCache() {
|
||||
@@ -523,7 +566,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
public int findNearestZeroCrossing(int pos, int range) {
|
||||
double[] data = getProcessedAudioData();
|
||||
double[][] data = getProcessedAudioData();
|
||||
if (data == null) return 0;
|
||||
if (data.length == 0) return 0;
|
||||
|
||||
@@ -533,19 +576,19 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
int backwards = pos;
|
||||
int forwards = pos;
|
||||
|
||||
double backwardsPrev = data[backwards];
|
||||
double forwardsPrev = data[forwards];
|
||||
double backwardsPrev = (data[backwards][LEFT] + data[backwards][RIGHT]) / 2d;
|
||||
double forwardsPrev = (data[forwards][LEFT] + data[forwards][RIGHT]) / 2d;
|
||||
|
||||
while (backwards > 0 || forwards < data.length-2) {
|
||||
|
||||
if (forwards < data.length-2) forwards++;
|
||||
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;
|
||||
}
|
||||
|
||||
if (forwardsPrev < 0 && data[forwards] >= 0) {
|
||||
if (forwardsPrev < 0 && ((data[forwards][LEFT] + data[forwards][RIGHT]) / 2d) >= 0) {
|
||||
return forwards;
|
||||
}
|
||||
|
||||
@@ -554,8 +597,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
return pos;
|
||||
}
|
||||
|
||||
backwardsPrev = data[backwards];
|
||||
forwardsPrev = data[forwards];
|
||||
backwardsPrev = (data[backwards][LEFT] + data[backwards][RIGHT]) / 2d;
|
||||
forwardsPrev = (data[forwards][LEFT] + data[forwards][RIGHT]) / 2d;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
@@ -596,149 +639,18 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
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() {
|
||||
double oldGain = gain;
|
||||
gain = 1.0d;
|
||||
double[] samples = getProcessedAudioData();
|
||||
double[][] samples = getProcessedAudioData();
|
||||
gain = oldGain;
|
||||
if (samples == null) {
|
||||
return 0;
|
||||
}
|
||||
double ms = 0;
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
if (Math.abs(samples[i]) > ms) {
|
||||
ms = Math.abs(samples[i]);
|
||||
if (Math.abs((samples[i][LEFT] + samples[i][RIGHT]) / 2d) > ms) {
|
||||
ms = Math.abs((samples[i][LEFT] + samples[i][RIGHT]) / 2d);
|
||||
}
|
||||
}
|
||||
return ms;
|
||||
@@ -756,8 +668,11 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
public void setGain(double g) {
|
||||
if (g <= 0.0001d) g = 1.0d;
|
||||
if (g == gain) return;
|
||||
|
||||
if (gain != g) {
|
||||
clearCache();
|
||||
}
|
||||
gain = g;
|
||||
clearCache();
|
||||
}
|
||||
|
||||
public double getGain() {
|
||||
@@ -938,19 +853,18 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
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();
|
||||
int frameSize = format.getFrameSize();
|
||||
int chans = format.getChannels();
|
||||
int bytes = frameSize / chans;
|
||||
|
||||
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++) {
|
||||
|
||||
s.read(frame);
|
||||
int sample = 0;
|
||||
if (chans == 2) { // Stereo
|
||||
int ll = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||
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;
|
||||
if ((left & 0x8000) == 0x8000) left |= 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 {
|
||||
int l = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||
int h = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||
sample = (h << 8) | l;
|
||||
if ((sample & 0x8000) == 0x8000) sample |= 0xFFFF0000;
|
||||
int mono = (h << 8) | l;
|
||||
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;
|
||||
}
|
||||
|
||||
public double[] getDoubleDataS24LE(AudioInputStream s, AudioFormat format) throws IOException {
|
||||
public double[][] getDoubleDataS24LE(AudioInputStream s, AudioFormat format) throws IOException {
|
||||
long len = s.getFrameLength();
|
||||
int frameSize = format.getFrameSize();
|
||||
int chans = format.getChannels();
|
||||
int bytes = frameSize / chans;
|
||||
|
||||
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++) {
|
||||
|
||||
@@ -997,22 +913,22 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
int right = (rh << 16) | (rm << 8) | rl;
|
||||
if ((left & 0x800000) == 0x800000) left |= 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 {
|
||||
int l = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||
int m = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||
int h = frame[2] >= 0 ? frame[2] : 256 + frame[2];
|
||||
sample = (h << 16) | (m << 8) | l;
|
||||
if ((sample & 0x800000) == 0x800000) sample |= 0xFF000000;
|
||||
int mono = (h << 16) | (m << 8) | l;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void loadFile() {
|
||||
if (audioData != null) return;
|
||||
|
||||
@@ -1021,7 +937,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
||||
AudioFormat format = getAudioFormat();
|
||||
|
||||
double[] samples = null;
|
||||
double[][] samples = null;
|
||||
|
||||
switch (format.getSampleSizeInBits()) {
|
||||
case 16:
|
||||
@@ -1040,84 +956,101 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
}
|
||||
|
||||
public double[] getProcessedAudioData() {
|
||||
synchronized public double[][] getRawAudioData() {
|
||||
loadFile();
|
||||
return audioData;
|
||||
}
|
||||
|
||||
synchronized public double[][] getProcessedAudioData() {
|
||||
loadFile();
|
||||
// if (processedAudio != null) return processedAudio;
|
||||
|
||||
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++) {
|
||||
samples[i] = audioData[i];
|
||||
processedAudio[i][LEFT] = audioData[i][LEFT];
|
||||
processedAudio[i][RIGHT] = audioData[i][RIGHT];
|
||||
}
|
||||
// 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());
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
samples[i] = eff.process(samples[i]);
|
||||
eff.process(processedAudio);
|
||||
}
|
||||
|
||||
if (effectChain != null) {
|
||||
// Don't double up the default chain
|
||||
if (!effectChain.equals(def)) {
|
||||
eff = AudiobookRecorder.window.effects.get(effectChain);
|
||||
if (eff != null) {
|
||||
eff.init(getAudioFormat().getFrameRate());
|
||||
eff.process(processedAudio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// Add final master gain stage
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
samples[i] = samples[i] * gain;
|
||||
for (int i = 0; i < processedAudio.length; i++) {
|
||||
processedAudio[i][LEFT] *= gain;
|
||||
processedAudio[i][RIGHT] *= gain;
|
||||
}
|
||||
return samples;
|
||||
return processedAudio;
|
||||
}
|
||||
|
||||
public double[] getDoubleAudioData() {
|
||||
public double[][] getDoubleAudioData() {
|
||||
return getProcessedAudioData();
|
||||
}
|
||||
|
||||
public double[] getCroppedAudioData() {
|
||||
double[] inSamples = getDoubleAudioData();
|
||||
public double[][] getCroppedAudioData() {
|
||||
double[][] inSamples = getDoubleAudioData();
|
||||
if (inSamples == null) return null;
|
||||
updateCrossings();
|
||||
|
||||
int length = crossEndOffset - crossStartOffset;
|
||||
|
||||
double[] samples = new double[length];
|
||||
double[][] samples = new double[length][2];
|
||||
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;
|
||||
}
|
||||
|
||||
public byte[] getPCMData() {
|
||||
double[] croppedData = getCroppedAudioData();
|
||||
double[][] croppedData = getCroppedAudioData();
|
||||
if (croppedData == null) return null;
|
||||
int length = croppedData.length;
|
||||
byte[] pcmData = new byte[length * 2];
|
||||
byte[] pcmData = new byte[length * 4];
|
||||
for (int i = 0; i < length; i++) {
|
||||
double sd = croppedData[i] * 32768d;
|
||||
double sd = croppedData[i][LEFT] * 32768d;
|
||||
int si = (int)sd;
|
||||
if (si > 32767) si = 32767;
|
||||
if (si < -32768) si = -32768;
|
||||
pcmData[i * 2] = (byte)(si & 0xFF);
|
||||
pcmData[(i * 2) + 1] = (byte)((si & 0xFF00) >> 8);
|
||||
pcmData[i * 4] = (byte)(si & 0xFF);
|
||||
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;
|
||||
}
|
||||
|
||||
public void setEffectChain(String key) {
|
||||
if ((effectChain != null) && (!effectChain.equals(key))) {
|
||||
clearCache();
|
||||
}
|
||||
effectChain = key;
|
||||
}
|
||||
|
||||
public String getEffectChain() {
|
||||
if (effectChain == null) return AudiobookRecorder.window.defaultEffectChain;
|
||||
if (effectChain == null) return "none";
|
||||
return effectChain;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import javax.sound.sampled.*;
|
||||
|
||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
||||
|
||||
double[] samples = null;
|
||||
double[][] samples = null;
|
||||
|
||||
int leftMarker = 0;
|
||||
int rightMarker = 0;
|
||||
@@ -92,7 +92,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
double lmax = 0;
|
||||
|
||||
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) {
|
||||
have += sample;
|
||||
hcnt++;
|
||||
@@ -189,7 +189,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setData(double[] s) {
|
||||
public void setData(double[][] s) {
|
||||
samples = s;
|
||||
playMarker = 0;
|
||||
repaint();
|
||||
|
||||
Reference in New Issue
Block a user