~gryle-devel/gryle/trunk-deleted

« back to all changes in this revision

Viewing changes to src/javazoom/jl/decoder/OutputChannels.java

  • Committer: Richard Leo Marsh Warburton
  • Date: 2007-01-13 22:08:02 UTC
  • mto: (1.1.6 gryle)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: rlmw@viglab-28-20070113220802-6cjjur0hdk1rce47
added src files

Show diffs side-by-side

added added

removed removed

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