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
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
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
22 * A Type-safe representation of the the supported output channel constants.
\r
24 * This class is immutable and, hence, is thread safe.
\r
26 * @author Mat McGowan 12/12/99
\r
30 public class OutputChannels {
\r
32 * Flag to indicate output should include both channels.
\r
34 public static final int BOTH_CHANNELS = 0;
\r
37 * Flag to indicate output should include the left channel only.
\r
39 public static final int LEFT_CHANNEL = 1;
\r
42 * Flag to indicate output should include the right channel only.
\r
44 public static final int RIGHT_CHANNEL = 2;
\r
47 * Flag to indicate output is mono.
\r
49 public static final int DOWNMIX_CHANNELS = 3;
\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
56 private/* final */int outputChannels;
\r
59 * Creates an <code>OutputChannels</code> instance corresponding to the given
\r
63 * one of the OutputChannels channel code constants.
\r
65 * @throws IllegalArgumentException
\r
66 * if code is not a valid channel code.
\r
68 static public OutputChannels fromInt(int code) {
\r
76 case DOWNMIX_CHANNELS:
\r
79 throw new IllegalArgumentException("Invalid channel code: " + code);
\r
83 public OutputChannels(int channels) {
\r
84 outputChannels = channels;
\r
86 if (channels < 0 || channels > 3)
\r
87 throw new IllegalArgumentException("channels");
\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
94 * @return the channel code represented by this instance.
\r
96 public int getChannelsOutputCode() {
\r
97 return outputChannels;
\r
101 * Retrieves the number of output channels represented by this channel output
\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
107 public int getChannelCount() {
\r
108 int count = (outputChannels == BOTH_CHANNELS) ? 2 : 1;
\r
112 public boolean equals(Object o) {
\r
113 boolean equals = false;
\r
115 if (o instanceof OutputChannels) {
\r
116 OutputChannels oc = (OutputChannels) o;
\r
117 equals = (oc.outputChannels == outputChannels);
\r
123 public int hashCode() {
\r
124 return outputChannels;
\r