/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Infinite impulse response (IIR) filter class.
*
* The filters where implemented and adapted using algorithms from musicdsp.org
* archive: 1-RC and C filter, Simple 2-pole LP LP and HP filter, biquad,
* tweaked butterworth RBJ Audio-EQ-Cookbook, EQ filter kookbook
*
* @author Karl Helgason
*/
public final class SoftFilter {
//
//
// 0x00 = LP, Low Pass Filter
// 0x10 = HP, High Pass Filter
// 0x20 = BP, Band Pass Filter
// 0x30 = NP, Notch or Band Elimination Filter
//
private final float samplerate;
private float x1;
private float x2;
private float y1;
private float y2;
private float xx1;
private float xx2;
private float yy1;
private float yy2;
private float a0;
private float a1;
private float a2;
private float b1;
private float b2;
private float q;
private float last_a0;
private float last_a1;
private float last_a2;
private float last_b1;
private float last_b2;
private float last_q;
private float last_gain;
private boolean last_set = false;
private boolean dirty = true;
this.samplerate = samplerate;
dirty = true;
}
return;
dirty = true;
}
if (resonancedB == db)
return;
resonancedB = db;
dirty = true;
}
public void reset() {
dirty = true;
last_set = false;
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
xx1 = 0;
xx2 = 0;
yy1 = 0;
yy2 = 0;
wet = 0.0f;
gain = 1.0f;
a0 = 0;
a1 = 0;
a2 = 0;
b1 = 0;
b2 = 0;
}
this.filtertype = filtertype;
}
if (filtertype == FILTERTYPE_LP6)
if (filtertype == FILTERTYPE_LP12)
if (filtertype == FILTERTYPE_HP12)
if (filtertype == FILTERTYPE_BP12)
if (filtertype == FILTERTYPE_NP12)
if (filtertype == FILTERTYPE_LP24)
if (filtertype == FILTERTYPE_HP24)
}
if (dirty) {
filter2calc();
dirty = false;
}
if (!last_set) {
last_set = true;
}
if (wet_delta != 0) {
for (int i = 0; i < len; i++) {
gain += gain_delta;
float x = buffer[i];
x1 = x;
y1 = y;
}
for (int i = 0; i < len; i++) {
float x = buffer[i];
x1 = x;
y1 = y;
}
} else {
for (int i = 0; i < len; i++) {
gain += gain_delta;
float x = buffer[i];
x1 = x;
y1 = y;
}
}
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
}
}
private double sinh(double x) {
}
public void filter2calc() {
double resonancedB = this.resonancedB;
if (resonancedB < 0)
if (resonancedB > 30)
resonancedB *= 0.6;
if (filtertype == FILTERTYPE_BP12) {
wet = 1;
double r = (cutoff / samplerate);
if (r > 0.45)
r = 0.45;
double b1 = 0;
}
if (filtertype == FILTERTYPE_NP12) {
wet = 1;
double r = (cutoff / samplerate);
if (r > 0.45)
r = 0.45;
double b0 = 1;
double b2 = 1;
}
double r = (cutoff / samplerate);
if (r > 0.45) {
if (wet == 0) {
if (resonancedB < 0.00001)
wet = 0.0f;
else
wet = 1.0f;
}
r = 0.45;
} else
wet = 1.0f;
double csq = c * c;
}
double r = (cutoff / samplerate);
if (r > 0.45)
r = 0.45;
if (r < 0.0001)
r = 0.0001;
wet = 1.0f;
double csq = c * c;
}
}
if (dirty) {
filter2calc();
dirty = false;
}
if (!last_set) {
last_q = q;
last_set = true;
}
if (wet_delta != 0) {
for (int i = 0; i < len; i++) {
gain += gain_delta;
float x = buffer[i];
x1 = x;
y1 = y;
}
for (int i = 0; i < len; i++) {
float x = buffer[i];
x1 = x;
y1 = y;
}
} else {
for (int i = 0; i < len; i++) {
gain += gain_delta;
float x = buffer[i];
x1 = x;
y1 = y;
}
}
x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;
}
this.last_q = this.q;
}
public void filter1calc() {
if (cutoff < 120)
cutoff = 120;
if (c > 1)
c = 1;
if (resonancedB < 0)
resonancedB = 0;
if (resonancedB > 20)
resonancedB = 20;
if (wet == 0.0f)
wet = 1.0f;
}
if (dirty) {
filter1calc();
dirty = false;
}
if (!last_set) {
last_q = q;
last_set = true;
}
float q = this.last_q;
if (wet_delta != 0) {
for (int i = 0; i < len; i++) {
q += q_delta;
gain += gain_delta;
}
for (int i = 0; i < len; i++) {
}
} else {
for (int i = 0; i < len; i++) {
q += q_delta;
gain += gain_delta;
}
}
y2 = 0;
y1 = 0;
}
this.last_q = this.q;
}
}