Invert sample storage arrays
This commit is contained in:
@@ -27,9 +27,9 @@ public class AGC implements Effect {
|
||||
|
||||
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;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
double absSampleLeft = Math.abs(samples[Sentence.LEFT][i]) * gain;
|
||||
double absSampleRight = Math.abs(samples[Sentence.RIGHT][i]) * gain;
|
||||
|
||||
double factor = 0.0d;
|
||||
|
||||
@@ -49,8 +49,8 @@ public class AGC implements Effect {
|
||||
if (gain > limit) gain = limit;
|
||||
if (gain < 0) gain = 0;
|
||||
|
||||
samples[i][Sentence.LEFT] *= gain;
|
||||
samples[i][Sentence.RIGHT] *= gain;
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ public class Amplifier implements Effect {
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
samples[i][Sentence.LEFT] *= gain;
|
||||
samples[i][Sentence.RIGHT] *= gain;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -94,19 +94,19 @@ public class Biquad implements Effect {
|
||||
lz2 = 0d;
|
||||
rz1 = 0d;
|
||||
rz2 = 0d;
|
||||
for (double[] in : samples) {
|
||||
double lout = in[Sentence.LEFT] * a0 + lz1;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
double lout = samples[Sentence.LEFT][i] * a0 + lz1;
|
||||
|
||||
lz1 = in[Sentence.LEFT] * a1 + lz2 - b1 * lout;
|
||||
lz2 = in[Sentence.LEFT] * a2 - b2 * lout;
|
||||
lz1 = samples[Sentence.LEFT][i] * a1 + lz2 - b1 * lout;
|
||||
lz2 = samples[Sentence.LEFT][i] * a2 - b2 * lout;
|
||||
|
||||
double rout = in[Sentence.RIGHT] * a0 + rz1;
|
||||
double rout = samples[Sentence.RIGHT][i] * a0 + rz1;
|
||||
|
||||
rz1 = in[Sentence.RIGHT] * a1 + rz2 - b1 * rout;
|
||||
rz2 = in[Sentence.RIGHT] * a2 - b2 * rout;
|
||||
rz1 = samples[Sentence.RIGHT][i] * a1 + rz2 - b1 * rout;
|
||||
rz2 = samples[Sentence.RIGHT][i] * a2 - b2 * rout;
|
||||
|
||||
in[Sentence.LEFT] = lout;
|
||||
in[Sentence.RIGHT] = rout;
|
||||
samples[Sentence.LEFT][i] = lout;
|
||||
samples[Sentence.RIGHT][i] = rout;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ public class Clipping implements Effect {
|
||||
}
|
||||
|
||||
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;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
if (samples[Sentence.LEFT][i] > clip) samples[Sentence.LEFT][i] = clip;
|
||||
if (samples[Sentence.LEFT][i] < -clip) samples[Sentence.LEFT][i] = -clip;
|
||||
if (samples[Sentence.RIGHT][i] > clip) samples[Sentence.RIGHT][i] = clip;
|
||||
if (samples[Sentence.RIGHT][i] < -clip) samples[Sentence.RIGHT][i] = -clip;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
192
src/uk/co/majenko/audiobookrecorder/CommandLine.java
Normal file
192
src/uk/co/majenko/audiobookrecorder/CommandLine.java
Normal file
@@ -0,0 +1,192 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CommandLine {
|
||||
HashMap<String, Class<?>> parameterTypes = new HashMap<String, Class<?>>();
|
||||
HashMap<String, String> parameterComments = new HashMap<String, String>();
|
||||
HashMap<String, Object> parameterValues = new HashMap<String, Object>();
|
||||
HashMap<String, String> parameterNames = new HashMap<String, String>();
|
||||
ArrayList<String> extraValues = new ArrayList<String>();
|
||||
|
||||
public CommandLine() {
|
||||
}
|
||||
|
||||
public void addParameter(String key, String name, Class<?> type, String comment) {
|
||||
parameterNames.put(key, name);
|
||||
parameterTypes.put(key, type);
|
||||
parameterComments.put(key, comment);
|
||||
}
|
||||
|
||||
public String[] process(String[] args) {
|
||||
parameterValues = new HashMap<String, Object>();
|
||||
extraValues = new ArrayList<String>();
|
||||
|
||||
for (String arg : args) {
|
||||
if (arg.startsWith("--")) {
|
||||
arg = arg.substring(2);
|
||||
String value = "";
|
||||
int equals = arg.indexOf("=");
|
||||
if (equals > -1) {
|
||||
value = arg.substring(equals + 1);
|
||||
arg = arg.substring(0, equals);
|
||||
}
|
||||
|
||||
Class<?> aclass = parameterTypes.get(arg);
|
||||
if (aclass == null) {
|
||||
help();
|
||||
System.exit(0);
|
||||
}
|
||||
if (aclass == Boolean.class) {
|
||||
Boolean b = true;
|
||||
parameterValues.put(arg, b);
|
||||
continue;
|
||||
}
|
||||
if (value.equals("")) {
|
||||
help();
|
||||
System.exit(0);
|
||||
}
|
||||
if (aclass == Integer.class) {
|
||||
Integer i = 0;
|
||||
try {
|
||||
i = Integer.parseInt(value);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
parameterValues.put(arg, i);
|
||||
continue;
|
||||
}
|
||||
if (aclass == Float.class) {
|
||||
Float f = 0F;
|
||||
try {
|
||||
f = Float.parseFloat(value);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
parameterValues.put(arg, f);
|
||||
continue;
|
||||
}
|
||||
if (aclass == Double.class) {
|
||||
Double d = 0D;
|
||||
try {
|
||||
d = Double.parseDouble(value);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
parameterValues.put(arg, d);
|
||||
continue;
|
||||
}
|
||||
if (aclass == String.class) {
|
||||
parameterValues.put(arg, value);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
extraValues.add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
return extraValues.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public void help() {
|
||||
System.out.println("Available command line arguments:");
|
||||
int maxlen = 0;
|
||||
|
||||
String[] arglist = parameterTypes.keySet().toArray(new String[0]);
|
||||
Arrays.sort(arglist);
|
||||
|
||||
for (String s : arglist) {
|
||||
int thislen = s.length();
|
||||
if (parameterTypes.get(s) != Boolean.class) {
|
||||
thislen++;
|
||||
thislen += parameterNames.get(s).length();
|
||||
}
|
||||
if (thislen > maxlen) {
|
||||
maxlen = thislen;
|
||||
}
|
||||
}
|
||||
for (String s : arglist) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
System.out.print(" --");
|
||||
sb.append(s);
|
||||
if (parameterTypes.get(s) != Boolean.class) {
|
||||
sb.append("=");
|
||||
sb.append(parameterNames.get(s));
|
||||
}
|
||||
while (sb.length() < maxlen) {
|
||||
sb.append(" ");
|
||||
}
|
||||
System.out.print(sb.toString());
|
||||
System.out.print(" ");
|
||||
System.out.println(parameterComments.get(s));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSet(String key) {
|
||||
Object value = parameterValues.get(key);
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getString(String key) {
|
||||
Class<?> type = parameterTypes.get(key);
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
if (type != String.class) {
|
||||
return null;
|
||||
}
|
||||
String value = (String)parameterValues.get(key);
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getInteger(String key) {
|
||||
Class<?> type = parameterTypes.get(key);
|
||||
if (type == null) {
|
||||
return 0;
|
||||
}
|
||||
if (type != Integer.class) {
|
||||
return 0;
|
||||
}
|
||||
Integer value = (Integer)parameterValues.get(key);
|
||||
if (value == null) {
|
||||
return 0;
|
||||
}
|
||||
return (int)value;
|
||||
}
|
||||
|
||||
public float getFloat(String key) {
|
||||
Class<?> type = parameterTypes.get(key);
|
||||
if (type == null) {
|
||||
return 0f;
|
||||
}
|
||||
if (type != Float.class) {
|
||||
return 0f;
|
||||
}
|
||||
Float value = (Float)parameterValues.get(key);
|
||||
if (value == null) {
|
||||
return 0f;
|
||||
}
|
||||
return (float)value;
|
||||
}
|
||||
|
||||
public double getDouble(String key) {
|
||||
Class<?> type = parameterTypes.get(key);
|
||||
if (type == null) {
|
||||
return 0d;
|
||||
}
|
||||
if (type != Double.class) {
|
||||
return 0d;
|
||||
}
|
||||
Double value = (Double)parameterValues.get(key);
|
||||
if (value == null) {
|
||||
return 0d;
|
||||
}
|
||||
return (double)value;
|
||||
}
|
||||
|
||||
public void set(String key, String value) {
|
||||
parameterValues.put(key, value);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,53 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class Debug {
|
||||
static long timestamp;
|
||||
static public boolean debugEnabled = false;
|
||||
static public boolean traceEnabled = false;
|
||||
|
||||
static void debug(String msg) {
|
||||
if (!debugEnabled) return;
|
||||
long now = System.currentTimeMillis();
|
||||
long diff = now - timestamp;
|
||||
timestamp = now;
|
||||
System.err.println(String.format("%8d - %s", diff, msg));
|
||||
}
|
||||
|
||||
static void d(Object... args) {
|
||||
if (!debugEnabled) return;
|
||||
|
||||
Thread t = Thread.currentThread();
|
||||
StackTraceElement[] st = t.getStackTrace();
|
||||
StackTraceElement caller = st[2];
|
||||
|
||||
String tag = "[" + getCurrentLocalDateTimeStamp() + "] " + caller.getFileName() + " " + caller.getLineNumber() + " (" + caller.getMethodName() + "):";
|
||||
|
||||
System.err.print(tag);
|
||||
|
||||
for (Object o : args) {
|
||||
System.err.print(" ");
|
||||
System.err.print(o);
|
||||
}
|
||||
System.err.println();
|
||||
}
|
||||
|
||||
static void trace() {
|
||||
if (!traceEnabled) return;
|
||||
Thread t = Thread.currentThread();
|
||||
StackTraceElement[] st = t.getStackTrace();
|
||||
StackTraceElement caller = st[3];
|
||||
StackTraceElement callee = st[2];
|
||||
|
||||
String tag = "[" + getCurrentLocalDateTimeStamp() + "] " + t.getName() + " - " + caller.getFileName() + ":" + caller.getLineNumber() + " " + caller.getMethodName() + "(...) -> " + callee.getFileName() + ":" + callee.getLineNumber() + " " + callee.getMethodName() + "(...)";
|
||||
|
||||
System.err.println(tag);
|
||||
}
|
||||
|
||||
public static String getCurrentLocalDateTimeStamp() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,60 +17,50 @@ public class DelayLine implements Effect {
|
||||
}
|
||||
|
||||
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];
|
||||
double[][] savedSamples = new double[2][samples[Sentence.LEFT].length];
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
savedSamples[Sentence.LEFT][i] = samples[Sentence.LEFT][i];
|
||||
savedSamples[Sentence.RIGHT][i] = samples[Sentence.RIGHT][i];
|
||||
}
|
||||
if (wetOnly) {
|
||||
for (int i = 0; i < samples.length; i++) {
|
||||
samples[i][Sentence.LEFT] = 0d;
|
||||
samples[i][Sentence.RIGHT] = 0d;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] = 0d;
|
||||
samples[Sentence.RIGHT][i] = 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];
|
||||
double[][] subSamples = new double[2][samples[Sentence.LEFT].length];
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
subSamples[Sentence.LEFT][i] = savedSamples[Sentence.LEFT][i];
|
||||
subSamples[Sentence.RIGHT][i] = savedSamples[Sentence.RIGHT][i];
|
||||
}
|
||||
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];
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
subSamples[Sentence.LEFT][i] = savedSamples[Sentence.LEFT][i];
|
||||
subSamples[Sentence.RIGHT][i] = savedSamples[Sentence.RIGHT][i];
|
||||
}
|
||||
|
||||
d.process(subSamples);
|
||||
|
||||
for (int i = 0; i < subSamples.length; i++) {
|
||||
for (int i = 0; i < subSamples[Sentence.LEFT].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];
|
||||
if ((off < samples[Sentence.LEFT].length) && (off > 0)) {
|
||||
samples[Sentence.LEFT][off] = mix(samples[Sentence.LEFT][off], subSamples[Sentence.LEFT][i]);
|
||||
samples[Sentence.RIGHT][off] = mix(samples[Sentence.RIGHT][off], subSamples[Sentence.RIGHT][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double[] mix(double[] a, double[] b) {
|
||||
double[] out = new double[2];
|
||||
double mix(double a, double b) {
|
||||
double out;
|
||||
|
||||
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]);
|
||||
if ((a < 0) && (b < 0)) {
|
||||
out = (a + b) - (a * b);
|
||||
} else if ((a > 0) && (b > 0)) {
|
||||
out = (a + b) - (a * b);
|
||||
} else {
|
||||
out[Sentence.LEFT] = a[Sentence.LEFT] + b[Sentence.LEFT];
|
||||
}
|
||||
|
||||
if ((a[Sentence.RIGHT] < 0) && (b[Sentence.RIGHT] < 0)) {
|
||||
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
||||
} else if ((a[Sentence.RIGHT] > 0) && (b[Sentence.RIGHT] > 0)) {
|
||||
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
||||
} else {
|
||||
out[Sentence.RIGHT] = a[Sentence.RIGHT] + b[Sentence.RIGHT];
|
||||
out = a + b;
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
@@ -29,16 +29,16 @@ public class DelayLineStore {
|
||||
e.process(samples);
|
||||
}
|
||||
|
||||
for (double[] sample : samples) {
|
||||
sample[Sentence.LEFT] *= gain;
|
||||
sample[Sentence.RIGHT] *= gain;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
|
||||
if (pan < 0) {
|
||||
double p = 1 + pan;
|
||||
sample[Sentence.RIGHT] *= p;
|
||||
samples[Sentence.RIGHT][i] *= p;
|
||||
} else {
|
||||
double p = 1 - pan;
|
||||
sample[Sentence.LEFT] *= p;
|
||||
samples[Sentence.LEFT][i] *= p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class LFO implements Effect {
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (double[] sample : samples) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
double v = 0;
|
||||
switch (waveform) {
|
||||
case SINE: v = Math.sin(phase); break;
|
||||
@@ -68,12 +68,12 @@ public class LFO implements Effect {
|
||||
// Apply it to the sample
|
||||
switch (mode) {
|
||||
case REPLACE:
|
||||
sample[Sentence.LEFT] = (sample[Sentence.LEFT] * v);
|
||||
sample[Sentence.RIGHT] = (sample[Sentence.RIGHT] * v);
|
||||
samples[Sentence.LEFT][i] = (samples[Sentence.LEFT][i] * v);
|
||||
samples[Sentence.RIGHT][i] = (samples[Sentence.RIGHT][i] * v);
|
||||
break;
|
||||
case ADD:
|
||||
sample[Sentence.LEFT] += (sample[Sentence.LEFT] * v);
|
||||
sample[Sentence.RIGHT] += (sample[Sentence.RIGHT] * v);
|
||||
samples[Sentence.LEFT][i] += (samples[Sentence.LEFT][i] * v);
|
||||
samples[Sentence.RIGHT][i] += (samples[Sentence.RIGHT][i] * v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,13 +20,13 @@ public class Pan implements Effect {
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (double[] sample : samples) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
if (pan < 0) {
|
||||
double p = 1 + pan;
|
||||
sample[Sentence.RIGHT] *= p;
|
||||
samples[Sentence.RIGHT][i] *= p;
|
||||
} else {
|
||||
double p = 1 - pan;
|
||||
sample[Sentence.LEFT] *= p;
|
||||
samples[Sentence.LEFT][i] *= p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -34,6 +34,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
int offsetFactor = 0;
|
||||
int offset = 0;
|
||||
|
||||
String loadedId = null;
|
||||
|
||||
ArrayList<MarkerDragListener> markerDragListeners;
|
||||
|
||||
public Waveform() {
|
||||
@@ -79,7 +81,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
|
||||
if (samples != null) {
|
||||
|
||||
int num = samples.length;
|
||||
int num = samples[Sentence.LEFT].length;
|
||||
step = num / zoomFactor / w;
|
||||
if (step == 0) return;
|
||||
|
||||
@@ -97,8 +99,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
double lmax = 0;
|
||||
|
||||
for (int o = 0; o < step; o++) {
|
||||
if (offset + (n * step) + o >= samples.length) break;
|
||||
double sample = (samples[offset + (n * step) + o][Sentence.LEFT] + samples[offset + (n * step) + o][Sentence.RIGHT]) / 2d;
|
||||
if (offset + (n * step) + o >= samples[Sentence.LEFT].length) break;
|
||||
double sample = (samples[Sentence.LEFT][offset + (n * step) + o] + samples[Sentence.RIGHT][offset + (n * step) + o]) / 2d;
|
||||
if (sample >= 0) {
|
||||
have += sample;
|
||||
hcnt++;
|
||||
@@ -387,4 +389,12 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
public int getCutEnd() {
|
||||
return cutExit;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
loadedId = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return loadedId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user