Added AGC filter
This commit is contained in:
57
src/uk/co/majenko/audiobookrecorder/AGC.java
Normal file
57
src/uk/co/majenko/audiobookrecorder/AGC.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AGC implements Effect {
|
||||
double limit;
|
||||
double gain;
|
||||
double ceiling;
|
||||
double decay;
|
||||
double attack;
|
||||
|
||||
public AGC(double c, double a, double d, double l) {
|
||||
ceiling = c;
|
||||
attack = a;
|
||||
decay = d;
|
||||
limit = l;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public double process(double sample) {
|
||||
double absSample = Math.abs(sample) * gain;
|
||||
|
||||
if (absSample > ceiling) {
|
||||
gain -= attack;
|
||||
if (gain < 0) gain = 0;
|
||||
}
|
||||
|
||||
if (absSample < ceiling) {
|
||||
gain += decay;
|
||||
if (gain > limit) {
|
||||
gain = limit;
|
||||
}
|
||||
}
|
||||
|
||||
sample *= gain;
|
||||
|
||||
return sample;
|
||||
}
|
||||
|
||||
public void init(double sr) {
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2587,6 +2587,11 @@ System.err.println(format);
|
||||
if (eff != null) {
|
||||
group.addEffect(eff);
|
||||
}
|
||||
} else if (e.getTagName().equals("agc")) {
|
||||
Effect eff = (Effect)loadAGC(e);
|
||||
if (eff != null) {
|
||||
group.addEffect(eff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2667,6 +2672,11 @@ System.err.println(format);
|
||||
if (eff != null) {
|
||||
store.addEffect(eff);
|
||||
}
|
||||
} else if (ie.getTagName().equals("agc")) {
|
||||
Effect eff = (Effect)loadAGC(ie);
|
||||
if (eff != null) {
|
||||
store.addEffect(eff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2689,6 +2699,21 @@ System.err.println(format);
|
||||
return new LFO(f, d, p);
|
||||
}
|
||||
|
||||
public AGC loadAGC(Element root) {
|
||||
double ceiling = Utils.s2d(root.getAttribute("ceiling"));
|
||||
double limit = Utils.s2d(root.getAttribute("limit"));
|
||||
double attack = Utils.s2d(root.getAttribute("attack"));
|
||||
double decay = Utils.s2d(root.getAttribute("decay"));
|
||||
if (ceiling < 0.0001d) {
|
||||
ceiling = 0.708d; // -3dB
|
||||
}
|
||||
if (limit < 0.0001d) {
|
||||
limit = 1d; // No gain
|
||||
}
|
||||
AGC agc = new AGC(ceiling, attack, decay, limit);
|
||||
return agc;
|
||||
}
|
||||
|
||||
public void updateEffectChains() {
|
||||
int sel = effectChain.getSelectedIndex();
|
||||
KVPair<String, String> ent = effectChain.getItemAt(sel);
|
||||
|
||||
@@ -62,9 +62,12 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
g.drawLine(x, 0, x, h);
|
||||
}
|
||||
|
||||
int h2 = h/2;
|
||||
int db3 = (int) (h2 * 0.708);
|
||||
|
||||
for (int x = 0; x < w; x += 4) {
|
||||
g.drawLine(x, h/4, x, h/4);
|
||||
g.drawLine(x, h/4*3, x, h/4*3);
|
||||
g.drawLine(x, h2 + db3, x, h2 + db3);
|
||||
g.drawLine(x, h2 - db3, x, h2 - db3);
|
||||
}
|
||||
|
||||
double scale = (h/2);
|
||||
|
||||
Reference in New Issue
Block a user