Added groundwork for multiple EQ profiles
This commit is contained in:
@@ -84,6 +84,8 @@ public class AudiobookRecorder extends JFrame {
|
||||
JButtonSpacePlay reprocessAudioPeak;
|
||||
JButtonSpacePlay normalizeAudio;
|
||||
|
||||
JComboBox<String> eqProfile;
|
||||
|
||||
Thread playingThread = null;
|
||||
|
||||
Random rng = new Random();
|
||||
@@ -421,10 +423,12 @@ public class AudiobookRecorder extends JFrame {
|
||||
JToolBar controlsTop = new JToolBar(JToolBar.HORIZONTAL);
|
||||
JToolBar controlsLeft = new JToolBar(JToolBar.VERTICAL);
|
||||
JToolBar controlsRight = new JToolBar(JToolBar.VERTICAL);
|
||||
JToolBar controlsBottom = new JToolBar(JToolBar.HORIZONTAL);
|
||||
|
||||
controlsTop.setFloatable(false);
|
||||
controlsLeft.setFloatable(false);
|
||||
controlsRight.setFloatable(false);
|
||||
controlsBottom.setFloatable(false);
|
||||
|
||||
controlsLeft.add(reprocessAudioFFT);
|
||||
controlsLeft.add(reprocessAudioPeak);
|
||||
@@ -445,6 +449,11 @@ public class AudiobookRecorder extends JFrame {
|
||||
selectedSentence.setLocked(false);
|
||||
}
|
||||
}
|
||||
postSentenceGap.setEnabled(!selectedSentence.isLocked());
|
||||
gainPercent.setEnabled(!selectedSentence.isLocked());
|
||||
reprocessAudioFFT.setEnabled(!selectedSentence.isLocked());
|
||||
reprocessAudioPeak.setEnabled(!selectedSentence.isLocked());
|
||||
|
||||
bookTreeModel.reload(selectedSentence);
|
||||
}
|
||||
});
|
||||
@@ -518,9 +527,27 @@ public class AudiobookRecorder extends JFrame {
|
||||
});
|
||||
controlsRight.add(zoomOut);
|
||||
|
||||
controlsBottom.add(new JLabel("EQ Profile: "));
|
||||
|
||||
String[] profiles = new String[2];
|
||||
profiles[0] = "Default";
|
||||
profiles[1] = "Phone";
|
||||
|
||||
eqProfile = new JComboBox<String>(profiles);
|
||||
controlsBottom.add(eqProfile);
|
||||
|
||||
eqProfile.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (selectedSentence != null) {
|
||||
selectedSentence.setEQProfile(eqProfile.getSelectedIndex());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sampleControl.add(controlsTop, BorderLayout.NORTH);
|
||||
sampleControl.add(controlsLeft, BorderLayout.WEST);
|
||||
sampleControl.add(controlsRight, BorderLayout.EAST);
|
||||
sampleControl.add(controlsBottom, BorderLayout.SOUTH);
|
||||
|
||||
centralPanel.add(sampleControl, BorderLayout.SOUTH);
|
||||
|
||||
@@ -1413,8 +1440,10 @@ public class AudiobookRecorder extends JFrame {
|
||||
prefs.setProperty("audio.recording.resolution", "" + book.getResolution());
|
||||
prefs.setProperty("audio.recording.channels", "" + book.getChannels());
|
||||
|
||||
for (int i = 0; i < 31; i++) {
|
||||
prefs.setProperty("audio.eq." + i, String.format("%.3f", book.equaliser.getChannel(i)));
|
||||
for (int e = 0; e < book.equaliser.length; e++) {
|
||||
for (int i = 0; i < 31; i++) {
|
||||
prefs.setProperty(String.format("audio.eq.profiles.%d.%d", e, i), String.format("%.3f", book.equaliser[e].getChannel(i)));
|
||||
}
|
||||
}
|
||||
|
||||
for (Enumeration o = book.children(); o.hasMoreElements();) {
|
||||
@@ -1437,6 +1466,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
prefs.setProperty(String.format("%s.sentence.%08d.attention", keybase, i), snt.getAttentionFlag() ? "true" : "false");
|
||||
prefs.setProperty(String.format("%s.sentence.%08d.ethereal", keybase, i), snt.getEthereal() ? "true" : "false");
|
||||
prefs.setProperty(String.format("%s.sentence.%08d.gain", keybase, i), String.format("%.8f", snt.getGain()));
|
||||
prefs.setProperty(String.format("%s.sentence.%08d.eqprofile", keybase, i), Integer.toString(snt.getEQProfile()));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -1512,11 +1542,13 @@ public class AudiobookRecorder extends JFrame {
|
||||
book.setResolution(res);
|
||||
|
||||
|
||||
for (int i = 0; i < 31; i++) {
|
||||
if (prefs.getProperty("audio.eq." + i) == null) {
|
||||
book.equaliser.setChannel(i, Options.getFloat("audio.eq." + i));
|
||||
} else {
|
||||
book.equaliser.setChannel(i, Utils.s2f(prefs.getProperty("audio.eq." + i)));
|
||||
for (int e = 0; e < book.equaliser.length; e++) {
|
||||
for (int i = 0; i < 31; i++) {
|
||||
if (prefs.getProperty(String.format("audio.eq.profiles.%d.%d", e, i)) == null) {
|
||||
book.equaliser[e].setChannel(i, Options.getFloat(String.format("audio.eq.profiles.%d.%d", e, i)));
|
||||
} else {
|
||||
book.equaliser[e].setChannel(i, Utils.s2f(prefs.getProperty("audio.eq." + i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1548,8 +1580,10 @@ public class AudiobookRecorder extends JFrame {
|
||||
locked.setSelected(s.isLocked());
|
||||
attention.setSelected(s.getAttentionFlag());
|
||||
ethereal.setSelected(s.getEthereal());
|
||||
eqProfile.setSelectedIndex(s.getEQProfile());
|
||||
|
||||
postSentenceGap.setEnabled(!s.isLocked());
|
||||
gainPercent.setEnabled(!s.isLocked());
|
||||
reprocessAudioFFT.setEnabled(!s.isLocked());
|
||||
reprocessAudioPeak.setEnabled(!s.isLocked());
|
||||
} else {
|
||||
@@ -1557,6 +1591,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
sampleWaveform.clearData();
|
||||
postSentenceGap.setValue(0);
|
||||
gainPercent.setValue(100);
|
||||
eqProfile.setSelectedIndex(0);
|
||||
locked.setSelected(false);
|
||||
attention.setSelected(false);
|
||||
ethereal.setSelected(false);
|
||||
@@ -1601,6 +1636,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
s.setAttentionFlag(Utils.s2b(prefs.getProperty(String.format("chapter.audition.sentence.%08d.attention", i))));
|
||||
s.setEthereal(Utils.s2b(prefs.getProperty(String.format("chapter.audition.sentence.%08d.ethereal", i))));
|
||||
s.setGain(Utils.s2d(prefs.getProperty(String.format("chapter.audition.sentence.%08d.gain", i))));
|
||||
s.setEQProfile(Utils.s2i(prefs.getProperty(String.format("chapter.audition.sentence.%08d.eqprofile", i))));
|
||||
bookTreeModel.insertNodeInto(s, c, c.getChildCount());
|
||||
}
|
||||
|
||||
@@ -1622,6 +1658,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
s.setAttentionFlag(Utils.s2b(prefs.getProperty(String.format("chapter.open.sentence.%08d.attention", i))));
|
||||
s.setEthereal(Utils.s2b(prefs.getProperty(String.format("chapter.open.sentence.%08d.ethereal", i))));
|
||||
s.setGain(Utils.s2d(prefs.getProperty(String.format("chapter.open.sentence.%08d.gain", i))));
|
||||
s.setEQProfile(Utils.s2i(prefs.getProperty(String.format("chapter.open.sentence.%08d.eqprofile", i))));
|
||||
bookTreeModel.insertNodeInto(s, c, c.getChildCount());
|
||||
}
|
||||
|
||||
@@ -1649,6 +1686,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
s.setAttentionFlag(Utils.s2b(prefs.getProperty(String.format("chapter.%04d.sentence.%08d.attention", cno, i))));
|
||||
s.setEthereal(Utils.s2b(prefs.getProperty(String.format("chapter.%04d.sentence.%08d.ethereal", cno, i))));
|
||||
s.setGain(Utils.s2d(prefs.getProperty(String.format("chapter.%04d.sentence.%08d.gain", cno, i))));
|
||||
s.setEQProfile(Utils.s2i(prefs.getProperty(String.format("chapter.%04d.sentence.%08d.eqprofile", cno, i))));
|
||||
bookTreeModel.insertNodeInto(s, c, c.getChildCount());
|
||||
}
|
||||
}
|
||||
@@ -1671,6 +1709,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
s.setAttentionFlag(Utils.s2b(prefs.getProperty(String.format("chapter.close.sentence.%08d.attention", i))));
|
||||
s.setEthereal(Utils.s2b(prefs.getProperty(String.format("chapter.close.sentence.%08d.ethereal", i))));
|
||||
s.setGain(Utils.s2d(prefs.getProperty(String.format("chapter.close.sentence.%08d.gain", i))));
|
||||
s.setEQProfile(Utils.s2i(prefs.getProperty(String.format("chapter.close.sentence.%08d.eqprofile", i))));
|
||||
bookTreeModel.insertNodeInto(s, c, c.getChildCount());
|
||||
}
|
||||
|
||||
@@ -1980,7 +2019,11 @@ public class AudiobookRecorder extends JFrame {
|
||||
if (equaliserWindow == null) {
|
||||
equaliserWindow = new JDialog();
|
||||
equaliserWindow.setTitle("Equaliser");
|
||||
equaliserWindow.add(new JScrollPane(book.equaliser));
|
||||
JTabbedPane tabs = new JTabbedPane();
|
||||
equaliserWindow.add(tabs);
|
||||
for (int i = 0; i < book.equaliser.length; i++) {
|
||||
tabs.add(book.equaliser[i].getName(), new JScrollPane(book.equaliser[i]));
|
||||
}
|
||||
equaliserWindow.pack();
|
||||
}
|
||||
equaliserWindow.setVisible(true);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
|
||||
ImageIcon icon;
|
||||
|
||||
public Equaliser equaliser;
|
||||
public Equaliser[] equaliser = new Equaliser[2];
|
||||
|
||||
float[] eqChannels = new float[31];
|
||||
|
||||
@@ -36,7 +36,8 @@ public class Book extends DefaultMutableTreeNode {
|
||||
|
||||
prefs = p;
|
||||
name = bookname;
|
||||
equaliser = new Equaliser();
|
||||
equaliser[0] = new Equaliser("Default");
|
||||
equaliser[1] = new Equaliser("Phone");
|
||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import davaguine.jeq.core.IIRControls;
|
||||
public class Equaliser extends JPanel {
|
||||
|
||||
EqualiserChannel channels[];
|
||||
String name;
|
||||
|
||||
static final double[] frequencies = {
|
||||
20d, 25d, 31.5d, 40d, 50d, 63d, 80d, 100d, 125d, 160d, 200d,
|
||||
@@ -22,9 +23,11 @@ public class Equaliser extends JPanel {
|
||||
20000d
|
||||
};
|
||||
|
||||
public Equaliser() {
|
||||
public Equaliser(String n) {
|
||||
super();
|
||||
|
||||
name = n;
|
||||
|
||||
channels = new EqualiserChannel[31];
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
@@ -96,4 +99,8 @@ public class Equaliser extends JPanel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
31
src/uk/co/majenko/audiobookrecorder/KVPair.java
Normal file
31
src/uk/co/majenko/audiobookrecorder/KVPair.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
public class KVPair<K,V> implements Comparable {
|
||||
public K key;
|
||||
public V value;
|
||||
|
||||
public KVPair(K k, V v) {
|
||||
key = k;
|
||||
value = v;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (String)value;
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
// if (o instanceof KVPair) {
|
||||
// KVPair ko = (KVPair)o;
|
||||
// return key.compareTo(ko.key);
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
public K getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public V getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -47,28 +47,6 @@ public class Options extends JDialog {
|
||||
static HashMap<String, String> defaultPrefs;
|
||||
static Preferences prefs = null;
|
||||
|
||||
static class KVPair implements Comparable {
|
||||
public String key;
|
||||
public String value;
|
||||
|
||||
public KVPair(String k, String v) {
|
||||
key = k;
|
||||
value = v;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
if (o instanceof KVPair) {
|
||||
KVPair ko = (KVPair)o;
|
||||
return key.compareTo(ko.key);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
class JButtonObject extends JButton {
|
||||
Object object;
|
||||
public JButtonObject(String s, Object o) {
|
||||
@@ -312,7 +290,7 @@ public class Options extends JDialog {
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
tabs.add("Options", new JScrollPane(optionsPanel));
|
||||
equaliser = new Equaliser();
|
||||
equaliser = new Equaliser("Default");
|
||||
for (int i = 0; i < 31; i++) {
|
||||
equaliser.setChannel(i, Options.getFloat("audio.eq." + i));
|
||||
}
|
||||
@@ -387,8 +365,8 @@ public class Options extends JDialog {
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
static KVPair[] getRecordingMixerList() {
|
||||
TreeSet<KVPair> list = new TreeSet<KVPair>();
|
||||
static KVPair<String, String>[] getRecordingMixerList() {
|
||||
TreeSet<KVPair<String, String>> list = new TreeSet<KVPair<String, String>>();
|
||||
|
||||
AudioFormat stereoFormat = new AudioFormat(44100f, 16, 2, true, false);
|
||||
AudioFormat monoFormat = new AudioFormat(44100f, 16, 1, true, false);
|
||||
@@ -415,7 +393,7 @@ public class Options extends JDialog {
|
||||
}
|
||||
|
||||
if (supported) {
|
||||
KVPair p = new KVPair(i.getName(), i.getName()); //i.getDescription());
|
||||
KVPair<String, String> p = new KVPair<String, String>(i.getName(), i.getName()); //i.getDescription());
|
||||
list.add(p);
|
||||
}
|
||||
}
|
||||
@@ -424,7 +402,7 @@ public class Options extends JDialog {
|
||||
}
|
||||
|
||||
static KVPair[] getPlaybackMixerList() {
|
||||
TreeSet<KVPair> list = new TreeSet<KVPair>();
|
||||
TreeSet<KVPair<String, String>> list = new TreeSet<KVPair<String, String>>();
|
||||
|
||||
AudioFormat stereoFormat = new AudioFormat(44100f, 16, 2, true, false);
|
||||
AudioFormat monoFormat = new AudioFormat(44100f, 16, 1, true, false);
|
||||
@@ -452,7 +430,7 @@ public class Options extends JDialog {
|
||||
|
||||
|
||||
if (supported) {
|
||||
KVPair p = new KVPair(i.getName(), i.getName()); //i.getDescription());
|
||||
KVPair<String, String> p = new KVPair<String, String>(i.getName(), i.getName()); //i.getDescription());
|
||||
list.add(p);
|
||||
}
|
||||
}
|
||||
@@ -462,16 +440,16 @@ public class Options extends JDialog {
|
||||
|
||||
static KVPair[] getChannelCountList() {
|
||||
KVPair[] l = new KVPair[2];
|
||||
l[0] = new KVPair("1", "Mono");
|
||||
l[1] = new KVPair("2", "Stereo");
|
||||
l[0] = new KVPair<String, String>("1", "Mono");
|
||||
l[1] = new KVPair<String, String>("2", "Stereo");
|
||||
return l;
|
||||
}
|
||||
|
||||
static KVPair[] getSampleRateList() {
|
||||
KVPair[] l = new KVPair[3];
|
||||
l[0] = new KVPair("44100", "44100");
|
||||
l[1] = new KVPair("48000", "48000");
|
||||
l[2] = new KVPair("96000", "96000");
|
||||
l[0] = new KVPair<String, String>("44100", "44100");
|
||||
l[1] = new KVPair<String, String>("48000", "48000");
|
||||
l[2] = new KVPair<String, String>("96000", "96000");
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -483,7 +461,7 @@ public class Options extends JDialog {
|
||||
KVPair[] playbackMixers = getPlaybackMixerList();
|
||||
|
||||
if (recordingMixers.length > 0) {
|
||||
defaultPrefs.put("audio.recording.device", recordingMixers[0].key);
|
||||
defaultPrefs.put("audio.recording.device", (String)recordingMixers[0].key);
|
||||
} else {
|
||||
defaultPrefs.put("audio.recording.device", "");
|
||||
}
|
||||
@@ -492,7 +470,7 @@ public class Options extends JDialog {
|
||||
defaultPrefs.put("audio.recording.resolution", "16");
|
||||
defaultPrefs.put("audio.recording.trim", "peak");
|
||||
if (playbackMixers.length > 0) {
|
||||
defaultPrefs.put("audio.playback.device", playbackMixers[0].key);
|
||||
defaultPrefs.put("audio.playback.device", (String)playbackMixers[0].key);
|
||||
} else {
|
||||
defaultPrefs.put("audio.playback.device", "");
|
||||
}
|
||||
@@ -702,23 +680,23 @@ public class Options extends JDialog {
|
||||
|
||||
public static KVPair[] getBitrates() {
|
||||
KVPair[] pairs = new KVPair[4];
|
||||
pairs[0] = new KVPair("128000", "128kbps");
|
||||
pairs[1] = new KVPair("192000", "192kbps");
|
||||
pairs[2] = new KVPair("256000", "256kbps");
|
||||
pairs[3] = new KVPair("320000", "320kbps");
|
||||
pairs[0] = new KVPair<String, String>("128000", "128kbps");
|
||||
pairs[1] = new KVPair<String, String>("192000", "192kbps");
|
||||
pairs[2] = new KVPair<String, String>("256000", "256kbps");
|
||||
pairs[3] = new KVPair<String, String>("320000", "320kbps");
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public static KVPair[] getResolutionList() {
|
||||
KVPair[] pairs = new KVPair[1];
|
||||
pairs[0] = new KVPair("16", "16 Bit");
|
||||
pairs[0] = new KVPair<String, String>("16", "16 Bit");
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public static KVPair[] getTrimMethods() {
|
||||
KVPair[] pairs = new KVPair[2];
|
||||
pairs[0] = new KVPair("peak", "Peak Amplitude");
|
||||
pairs[1] = new KVPair("fft", "FFT Analysis");
|
||||
pairs[0] = new KVPair<String, String>("peak", "Peak Amplitude");
|
||||
pairs[1] = new KVPair<String, String>("fft", "FFT Analysis");
|
||||
return pairs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
boolean inSample;
|
||||
boolean attention = false;
|
||||
|
||||
int eqProfile = 0;
|
||||
|
||||
double gain = 1.0d;
|
||||
|
||||
String havenJobId = "";
|
||||
@@ -571,7 +573,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
EqualizerInputStream eq = new EqualizerInputStream(s, 31);
|
||||
AudioFormat format = getAudioFormat();
|
||||
IIRControls controls = eq.getControls();
|
||||
AudiobookRecorder.window.book.equaliser.apply(controls, format.getChannels());
|
||||
AudiobookRecorder.window.book.equaliser[eqProfile].apply(controls, format.getChannels());
|
||||
|
||||
int frameSize = format.getFrameSize();
|
||||
|
||||
@@ -609,7 +611,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
AudioFormat format = getAudioFormat();
|
||||
IIRControls controls = eq.getControls();
|
||||
AudiobookRecorder.window.book.equaliser.apply(controls, format.getChannels());
|
||||
AudiobookRecorder.window.book.equaliser[eqProfile].apply(controls, format.getChannels());
|
||||
|
||||
int frameSize = format.getFrameSize();
|
||||
int length = crossEndOffset - crossStartOffset;
|
||||
@@ -1036,8 +1038,19 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
}
|
||||
|
||||
public void normalize() {
|
||||
if (locked) return;
|
||||
int max = getPeakValue();
|
||||
setGain(23192d / max);
|
||||
double d = 23192d / max;
|
||||
if (d > 1.1d) d = 1.1d;
|
||||
setGain(d);
|
||||
}
|
||||
|
||||
public int getEQProfile() {
|
||||
return eqProfile;
|
||||
}
|
||||
|
||||
public void setEQProfile(int e) {
|
||||
eqProfile = e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user