544dfb25e19e90d0518c7e632b2611ca3fd959e5
[IRC.git] / Robust / src / Tests / ssJava / mp3decoder / 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 @LATTICE("B<T")\r
30 @METHODDEFAULT("OUT<IN")\r
31 public class OutputChannels {\r
32   /**\r
33    * Flag to indicate output should include both channels.\r
34    */\r
35   public static final int BOTH_CHANNELS = 0;\r
36 \r
37   /**\r
38    * Flag to indicate output should include the left channel only.\r
39    */\r
40   public static final int LEFT_CHANNEL = 1;\r
41 \r
42   /**\r
43    * Flag to indicate output should include the right channel only.\r
44    */\r
45   public static final int RIGHT_CHANNEL = 2;\r
46 \r
47   /**\r
48    * Flag to indicate output is mono.\r
49    */\r
50   public static final int DOWNMIX_CHANNELS = 3;\r
51 \r
52   @LOC("B")\r
53   public static final OutputChannels LEFT = new OutputChannels(LEFT_CHANNEL);\r
54   @LOC("B")\r
55   public static final OutputChannels RIGHT = new OutputChannels(RIGHT_CHANNEL);\r
56   @LOC("B")\r
57   public static final OutputChannels BOTH = new OutputChannels(BOTH_CHANNELS);\r
58   @LOC("B")\r
59   public static final OutputChannels DOWNMIX = new OutputChannels(DOWNMIX_CHANNELS);\r
60 \r
61   @LOC("T")\r
62   private/* final */int outputChannels;\r
63 \r
64   /**\r
65    * Creates an <code>OutputChannels</code> instance corresponding to the given\r
66    * channel code.\r
67    * \r
68    * @param code\r
69    *          one of the OutputChannels channel code constants.\r
70    * \r
71    * @throws IllegalArgumentException\r
72    *           if code is not a valid channel code.\r
73    */\r
74   static public OutputChannels fromInt(int code) {\r
75     switch (code) {\r
76     case LEFT_CHANNEL:\r
77       return LEFT;\r
78     case RIGHT_CHANNEL:\r
79       return RIGHT;\r
80     case BOTH_CHANNELS:\r
81       return BOTH;\r
82     case DOWNMIX_CHANNELS:\r
83       return DOWNMIX;\r
84     default:\r
85       throw new IllegalArgumentException("Invalid channel code: " + code);\r
86     }\r
87   }\r
88 \r
89   public OutputChannels(@LOC("IN") int channels) {\r
90     outputChannels = channels;\r
91 \r
92     if (channels < 0 || channels > 3)\r
93       throw new IllegalArgumentException("channels");\r
94   }\r
95 \r
96   /**\r
97    * Retrieves the code representing the desired output channels. Will be one of\r
98    * LEFT_CHANNEL, RIGHT_CHANNEL, BOTH_CHANNELS or DOWNMIX_CHANNELS.\r
99    * \r
100    * @return the channel code represented by this instance.\r
101    */\r
102   public int getChannelsOutputCode() {\r
103     return outputChannels;\r
104   }\r
105 \r
106   /**\r
107    * Retrieves the number of output channels represented by this channel output\r
108    * type.\r
109    * \r
110    * @return The number of output channels for this channel output type. This\r
111    *         will be 2 for BOTH_CHANNELS only, and 1 for all other types.\r
112    */\r
113   public int getChannelCount() {\r
114     int count = (outputChannels == BOTH_CHANNELS) ? 2 : 1;\r
115     return count;\r
116   }\r
117 \r
118   public boolean equals(Object o) {\r
119     boolean equals = false;\r
120 \r
121     if (o instanceof OutputChannels) {\r
122       OutputChannels oc = (OutputChannels) o;\r
123       equals = (oc.outputChannels == outputChannels);\r
124     }\r
125 \r
126     return equals;\r
127   }\r
128 \r
129   public int hashCode() {\r
130     return outputChannels;\r
131   }\r
132 \r
133 }\r