2
* 11/19/04 1.0 moved to LGPL.
3
* 12/12/99 Initial version. mdm@techie.com
4
*-----------------------------------------------------------------------
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU Library General Public License as published
7
* by the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
*----------------------------------------------------------------------
21
package javazoom.jl.decoder;
24
* The <code>Equalizer</code> class can be used to specify equalization
25
* settings for the MPEG audio decoder.
27
* The equalizer consists of 32 band-pass filters. Each band of the equalizer
28
* can take on a fractional value between -1.0 and +1.0. At -1.0, the input
29
* signal is attenuated by 6dB, at +1.0 the signal is amplified by 6dB.
35
public final class Equalizer {
37
* Equalizer setting to denote that a given band will not be present in the
40
static public final float BAND_NOT_PRESENT = Float.NEGATIVE_INFINITY;
42
static public final Equalizer PASS_THRU_EQ = new Equalizer();
44
private static final int BANDS = 32;
46
private final float[] settings = new float[BANDS];
49
* Creates a new <code>Equalizer</code> instance.
54
// private Equalizer(float b1, float b2, float b3, float b4, float b5,
55
// float b6, float b7, float b8, float b9, float b10, float b11,
56
// float b12, float b13, float b14, float b15, float b16,
57
// float b17, float b18, float b19, float b20);
59
public Equalizer(float[] settings) {
63
public Equalizer(EQFunction eq) {
67
public void setFrom(float[] eq) {
69
int max = (eq.length > BANDS) ? BANDS : eq.length;
71
for (int i = 0; i < max; i++) {
72
settings[i] = limit(eq[i]);
76
public void setFrom(EQFunction eq) {
80
for (int i = 0; i < max; i++) {
81
settings[i] = limit(eq.getBand(i));
86
* Sets the bands of this equalizer to the value the bands of another
87
* equalizer. Bands that are not present in both equalizers are ignored.
89
public void setFrom(Equalizer eq) {
96
* Sets all bands to 0.0
99
for (int i = 0; i < BANDS; i++) {
105
* Retrieves the number of bands present in this equalizer.
107
public int getBandCount() {
108
return settings.length;
111
public float setBand(int band, float neweq) {
114
if ((band >= 0) && (band < BANDS)) {
116
settings[band] = limit(neweq);
123
* Retrieves the eq setting for a given band.
125
public float getBand(int band) {
128
if ((band >= 0) && (band < BANDS)) {
135
private float limit(float eq) {
136
if (eq == BAND_NOT_PRESENT)
147
* Retrieves an array of floats whose values represent a scaling factor that
148
* can be applied to linear samples in each band to provide the equalization
149
* represented by this instance.
151
* @return an array of factors that can be applied to the subbands.
153
float[] getBandFactors() {
154
float[] factors = new float[BANDS];
155
for (int i = 0, maxCount = BANDS; i < maxCount; i++) {
156
factors[i] = getBandFactor(settings[i]);
163
* Converts an equalizer band setting to a sample factor. The factor is
164
* determined by the function f = 2^n where n is the equalizer band setting
165
* in the range [-1.0,1.0].
168
float getBandFactor(float eq) {
169
if (eq == BAND_NOT_PRESENT)
172
float f = (float) Math.pow(2.0, eq);
176
static abstract public class EQFunction {
178
* Returns the setting of a band in the equalizer.
181
* The index of the band to retrieve the setting for.
183
* @return the setting of the specified band. This is a value between -1
186
public float getBand(int band) {