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