-/*\r
- * 11/19/04 1.0 moved to LGPL.\r
- * 12/12/99 Initial version. mdm@techie.com\r
- *-----------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU Library General Public License as published\r
- * by the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- *----------------------------------------------------------------------\r
- */\r
-\r
-/**\r
- * The <code>Equalizer</code> class can be used to specify equalization settings\r
- * for the MPEG audio decoder.\r
- * <p>\r
- * The equalizer consists of 32 band-pass filters. Each band of the equalizer\r
- * can take on a fractional value between -1.0 and +1.0. At -1.0, the input\r
- * signal is attenuated by 6dB, at +1.0 the signal is amplified by 6dB.\r
- * \r
- * @see Decoder\r
- * \r
- * @author MDM\r
- */\r
-@LATTICE("B<IDX,IDX<T,IDX*")\r
-@METHODDEFAULT("OUT<V,V<SH,SH<C,C<IN,IN<P,C*,SH*,THISLOC=IN,GLOBALLOC=IN")\r
-public final class Equalizer {\r
- /**\r
- * Equalizer setting to denote that a given band will not be present in the\r
- * output signal.\r
- */\r
- @LOC("T")\r
- static public final float BAND_NOT_PRESENT = Float.NEGATIVE_INFINITY;\r
-\r
- @LOC("T")\r
- static public final Equalizer PASS_THRU_EQ = new Equalizer();\r
-\r
- @LOC("T")\r
- private static final int BANDS = 32;\r
-\r
- @LOC("B")\r
- private final float[] settings = new float[BANDS];\r
-\r
- /**\r
- * Creates a new <code>Equalizer</code> instance.\r
- */\r
- public Equalizer() {\r
- }\r
-\r
- // private Equalizer(float b1, float b2, float b3, float b4, float b5,\r
- // float b6, float b7, float b8, float b9, float b10, float b11,\r
- // float b12, float b13, float b14, float b15, float b16,\r
- // float b17, float b18, float b19, float b20);\r
-\r
- public Equalizer(float[] settings) {\r
- setFrom(settings);\r
- }\r
-\r
- public Equalizer(EQFunction eq) {\r
- setFrom(eq);\r
- }\r
-\r
- public void setFrom(float[] eq) {\r
- reset();\r
- int max = (eq.length > BANDS) ? BANDS : eq.length;\r
-\r
- for (int i = 0; i < max; i++) {\r
- settings[i] = limit(eq[i]);\r
- }\r
- }\r
-\r
- public void setFrom(EQFunction eq) {\r
- reset();\r
- int max = BANDS;\r
-\r
- for (int i = 0; i < max; i++) {\r
- settings[i] = limit(eq.getBand(i));\r
- }\r
- }\r
-\r
- /**\r
- * Sets the bands of this equalizer to the value the bands of another\r
- * equalizer. Bands that are not present in both equalizers are ignored.\r
- */\r
- public void setFrom(Equalizer eq) {\r
- if (eq != this) {\r
- setFrom(eq.settings);\r
- }\r
- }\r
-\r
- /**\r
- * Sets all bands to 0.0\r
- */\r
- public void reset() {\r
- for (int i = 0; i < BANDS; i++) {\r
- settings[i] = 0.0f;\r
- }\r
- }\r
-\r
- /**\r
- * Retrieves the number of bands present in this equalizer.\r
- */\r
- public int getBandCount() {\r
- return settings.length;\r
- }\r
-\r
- public float setBand(int band, float neweq) {\r
- float eq = 0.0f;\r
-\r
- if ((band >= 0) && (band < BANDS)) {\r
- eq = settings[band];\r
- settings[band] = limit(neweq);\r
- }\r
-\r
- return eq;\r
- }\r
-\r
- /**\r
- * Retrieves the eq setting for a given band.\r
- */\r
- public float getBand(int band) {\r
- float eq = 0.0f;\r
-\r
- if ((band >= 0) && (band < BANDS)) {\r
- eq = settings[band];\r
- }\r
-\r
- return eq;\r
- }\r
-\r
- private float limit(float eq) {\r
- if (eq == BAND_NOT_PRESENT)\r
- return eq;\r
- if (eq > 1.0f)\r
- return 1.0f;\r
- if (eq < -1.0f)\r
- return -1.0f;\r
-\r
- return eq;\r
- }\r
-\r
- /**\r
- * Retrieves an array of floats whose values represent a scaling factor that\r
- * can be applied to linear samples in each band to provide the equalization\r
- * represented by this instance.\r
- * \r
- * @return an array of factors that can be applied to the subbands.\r
- */\r
- @LATTICE("OUT<THIS,THISLOC=THIS")\r
- @RETURNLOC("OUT")\r
- float[] getBandFactors() {\r
- @LOC("OUT") float[] factors = new float[BANDS];\r
- @LOC("THIS,Equalizer.IDX") int maxCount = BANDS;\r
- for (@LOC("THIS,Equalizer.IDX") int i = 0; i < maxCount; i++) {\r
- factors[i] = getBandFactor(settings[i]);\r
- }\r
-\r
- return factors;\r
- }\r
-\r
- /**\r
- * Converts an equalizer band setting to a sample factor. The factor is\r
- * determined by the function f = 2^n where n is the equalizer band setting in\r
- * the range [-1.0,1.0].\r
- * \r
- */\r
- @RETURNLOC("C")\r
- @PCLOC("P")\r
- float getBandFactor(@LOC("IN") float eq) {\r
- if (eq == BAND_NOT_PRESENT)\r
- return 0.0f;\r
-\r
- @LOC("C") float f = (float) Math.pow(2.0, eq);\r
- return f;\r
- }\r
-\r
- static abstract public class EQFunction {\r
- /**\r
- * Returns the setting of a band in the equalizer.\r
- * \r
- * @param band\r
- * The index of the band to retrieve the setting for.\r
- * \r
- * @return the setting of the specified band. This is a value between -1 and\r
- * +1.\r
- */\r
- public float getBand(int band) {\r
- return 0.0f;\r
- }\r
-\r
- }\r
-\r
-}\r
+/*
+ * 11/19/04 1.0 moved to LGPL.
+ * 12/12/99 Initial version. mdm@techie.com
+ *-----------------------------------------------------------------------
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *----------------------------------------------------------------------
+ */
+
+/**
+ * The <code>Equalizer</code> class can be used to specify equalization settings
+ * for the MPEG audio decoder.
+ * <p>
+ * The equalizer consists of 32 band-pass filters. Each band of the equalizer
+ * can take on a fractional value between -1.0 and +1.0. At -1.0, the input
+ * signal is attenuated by 6dB, at +1.0 the signal is amplified by 6dB.
+ *
+ * @see Decoder
+ *
+ * @author MDM
+ */
+@LATTICE("B<IDX,IDX<T,IDX*")
+@METHODDEFAULT("OUT<V,V<SH,SH<C,C<IN,IN<P,C*,SH*,THISLOC=IN,GLOBALLOC=IN")
+public final class Equalizer {
+ /**
+ * Equalizer setting to denote that a given band will not be present in the
+ * output signal.
+ */
+ @LOC("T")
+ static public final float BAND_NOT_PRESENT = Float.NEGATIVE_INFINITY;
+
+ @LOC("T")
+ static public final Equalizer PASS_THRU_EQ = new Equalizer();
+
+ @LOC("T")
+ private static final int BANDS = 32;
+
+ @LOC("B")
+ private final float[] settings = new float[BANDS];
+
+ /**
+ * Creates a new <code>Equalizer</code> instance.
+ */
+ public Equalizer() {
+ }
+
+ // private Equalizer(float b1, float b2, float b3, float b4, float b5,
+ // float b6, float b7, float b8, float b9, float b10, float b11,
+ // float b12, float b13, float b14, float b15, float b16,
+ // float b17, float b18, float b19, float b20);
+
+ public Equalizer(float[] settings) {
+ setFrom(settings);
+ }
+
+ public Equalizer(EQFunction eq) {
+ setFrom(eq);
+ }
+
+ public void setFrom(float[] eq) {
+ reset();
+ int max = (eq.length > BANDS) ? BANDS : eq.length;
+
+ for (int i = 0; i < max; i++) {
+ settings[i] = limit(eq[i]);
+ }
+ }
+
+ public void setFrom(EQFunction eq) {
+ reset();
+ int max = BANDS;
+
+ for (int i = 0; i < max; i++) {
+ settings[i] = limit(eq.getBand(i));
+ }
+ }
+
+ /**
+ * Sets the bands of this equalizer to the value the bands of another
+ * equalizer. Bands that are not present in both equalizers are ignored.
+ */
+ public void setFrom(Equalizer eq) {
+ if (eq != this) {
+ setFrom(eq.settings);
+ }
+ }
+
+ /**
+ * Sets all bands to 0.0
+ */
+ public void reset() {
+ for (int i = 0; i < BANDS; i++) {
+ settings[i] = 0.0f;
+ }
+ }
+
+ /**
+ * Retrieves the number of bands present in this equalizer.
+ */
+ public int getBandCount() {
+ return settings.length;
+ }
+
+ public float setBand(int band, float neweq) {
+ float eq = 0.0f;
+
+ if ((band >= 0) && (band < BANDS)) {
+ eq = settings[band];
+ settings[band] = limit(neweq);
+ }
+
+ return eq;
+ }
+
+ /**
+ * Retrieves the eq setting for a given band.
+ */
+ public float getBand(int band) {
+ float eq = 0.0f;
+
+ if ((band >= 0) && (band < BANDS)) {
+ eq = settings[band];
+ }
+
+ return eq;
+ }
+
+ private float limit(float eq) {
+ if (eq == BAND_NOT_PRESENT)
+ return eq;
+ if (eq > 1.0f)
+ return 1.0f;
+ if (eq < -1.0f)
+ return -1.0f;
+
+ return eq;
+ }
+
+ /**
+ * Retrieves an array of floats whose values represent a scaling factor that
+ * can be applied to linear samples in each band to provide the equalization
+ * represented by this instance.
+ *
+ * @return an array of factors that can be applied to the subbands.
+ */
+ @LATTICE("OUT<THIS,THISLOC=THIS")
+ @RETURNLOC("OUT")
+ float[] getBandFactors() {
+ @LOC("OUT") float[] factors = new float[BANDS];
+ @LOC("THIS,Equalizer.IDX") int maxCount = BANDS;
+ for (@LOC("THIS,Equalizer.IDX") int i = 0; i < maxCount; i++) {
+ factors[i] = getBandFactor(settings[i]);
+ }
+
+ return factors;
+ }
+
+ /**
+ * Converts an equalizer band setting to a sample factor. The factor is
+ * determined by the function f = 2^n where n is the equalizer band setting in
+ * the range [-1.0,1.0].
+ *
+ */
+ @RETURNLOC("C")
+ @PCLOC("P")
+ float getBandFactor(@LOC("IN") float eq) {
+ if (eq == BAND_NOT_PRESENT)
+ return 0.0f;
+
+ @LOC("C") float f = (float) Math.pow(2.0, eq);
+ return f;
+ }
+
+ static abstract public class EQFunction {
+ /**
+ * Returns the setting of a band in the equalizer.
+ *
+ * @param band
+ * The index of the band to retrieve the setting for.
+ *
+ * @return the setting of the specified band. This is a value between -1 and
+ * +1.
+ */
+ public float getBand(int band) {
+ return 0.0f;
+ }
+
+ }
+
+}