001: /*
002: * Copyright (c) 2000 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: */
032:
033: // This code is repackaged after the code from Craig A. Lindley, from Digital Audio with Java
034: // Site ftp://ftp.prenhall.com/pub/ptr/professional_computer_science.w-022/digital_audio/
035: // Email
036: package com.db.media.audio.dsp.filter;
037:
038: // Base class for all IIR filters.
039:
040: public abstract class IIRFilterBase {
041:
042: protected static final int HISTORYSIZE = 3;
043:
044: // Private class data
045: protected double alpha;
046: protected double beta;
047: protected double gamma;
048: protected double amplitudeAdj;
049: protected double[] inArray;
050: protected double[] outArray;
051: protected int iIndex;
052: protected int jIndex;
053: protected int kIndex;
054:
055: // IIRFilterBase class constructor
056: // alpha, beta and gamma are precalculated filter coefficients
057: // that are passed into this filter element.
058: public IIRFilterBase(double alpha, double beta, double gamma) {
059:
060: // Save incoming
061: this .alpha = alpha;
062: this .beta = beta;
063: this .gamma = gamma;
064:
065: amplitudeAdj = 1.0;
066:
067: // Allocate history buffers
068: inArray = new double[HISTORYSIZE];
069: outArray = new double[HISTORYSIZE];
070:
071: }
072:
073: // Filter coefficients can also be extracted by passing in
074: // design object.
075: public IIRFilterBase(IIRFilterDesignBase fdb) {
076:
077: this (fdb.getAlpha(), fdb.getBeta(), fdb.getGamma());
078:
079: }
080:
081: public void updateFilterCoefficients(IIRFilterDesignBase fdb) {
082:
083: this .alpha = fdb.getAlpha();
084: this .beta = fdb.getBeta();
085: this .gamma = fdb.getGamma();
086:
087: }
088:
089: public void setAlpha(double alpha) {
090:
091: this .alpha = alpha;
092:
093: }
094:
095: public void setBeta(double beta) {
096:
097: this .beta = beta;
098:
099: }
100:
101: public void setGamma(double gamma) {
102:
103: this .gamma = gamma;
104:
105: }
106:
107: // Abstract method that runs the filter algorithm
108: public abstract void doFilter(short[] inBuffer, double[] outBuffer,
109: int length);
110:
111: // Set the amplitude adjustment to be applied to filtered data
112: // Values typically range from -.25 to +4.0 or -12 to +12 db.
113: public void setAmplitudeAdj(double amplitudeAdj) {
114:
115: this.amplitudeAdj = amplitudeAdj;
116:
117: }
118:
119: }
|