*----------------------------------------------------------------------\r
*/\r
\r
-\r
-\r
/**\r
- * The <code>Equalizer</code> class can be used to specify\r
- * equalization settings for the MPEG audio decoder. \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. \r
- * Each band of the equalizer can take on a fractional value between \r
- * -1.0 and +1.0.\r
- * At -1.0, the input signal is attenuated by 6dB, at +1.0 the signal is\r
- * amplified by 6dB. \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<T")\r
+@LATTICE("B<IDX,IDX<T,IDX*")\r
@METHODDEFAULT("OUT<V,V<SH,SH<C,C<IN,SH*,THISLOC=IN,GLOBALLOC=IN")\r
-public final class Equalizer\r
-{ \r
- /**\r
- * Equalizer setting to denote that a given band will not be\r
- * present in the output signal.\r
- */\r
- @LOC("T") static public final float BAND_NOT_PRESENT = Float.NEGATIVE_INFINITY;\r
- \r
- @LOC("T") static public final Equalizer PASS_THRU_EQ = new Equalizer();\r
- \r
- @LOC("T") private static final int BANDS = 32;\r
- \r
- @LOC("B") private final float[] settings = new float[BANDS];\r
- \r
- /**\r
- * Creates a new <code>Equalizer</code> instance. \r
- */\r
- public Equalizer()\r
- { \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
- {\r
- setFrom(settings);\r
- }\r
- \r
- public Equalizer(EQFunction eq)\r
- {\r
- setFrom(eq);\r
- }\r
- \r
- public void setFrom(float[] eq)\r
- {\r
- reset();\r
- int max = (eq.length > BANDS) ? BANDS : eq.length;\r
- \r
- for (int i=0; i<max; i++)\r
- {\r
- settings[i] = limit(eq[i]);\r
- }\r
- }\r
-\r
- public void setFrom(EQFunction eq)\r
- {\r
- reset();\r
- int max = BANDS;\r
- \r
- for (int i=0; i<max; i++)\r
- {\r
- settings[i] = limit(eq.getBand(i));\r
- } \r
- }\r
- \r
- /**\r
- * Sets the bands of this equalizer to the value the bands of\r
- * another equalizer. Bands that are not present in both equalizers are ignored. \r
- */\r
- public void setFrom(Equalizer eq)\r
- {\r
- if (eq!=this)\r
- {\r
- setFrom(eq.settings);\r
- }\r
- }\r
- \r
- \r
- \r
- \r
- /**\r
- * Sets all bands to 0.0\r
- */\r
- public void reset()\r
- {\r
- for (int i=0; i<BANDS; i++)\r
- {\r
- settings[i] = 0.0f;\r
- }\r
- }\r
-\r
- \r
- /**\r
- * Retrieves the number of bands present in this equalizer.\r
- */\r
- public int getBandCount()\r
- {\r
- return settings.length; \r
- }\r
- \r
- public float setBand(int band, float neweq)\r
- {\r
- float eq = 0.0f;\r
- \r
- if ((band>=0) && (band<BANDS))\r
- {\r
- eq = settings[band];\r
- settings[band] = limit(neweq);\r
- }\r
- \r
- return eq; \r
- }\r
- \r
- \r
- \r
- /**\r
- * Retrieves the eq setting for a given band.\r
- */\r
- public float getBand(int band)\r
- {\r
- float eq = 0.0f;\r
- \r
- if ((band>=0) && (band<BANDS))\r
- {\r
- eq = settings[band];\r
- }\r
- \r
- return eq;\r
- }\r
- \r
- private float limit(float eq)\r
- {\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\r
- * scaling factor that can be applied to linear samples\r
- * in each band to provide the equalization represented by\r
- * this instance. \r
- * \r
- * @return an array of factors that can be applied to the\r
- * subbands.\r
- */\r
- @RETURNLOC("OUT") \r
- float[] getBandFactors()\r
- {\r
- @LOC("OUT") float[] factors = new float[BANDS];\r
- @LOC("C") int maxCount = BANDS;\r
- for (@LOC("SH") int i=0; i<maxCount; i++)\r
- {\r
- factors[i] = getBandFactor(settings[i]);\r
- }\r
- \r
- return factors;\r
- }\r
- \r
- /**\r
- * Converts an equalizer band setting to a sample factor.\r
- * The factor is determined by the function f = 2^n where\r
- * n is the equalizer band setting in the range [-1.0,1.0].\r
- * \r
- */\r
- @RETURNLOC("C")\r
- float getBandFactor(@LOC("IN") float eq)\r
- {\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
- \r
- static abstract public class EQFunction\r
- {\r
- /**\r
- * Returns the setting of a band in the equalizer. \r
- * \r
- * @param band The index of the band to retrieve the setting\r
- * for. \r
- * \r
- * @return the setting of the specified band. This is a value between\r
- * -1 and +1.\r
- */\r
- public float getBand(int band)\r
- {\r
- return 0.0f; \r
- }\r
- \r
- }\r
- \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
+ 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