Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| babd3d2052 | |||
| 9464839b4d | |||
| bcf7875414 | |||
| 732894a0fb |
@@ -1 +1 @@
|
|||||||
version=0.1.7
|
version=0.1.8
|
||||||
|
|||||||
@@ -25,11 +25,11 @@ public class AGC implements Effect {
|
|||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
gain = 1d;
|
gain = 1d;
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
double absSampleLeft = Math.abs(samples[i].left) * gain;
|
double absSampleLeft = Math.abs(samples[i][Sentence.LEFT]) * gain;
|
||||||
double absSampleRight = Math.abs(samples[i].right) * gain;
|
double absSampleRight = Math.abs(samples[i][Sentence.RIGHT]) * gain;
|
||||||
|
|
||||||
if (absSampleLeft > ceiling) {
|
if (absSampleLeft > ceiling) {
|
||||||
gain -= attack;
|
gain -= attack;
|
||||||
@@ -48,8 +48,8 @@ public class AGC implements Effect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
samples[i].left *= gain;
|
samples[i][Sentence.LEFT] *= gain;
|
||||||
samples[i].right *= gain;
|
samples[i][Sentence.RIGHT] *= gain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ public class Amplifier implements Effect {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
samples[i].left *= gain;
|
samples[i][Sentence.LEFT] *= gain;
|
||||||
samples[i].right *= gain;
|
samples[i][Sentence.RIGHT] *= gain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,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;
|
||||||
@@ -298,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);
|
||||||
|
|
||||||
@@ -312,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();
|
||||||
}
|
}
|
||||||
@@ -457,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);
|
||||||
|
|
||||||
@@ -1943,14 +1948,14 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
public double getNoiseFloor() {
|
public double getNoiseFloor() {
|
||||||
if (roomNoise == null) return 0;
|
if (roomNoise == null) return 0;
|
||||||
Sample[] 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].getMono()) > ms) {
|
if (Math.abs((samples[i][Sentence.LEFT] + samples[i][Sentence.RIGHT]) / 2d) > ms) {
|
||||||
ms = Math.abs(samples[i].getMono());
|
ms = Math.abs((samples[i][Sentence.LEFT] + samples[i][Sentence.RIGHT]) / 2d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2115,15 +2120,15 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
}
|
}
|
||||||
data = s.getPCMData();
|
data = s.getPCMData();
|
||||||
DefaultMutableTreeNode next = s.getNextSibling();
|
DefaultMutableTreeNode next = s.getNextSibling();
|
||||||
if (next != null) {
|
// if (next != null) {
|
||||||
Thread t = new Thread(new Runnable() {
|
// Thread t = new Thread(new Runnable() {
|
||||||
public void run() {
|
// public void run() {
|
||||||
Sentence ns = (Sentence)next;
|
// Sentence ns = (Sentence)next;
|
||||||
ns.getProcessedAudioData(); // Cache it
|
// ns.getProcessedAudioData(); // Cache it
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
t.start();
|
// 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;
|
||||||
@@ -2644,7 +2649,11 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
|
|
||||||
public void updateWaveform() {
|
public void updateWaveform() {
|
||||||
if (selectedSentence != null) {
|
if (selectedSentence != null) {
|
||||||
sampleWaveform.setData(selectedSentence.getDoubleAudioData());
|
if (rawAudio.isSelected()) {
|
||||||
|
sampleWaveform.setData(selectedSentence.getRawAudioData());
|
||||||
|
} else {
|
||||||
|
sampleWaveform.setData(selectedSentence.getDoubleAudioData());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2715,6 +2724,11 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
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) {
|
||||||
@@ -2815,6 +2829,11 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
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) {
|
||||||
@@ -2850,6 +2869,11 @@ public class AudiobookRecorder extends JFrame {
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Chain loadChain(Element root) {
|
||||||
|
Chain c = new Chain(root.getAttribute("src"));
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
public Pan loadPan(Element root) {
|
public Pan loadPan(Element root) {
|
||||||
Pan p = new Pan(Utils.s2d(root.getAttribute("pan")));
|
Pan p = new Pan(Utils.s2d(root.getAttribute("pan")));
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
@@ -89,24 +89,24 @@ public class Biquad implements Effect {
|
|||||||
setPeakGain(peakGainDB);
|
setPeakGain(peakGainDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
lz1 = 0d;
|
lz1 = 0d;
|
||||||
lz2 = 0d;
|
lz2 = 0d;
|
||||||
rz1 = 0d;
|
rz1 = 0d;
|
||||||
rz2 = 0d;
|
rz2 = 0d;
|
||||||
for (Sample in : samples) {
|
for (double[] in : samples) {
|
||||||
double lout = in.left * a0 + lz1;
|
double lout = in[Sentence.LEFT] * a0 + lz1;
|
||||||
|
|
||||||
lz1 = in.left * a1 + lz2 - b1 * lout;
|
lz1 = in[Sentence.LEFT] * a1 + lz2 - b1 * lout;
|
||||||
lz2 = in.left * a2 - b2 * lout;
|
lz2 = in[Sentence.LEFT] * a2 - b2 * lout;
|
||||||
|
|
||||||
double rout = in.right * a0 + rz1;
|
double rout = in[Sentence.RIGHT] * a0 + rz1;
|
||||||
|
|
||||||
rz1 = in.right * a1 + rz2 - b1 * rout;
|
rz1 = in[Sentence.RIGHT] * a1 + rz2 - b1 * rout;
|
||||||
rz2 = in.right * a2 - b2 * rout;
|
rz2 = in[Sentence.RIGHT] * a2 - b2 * rout;
|
||||||
|
|
||||||
in.left = lout;
|
in[Sentence.LEFT] = lout;
|
||||||
in.right = rout;
|
in[Sentence.RIGHT] = rout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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,12 +19,12 @@ public class Clipping implements Effect {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
for (Sample sample : samples) {
|
for (double[] sample : samples) {
|
||||||
if (sample.left > clip) sample.left = clip;
|
if (sample[Sentence.LEFT] > clip) sample[Sentence.LEFT] = clip;
|
||||||
if (sample.left < -clip) sample.left = -clip;
|
if (sample[Sentence.LEFT] < -clip) sample[Sentence.LEFT] = -clip;
|
||||||
if (sample.right > clip) sample.right = clip;
|
if (sample[Sentence.RIGHT] > clip) sample[Sentence.RIGHT] = clip;
|
||||||
if (sample.right < -clip) sample.right = -clip;
|
if (sample[Sentence.RIGHT] < -clip) sample[Sentence.RIGHT] = -clip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,22 +16,28 @@ public class DelayLine implements Effect {
|
|||||||
return "Delay Line (" + delayLines.size() + " lines)";
|
return "Delay Line (" + delayLines.size() + " lines)";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
Sample[] savedSamples = new Sample[samples.length];
|
double[][] savedSamples = new double[samples.length][2];
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
savedSamples[i] = new Sample(samples[i].left, samples[i].right);
|
savedSamples[i][Sentence.LEFT] = samples[i][Sentence.LEFT];
|
||||||
|
savedSamples[i][Sentence.RIGHT] = samples[i][Sentence.RIGHT];
|
||||||
}
|
}
|
||||||
if (wetOnly) {
|
if (wetOnly) {
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
samples[i].left = 0d;
|
samples[i][Sentence.LEFT] = 0d;
|
||||||
samples[i].right = 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 (DelayLineStore d : delayLines) {
|
||||||
Sample[] subSamples = new Sample[samples.length];
|
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
subSamples[i] = new Sample(savedSamples[i].left, savedSamples[i].right);
|
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
||||||
|
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
||||||
}
|
}
|
||||||
|
|
||||||
d.process(subSamples);
|
d.process(subSamples);
|
||||||
@@ -40,31 +46,31 @@ public class DelayLine implements Effect {
|
|||||||
int off = i + d.getSamples();
|
int off = i + d.getSamples();
|
||||||
if ((off < samples.length) && (off > 0)) {
|
if ((off < samples.length) && (off > 0)) {
|
||||||
|
|
||||||
Sample ns = mix(samples[off], subSamples[i]);
|
double[] ns = mix(samples[off], subSamples[i]);
|
||||||
samples[off].left = ns.left;
|
samples[off][Sentence.LEFT] = ns[Sentence.LEFT];
|
||||||
samples[off].right = ns.right;
|
samples[off][Sentence.RIGHT] = ns[Sentence.RIGHT];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sample mix(Sample a, Sample b) {
|
double[] mix(double[] a, double[] b) {
|
||||||
Sample out = new Sample(0, 0);
|
double[] out = new double[2];
|
||||||
|
|
||||||
if ((a.left < 0) && (b.left < 0)) {
|
if ((a[Sentence.LEFT] < 0) && (b[Sentence.LEFT] < 0)) {
|
||||||
out.left = (a.left + b.left) - (a.left * b.left);
|
out[Sentence.LEFT] = (a[Sentence.LEFT] + b[Sentence.LEFT]) - (a[Sentence.LEFT] * b[Sentence.LEFT]);
|
||||||
} else if ((a.left > 0) && (b.left > 0)) {
|
} else if ((a[Sentence.LEFT] > 0) && (b[Sentence.LEFT] > 0)) {
|
||||||
out.left = (a.left + b.left) - (a.left * b.left);
|
out[Sentence.LEFT] = (a[Sentence.LEFT] + b[Sentence.LEFT]) - (a[Sentence.LEFT] * b[Sentence.LEFT]);
|
||||||
} else {
|
} else {
|
||||||
out.left = a.left + b.left;
|
out[Sentence.LEFT] = a[Sentence.LEFT] + b[Sentence.LEFT];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((a.right < 0) && (b.right < 0)) {
|
if ((a[Sentence.RIGHT] < 0) && (b[Sentence.RIGHT] < 0)) {
|
||||||
out.right = (a.right + b.right) - (a.right * b.right);
|
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
||||||
} else if ((a.right > 0) && (b.right > 0)) {
|
} else if ((a[Sentence.RIGHT] > 0) && (b[Sentence.RIGHT] > 0)) {
|
||||||
out.right = (a.right + b.right) - (a.right * b.right);
|
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
||||||
} else {
|
} else {
|
||||||
out.right = a.right + b.right;
|
out[Sentence.RIGHT] = a[Sentence.RIGHT] + b[Sentence.RIGHT];
|
||||||
}
|
}
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
|
|||||||
@@ -24,21 +24,21 @@ public class DelayLineStore {
|
|||||||
effects = new ArrayList<Effect>();
|
effects = new ArrayList<Effect>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
for (Effect e : effects) {
|
for (Effect e : effects) {
|
||||||
e.process(samples);
|
e.process(samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Sample sample : samples) {
|
for (double[] sample : samples) {
|
||||||
sample.left *= gain;
|
sample[Sentence.LEFT] *= gain;
|
||||||
sample.right *= gain;
|
sample[Sentence.RIGHT] *= gain;
|
||||||
|
|
||||||
if (pan < 0) {
|
if (pan < 0) {
|
||||||
double p = 1 + pan;
|
double p = 1 + pan;
|
||||||
sample.right *= p;
|
sample[Sentence.RIGHT] *= p;
|
||||||
} else {
|
} else {
|
||||||
double p = 1 - pan;
|
double p = 1 - pan;
|
||||||
sample.left *= p;
|
sample[Sentence.LEFT] *= p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package uk.co.majenko.audiobookrecorder;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public interface Effect {
|
public interface Effect {
|
||||||
public void process(Sample[] samples);
|
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,7 +16,7 @@ public class EffectGroup implements Effect {
|
|||||||
effects = new ArrayList<Effect>();
|
effects = new ArrayList<Effect>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
for (Effect e : effects) {
|
for (Effect e : effects) {
|
||||||
e.process(samples);
|
e.process(samples);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ public class LFO implements Effect {
|
|||||||
phase = p;
|
phase = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
for (Sample sample : 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)) {
|
||||||
@@ -38,8 +38,8 @@ public class LFO implements Effect {
|
|||||||
v *= depth;
|
v *= depth;
|
||||||
|
|
||||||
// Apply it to the sample
|
// Apply it to the sample
|
||||||
sample.left += (sample.left * v);
|
sample[Sentence.LEFT] += (sample[Sentence.LEFT] * v);
|
||||||
sample.right += (sample.right * v);
|
sample[Sentence.RIGHT] += (sample[Sentence.RIGHT] * v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -775,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ public class Pan implements Effect {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(Sample[] samples) {
|
public void process(double[][] samples) {
|
||||||
for (Sample sample : samples) {
|
for (double[] sample : samples) {
|
||||||
if (pan < 0) {
|
if (pan < 0) {
|
||||||
double p = 1 + pan;
|
double p = 1 + pan;
|
||||||
sample.right *= p;
|
sample[Sentence.RIGHT] *= p;
|
||||||
} else {
|
} else {
|
||||||
double p = 1 - pan;
|
double p = 1 - pan;
|
||||||
sample.left *= p;
|
sample[Sentence.LEFT] *= p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
|
||||||
|
|
||||||
public class Sample {
|
|
||||||
public double left;
|
|
||||||
public 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -58,14 +58,18 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
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;
|
||||||
|
|
||||||
Sample[] audioData = null;
|
double[][] audioData = null;
|
||||||
Sample[] processedAudio = null;
|
|
||||||
|
// double[][] processedAudio = null;
|
||||||
|
|
||||||
RecordingThread recordingThread;
|
RecordingThread recordingThread;
|
||||||
|
|
||||||
boolean effectEthereal = false;
|
boolean effectEthereal = false;
|
||||||
@@ -134,7 +138,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Sentence() {
|
public Sentence() {
|
||||||
super("");
|
super("");
|
||||||
id = UUID.randomUUID().toString();
|
id = UUID.randomUUID().toString();
|
||||||
@@ -173,19 +176,21 @@ 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.sphinx")) {
|
if (Options.getBoolean("process.sphinx")) {
|
||||||
recognise();
|
recognise();
|
||||||
@@ -195,40 +200,19 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public static final int FFTBuckets = 1024;
|
public static final int FFTBuckets = 1024;
|
||||||
|
|
||||||
public double[][] getFFTProfile() {
|
public void autoTrimSampleFFT() {
|
||||||
double[] real = new double[FFTBuckets];
|
autoTrimSampleFFT(false);
|
||||||
double[] imag = new double[FFTBuckets];
|
|
||||||
|
|
||||||
Sample[] 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].getMono();
|
|
||||||
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(boolean useRaw) {
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
Sample[] 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;
|
||||||
@@ -242,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].getMono();
|
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;
|
||||||
@@ -309,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;
|
||||||
Sample[] 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;
|
||||||
@@ -319,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].getMono()) > 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;
|
||||||
@@ -334,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].getMono()) > 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;
|
||||||
@@ -565,7 +558,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
audioData = null;
|
audioData = null;
|
||||||
processedAudio = null;
|
// processedAudio = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean lockedInCache() {
|
public boolean lockedInCache() {
|
||||||
@@ -573,7 +566,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int findNearestZeroCrossing(int pos, int range) {
|
public int findNearestZeroCrossing(int pos, int range) {
|
||||||
Sample[] 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;
|
||||||
|
|
||||||
@@ -583,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].getMono();
|
double backwardsPrev = (data[backwards][LEFT] + data[backwards][RIGHT]) / 2d;
|
||||||
double forwardsPrev = data[forwards].getMono();
|
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].getMono() < 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].getMono() >= 0) {
|
if (forwardsPrev < 0 && ((data[forwards][LEFT] + data[forwards][RIGHT]) / 2d) >= 0) {
|
||||||
return forwards;
|
return forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,8 +597,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
backwardsPrev = data[backwards].getMono();
|
backwardsPrev = (data[backwards][LEFT] + data[backwards][RIGHT]) / 2d;
|
||||||
forwardsPrev = data[forwards].getMono();
|
forwardsPrev = (data[forwards][LEFT] + data[forwards][RIGHT]) / 2d;
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
@@ -649,15 +642,15 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
public double getPeakValue() {
|
public double getPeakValue() {
|
||||||
double oldGain = gain;
|
double oldGain = gain;
|
||||||
gain = 1.0d;
|
gain = 1.0d;
|
||||||
Sample[] 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].getMono()) > ms) {
|
if (Math.abs((samples[i][LEFT] + samples[i][RIGHT]) / 2d) > ms) {
|
||||||
ms = Math.abs(samples[i].getMono());
|
ms = Math.abs((samples[i][LEFT] + samples[i][RIGHT]) / 2d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ms;
|
return ms;
|
||||||
@@ -860,14 +853,14 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
AudiobookRecorder.window.updateWaveform();
|
AudiobookRecorder.window.updateWaveform();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sample[] 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];
|
||||||
Sample[] samples = new Sample[(int)len];
|
double[][] samples = new double[(int)len][2];
|
||||||
|
|
||||||
for (long fno = 0; fno < len; fno++) {
|
for (long fno = 0; fno < len; fno++) {
|
||||||
|
|
||||||
@@ -881,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;
|
||||||
samples[(int)fno] = new Sample((double)left / 32768d, (double)right / 32768d);
|
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];
|
||||||
int mono = (h << 8) | l;
|
int mono = (h << 8) | l;
|
||||||
if ((mono & 0x8000) == 0x8000) mono |= 0xFFFF0000;
|
if ((mono & 0x8000) == 0x8000) mono |= 0xFFFF0000;
|
||||||
samples[(int)fno] = new Sample((double)mono / 32768d);
|
samples[(int)fno][LEFT] = (double)mono / 32768d;
|
||||||
|
samples[(int)fno][RIGHT] = (double)mono / 32768d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return samples;
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sample[] 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];
|
||||||
Sample[] samples = new Sample[(int)len];
|
double[][] samples = new double[(int)len][2];
|
||||||
|
|
||||||
for (long fno = 0; fno < len; fno++) {
|
for (long fno = 0; fno < len; fno++) {
|
||||||
|
|
||||||
@@ -918,14 +913,16 @@ 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;
|
||||||
samples[(int)fno] = new Sample((double)left / 8388608d, (double)right / 8388608d);
|
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];
|
||||||
int mono = (h << 16) | (m << 8) | l;
|
int mono = (h << 16) | (m << 8) | l;
|
||||||
if ((mono & 0x800000) == 0x800000) mono |= 0xFF000000;
|
if ((mono & 0x800000) == 0x800000) mono |= 0xFF000000;
|
||||||
samples[(int)fno] = new Sample((double)mono / 8388608d);
|
samples[(int)fno][LEFT] = (double)mono / 8388608d;
|
||||||
|
samples[(int)fno][RIGHT] = (double)mono / 8388608d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -940,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();
|
||||||
|
|
||||||
Sample[] samples = null;
|
double[][] samples = null;
|
||||||
|
|
||||||
switch (format.getSampleSizeInBits()) {
|
switch (format.getSampleSizeInBits()) {
|
||||||
case 16:
|
case 16:
|
||||||
@@ -959,14 +956,20 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sample[] getProcessedAudioData() {
|
synchronized public double[][] getRawAudioData() {
|
||||||
loadFile();
|
loadFile();
|
||||||
if (processedAudio != null) return processedAudio;
|
return audioData;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized public double[][] getProcessedAudioData() {
|
||||||
|
loadFile();
|
||||||
|
// if (processedAudio != null) return processedAudio;
|
||||||
|
|
||||||
if (audioData == null) return null;
|
if (audioData == null) return null;
|
||||||
processedAudio = new Sample[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++) {
|
||||||
processedAudio[i] = new Sample(audioData[i].left, audioData[i].right);
|
processedAudio[i][LEFT] = audioData[i][LEFT];
|
||||||
|
processedAudio[i][RIGHT] = audioData[i][RIGHT];
|
||||||
}
|
}
|
||||||
// Add processing in here.
|
// Add processing in here.
|
||||||
|
|
||||||
@@ -992,43 +995,44 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
// Add final master gain stage
|
// Add final master gain stage
|
||||||
for (int i = 0; i < processedAudio.length; i++) {
|
for (int i = 0; i < processedAudio.length; i++) {
|
||||||
processedAudio[i].left = processedAudio[i].left * gain;
|
processedAudio[i][LEFT] *= gain;
|
||||||
processedAudio[i].right = processedAudio[i].right * gain;
|
processedAudio[i][RIGHT] *= gain;
|
||||||
}
|
}
|
||||||
return processedAudio;
|
return processedAudio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sample[] getDoubleAudioData() {
|
public double[][] getDoubleAudioData() {
|
||||||
return getProcessedAudioData();
|
return getProcessedAudioData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sample[] getCroppedAudioData() {
|
public double[][] getCroppedAudioData() {
|
||||||
Sample[] 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;
|
||||||
|
|
||||||
Sample[] samples = new Sample[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() {
|
||||||
Sample[] 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 * 4];
|
byte[] pcmData = new byte[length * 4];
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
double sd = croppedData[i].left * 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 * 4] = (byte)(si & 0xFF);
|
pcmData[i * 4] = (byte)(si & 0xFF);
|
||||||
pcmData[(i * 4) + 1] = (byte)((si & 0xFF00) >> 8);
|
pcmData[(i * 4) + 1] = (byte)((si & 0xFF00) >> 8);
|
||||||
sd = croppedData[i].right * 32768d;
|
sd = croppedData[i][RIGHT] * 32768d;
|
||||||
si = (int)sd;
|
si = (int)sd;
|
||||||
if (si > 32767) si = 32767;
|
if (si > 32767) si = 32767;
|
||||||
if (si < -32768) si = -32768;
|
if (si < -32768) si = -32768;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import javax.sound.sampled.*;
|
|||||||
|
|
||||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
||||||
|
|
||||||
Sample[] 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].getMono();
|
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(Sample[] s) {
|
public void setData(double[][] s) {
|
||||||
samples = s;
|
samples = s;
|
||||||
playMarker = 0;
|
playMarker = 0;
|
||||||
repaint();
|
repaint();
|
||||||
|
|||||||
Reference in New Issue
Block a user