summaryrefslogtreecommitdiff
path: root/songdbj/javazoom/jl/decoder/OutputChannels.java
diff options
context:
space:
mode:
Diffstat (limited to 'songdbj/javazoom/jl/decoder/OutputChannels.java')
-rw-r--r--songdbj/javazoom/jl/decoder/OutputChannels.java143
1 files changed, 143 insertions, 0 deletions
diff --git a/songdbj/javazoom/jl/decoder/OutputChannels.java b/songdbj/javazoom/jl/decoder/OutputChannels.java
new file mode 100644
index 0000000000..58c8310de7
--- /dev/null
+++ b/songdbj/javazoom/jl/decoder/OutputChannels.java
@@ -0,0 +1,143 @@
1/*
2 * 11/19/04 1.0 moved to LGPL.
3 * 12/12/99 Initial implementation. mdm@techie.com.
4 *-----------------------------------------------------------------------
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Library General Public License as published
7 * by the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------
19 */
20
21package javazoom.jl.decoder;
22
23
24/**
25 * A Type-safe representation of the the supported output channel
26 * constants.
27 *
28 * This class is immutable and, hence, is thread safe.
29 *
30 * @author Mat McGowan 12/12/99
31 * @since 0.0.7
32 */
33public class OutputChannels
34{
35 /**
36 * Flag to indicate output should include both channels.
37 */
38 public static final int BOTH_CHANNELS = 0;
39
40 /**
41 * Flag to indicate output should include the left channel only.
42 */
43 public static final int LEFT_CHANNEL = 1;
44
45 /**
46 * Flag to indicate output should include the right channel only.
47 */
48 public static final int RIGHT_CHANNEL = 2;
49
50 /**
51 * Flag to indicate output is mono.
52 */
53 public static final int DOWNMIX_CHANNELS = 3;
54
55
56 public static final OutputChannels LEFT = new OutputChannels(LEFT_CHANNEL);
57 public static final OutputChannels RIGHT = new OutputChannels(RIGHT_CHANNEL);
58 public static final OutputChannels BOTH = new OutputChannels(BOTH_CHANNELS);
59 public static final OutputChannels DOWNMIX = new OutputChannels(DOWNMIX_CHANNELS);
60
61
62 private /*final*/ int outputChannels;
63
64 /**
65 * Creates an <code>OutputChannels</code> instance
66 * corresponding to the given channel code.
67 *
68 * @param code one of the OutputChannels channel code constants.
69 *
70 * @throws IllegalArgumentException if code is not a valid
71 * channel code.
72 */
73 static public OutputChannels fromInt(int code)
74 {
75 switch (code)
76 {
77 case LEFT_CHANNEL:
78 return LEFT;
79 case RIGHT_CHANNEL:
80 return RIGHT;
81 case BOTH_CHANNELS:
82 return BOTH;
83 case DOWNMIX_CHANNELS:
84 return DOWNMIX;
85 default:
86 throw new IllegalArgumentException("Invalid channel code: "+code);
87 }
88 }
89
90 private OutputChannels(int channels)
91 {
92 outputChannels = channels;
93
94 if (channels<0 || channels>3)
95 throw new IllegalArgumentException("channels");
96 }
97
98 /**
99 * Retrieves the code representing the desired output channels.
100 * Will be one of LEFT_CHANNEL, RIGHT_CHANNEL, BOTH_CHANNELS
101 * or DOWNMIX_CHANNELS.
102 *
103 * @return the channel code represented by this instance.
104 */
105 public int getChannelsOutputCode()
106 {
107 return outputChannels;
108 }
109
110 /**
111 * Retrieves the number of output channels represented
112 * by this channel output type.
113 *
114 * @return The number of output channels for this channel output
115 * type. This will be 2 for BOTH_CHANNELS only, and 1
116 * for all other types.
117 */
118 public int getChannelCount()
119 {
120 int count = (outputChannels==BOTH_CHANNELS) ? 2 : 1;
121 return count;
122 }
123
124
125 public boolean equals(Object o)
126 {
127 boolean equals = false;
128
129 if (o instanceof OutputChannels)
130 {
131 OutputChannels oc = (OutputChannels)o;
132 equals = (oc.outputChannels == outputChannels);
133 }
134
135 return equals;
136 }
137
138 public int hashCode()
139 {
140 return outputChannels;
141 }
142
143}