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: // Optimized IIR lowpass filter used as shelving EQ
039:
040: public class IIRLowpassFilter extends IIRFilterBase {
041:
042: // IIRLowpassFilter class constructor
043: // alpha, beta and gamma are precalculated filter coefficients
044: // that are passed into this filter element.
045: public IIRLowpassFilter(double alpha, double beta, double gamma) {
046:
047: super (alpha, beta, gamma);
048:
049: }
050:
051: // Filter coefficients can also be extracted by passing in
052: // design object.
053: public IIRLowpassFilter(IIRLowpassFilterDesign fd) {
054:
055: super (fd);
056:
057: }
058:
059: // Run the filter algorithm
060: public void doFilter(short[] inBuffer, double[] outBuffer,
061: int length) {
062:
063: for (int index = 0; index < length; index++) {
064: // Fetch sample
065: inArray[iIndex] = (double) inBuffer[index];
066:
067: // Do indices maintainance
068: jIndex = iIndex - 2;
069: if (jIndex < 0)
070: jIndex += HISTORYSIZE;
071: kIndex = iIndex - 1;
072: if (kIndex < 0)
073: kIndex += HISTORYSIZE;
074:
075: // Run the lowpass difference equation
076: double out = outArray[iIndex] = 2.0 * (alpha
077: * (inArray[iIndex] + (2 * inArray[kIndex]) + inArray[jIndex])
078: + gamma * outArray[kIndex] - beta
079: * outArray[jIndex]);
080:
081: outBuffer[index] += amplitudeAdj * out;
082:
083: iIndex = (iIndex + 1) % HISTORYSIZE;
084: }
085:
086: }
087:
088: public void doFilterNoSum(short[] inBuffer, double[] outBuffer,
089: int length) {
090:
091: for (int index = 0; index < length; index++) {
092: // Fetch sample
093: inArray[iIndex] = (double) inBuffer[index];
094:
095: // Do indices maintainance
096: jIndex = iIndex - 2;
097: if (jIndex < 0)
098: jIndex += HISTORYSIZE;
099: kIndex = iIndex - 1;
100: if (kIndex < 0)
101: kIndex += HISTORYSIZE;
102:
103: // Run the lowpass difference equation
104: double out = outArray[iIndex] = 2.0 * (alpha
105: * (inArray[iIndex] + (2 * inArray[kIndex]) + inArray[jIndex])
106: + gamma * outArray[kIndex] - beta
107: * outArray[jIndex]);
108:
109: outBuffer[index] = out;
110:
111: iIndex = (iIndex + 1) % HISTORYSIZE;
112: }
113:
114: }
115:
116: public void doFilterNoSum(double[] inBuffer, double[] outBuffer,
117: int length) {
118:
119: for (int index = 0; index < length; index++) {
120: // Fetch sample
121: inArray[iIndex] = inBuffer[index];
122:
123: // Do indices maintainance
124: jIndex = iIndex - 2;
125: if (jIndex < 0)
126: jIndex += HISTORYSIZE;
127: kIndex = iIndex - 1;
128: if (kIndex < 0)
129: kIndex += HISTORYSIZE;
130:
131: // Run the lowpass difference equation
132: double out = outArray[iIndex] = 2.0 * (alpha
133: * (inArray[iIndex] + (2 * inArray[kIndex]) + inArray[jIndex])
134: + gamma * outArray[kIndex] - beta
135: * outArray[jIndex]);
136:
137: outBuffer[index] = out;
138:
139: iIndex = (iIndex + 1) % HISTORYSIZE;
140: }
141:
142: }
143:
144: }
|