changes: now Inference engine works fine with the EyeTracking benchmark.
[IRC.git] / Robust / src / Benchmarks / SSJava / MP3DecoderInfer / OutputChannels.java
1 /*\r
2  * 11/19/04 1.0 moved to LGPL.\r
3  * 12/12/99 Initial implementation.             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
9  *\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
14  *\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
19  */\r
20 \r
21 /**\r
22  * A Type-safe representation of the the supported output channel constants.\r
23  * \r
24  * This class is immutable and, hence, is thread safe.\r
25  * \r
26  * @author Mat McGowan 12/12/99\r
27  * @since 0.0.7\r
28  */\r
29 \r
30 public class OutputChannels {\r
31   /**\r
32    * Flag to indicate output should include both channels.\r
33    */\r
34   public static final int BOTH_CHANNELS = 0;\r
35 \r
36   /**\r
37    * Flag to indicate output should include the left channel only.\r
38    */\r
39   public static final int LEFT_CHANNEL = 1;\r
40 \r
41   /**\r
42    * Flag to indicate output should include the right channel only.\r
43    */\r
44   public static final int RIGHT_CHANNEL = 2;\r
45 \r
46   /**\r
47    * Flag to indicate output is mono.\r
48    */\r
49   public static final int DOWNMIX_CHANNELS = 3;\r
50 \r
51   public static final OutputChannels LEFT = new OutputChannels(LEFT_CHANNEL);\r
52   public static final OutputChannels RIGHT = new OutputChannels(RIGHT_CHANNEL);\r
53   public static final OutputChannels BOTH = new OutputChannels(BOTH_CHANNELS);\r
54   public static final OutputChannels DOWNMIX = new OutputChannels(DOWNMIX_CHANNELS);\r
55 \r
56   private/* final */int outputChannels;\r
57 \r
58   /**\r
59    * Creates an <code>OutputChannels</code> instance corresponding to the given\r
60    * channel code.\r
61    * \r
62    * @param code\r
63    *          one of the OutputChannels channel code constants.\r
64    * \r
65    * @throws IllegalArgumentException\r
66    *           if code is not a valid channel code.\r
67    */\r
68   static public OutputChannels fromInt(int code) {\r
69     switch (code) {\r
70     case LEFT_CHANNEL:\r
71       return LEFT;\r
72     case RIGHT_CHANNEL:\r
73       return RIGHT;\r
74     case BOTH_CHANNELS:\r
75       return BOTH;\r
76     case DOWNMIX_CHANNELS:\r
77       return DOWNMIX;\r
78     default:\r
79       throw new IllegalArgumentException("Invalid channel code: " + code);\r
80     }\r
81   }\r
82 \r
83   public OutputChannels(int channels) {\r
84     outputChannels = channels;\r
85 \r
86     if (channels < 0 || channels > 3)\r
87       throw new IllegalArgumentException("channels");\r
88   }\r
89 \r
90   /**\r
91    * Retrieves the code representing the desired output channels. Will be one of\r
92    * LEFT_CHANNEL, RIGHT_CHANNEL, BOTH_CHANNELS or DOWNMIX_CHANNELS.\r
93    * \r
94    * @return the channel code represented by this instance.\r
95    */\r
96   public int getChannelsOutputCode() {\r
97     return outputChannels;\r
98   }\r
99 \r
100   /**\r
101    * Retrieves the number of output channels represented by this channel output\r
102    * type.\r
103    * \r
104    * @return The number of output channels for this channel output type. This\r
105    *         will be 2 for BOTH_CHANNELS only, and 1 for all other types.\r
106    */\r
107   public int getChannelCount() {\r
108     int count = (outputChannels == BOTH_CHANNELS) ? 2 : 1;\r
109     return count;\r
110   }\r
111 \r
112   public boolean equals(Object o) {\r
113     boolean equals = false;\r
114 \r
115     if (o instanceof OutputChannels) {\r
116       OutputChannels oc = (OutputChannels) o;\r
117       equals = (oc.outputChannels == outputChannels);\r
118     }\r
119 \r
120     return equals;\r
121   }\r
122 \r
123   public int hashCode() {\r
124     return outputChannels;\r
125   }\r
126 \r
127 }\r