2 * 11/19/04 1.0 moved to LGPL.
\r
3 * 12/12/99 Initial version. mdm@techie.com
\r
4 *-----------------------------------------------------------------------
\r
5 * This program is free software; you can redistribute it and/or modify
\r
6 * it under the terms of the GNU Library General Public License as published
\r
7 * by the Free Software Foundation; either version 2 of the License, or
\r
8 * (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU Library General Public License for more details.
\r
15 * You should have received a copy of the GNU Library General Public
\r
16 * License along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
\r
18 *----------------------------------------------------------------------
\r
24 * The <code>Equalizer</code> class can be used to specify
\r
25 * equalization settings for the MPEG audio decoder.
\r
27 * The equalizer consists of 32 band-pass filters.
\r
28 * Each band of the equalizer can take on a fractional value between
\r
30 * At -1.0, the input signal is attenuated by 6dB, at +1.0 the signal is
\r
31 * amplified by 6dB.
\r
38 @METHODDEFAULT("OUT<V,V<SH,SH<C,C<IN,SH*,THISLOC=IN,GLOBALLOC=IN")
\r
39 public final class Equalizer
\r
42 * Equalizer setting to denote that a given band will not be
\r
43 * present in the output signal.
\r
45 @LOC("T") static public final float BAND_NOT_PRESENT = Float.NEGATIVE_INFINITY;
\r
47 @LOC("T") static public final Equalizer PASS_THRU_EQ = new Equalizer();
\r
49 @LOC("T") private static final int BANDS = 32;
\r
51 @LOC("B") private final float[] settings = new float[BANDS];
\r
54 * Creates a new <code>Equalizer</code> instance.
\r
60 // private Equalizer(float b1, float b2, float b3, float b4, float b5,
\r
61 // float b6, float b7, float b8, float b9, float b10, float b11,
\r
62 // float b12, float b13, float b14, float b15, float b16,
\r
63 // float b17, float b18, float b19, float b20);
\r
65 public Equalizer(float[] settings)
\r
70 public Equalizer(EQFunction eq)
\r
75 public void setFrom(float[] eq)
\r
78 int max = (eq.length > BANDS) ? BANDS : eq.length;
\r
80 for (int i=0; i<max; i++)
\r
82 settings[i] = limit(eq[i]);
\r
86 public void setFrom(EQFunction eq)
\r
91 for (int i=0; i<max; i++)
\r
93 settings[i] = limit(eq.getBand(i));
\r
98 * Sets the bands of this equalizer to the value the bands of
\r
99 * another equalizer. Bands that are not present in both equalizers are ignored.
\r
101 public void setFrom(Equalizer eq)
\r
105 setFrom(eq.settings);
\r
113 * Sets all bands to 0.0
\r
115 public void reset()
\r
117 for (int i=0; i<BANDS; i++)
\r
119 settings[i] = 0.0f;
\r
125 * Retrieves the number of bands present in this equalizer.
\r
127 public int getBandCount()
\r
129 return settings.length;
\r
132 public float setBand(int band, float neweq)
\r
136 if ((band>=0) && (band<BANDS))
\r
138 eq = settings[band];
\r
139 settings[band] = limit(neweq);
\r
148 * Retrieves the eq setting for a given band.
\r
150 public float getBand(int band)
\r
154 if ((band>=0) && (band<BANDS))
\r
156 eq = settings[band];
\r
162 private float limit(float eq)
\r
164 if (eq==BAND_NOT_PRESENT)
\r
175 * Retrieves an array of floats whose values represent a
\r
176 * scaling factor that can be applied to linear samples
\r
177 * in each band to provide the equalization represented by
\r
180 * @return an array of factors that can be applied to the
\r
184 float[] getBandFactors()
\r
186 @LOC("OUT") float[] factors = new float[BANDS];
\r
187 @LOC("C") int maxCount = BANDS;
\r
188 for (@LOC("SH") int i=0; i<maxCount; i++)
\r
190 factors[i] = getBandFactor(settings[i]);
\r
197 * Converts an equalizer band setting to a sample factor.
\r
198 * The factor is determined by the function f = 2^n where
\r
199 * n is the equalizer band setting in the range [-1.0,1.0].
\r
203 float getBandFactor(@LOC("IN") float eq)
\r
205 if (eq==BAND_NOT_PRESENT)
\r
208 @LOC("C") float f = (float)Math.pow(2.0, eq);
\r
213 static abstract public class EQFunction
\r
216 * Returns the setting of a band in the equalizer.
\r
218 * @param band The index of the band to retrieve the setting
\r
221 * @return the setting of the specified band. This is a value between
\r
224 public float getBand(int band)
\r