Path: blob/main/src/lwjgl/java/javazoom/jl/decoder/OutputChannels.java
8650 views
/*1* 11/19/04 1.0 moved to LGPL.2* 12/12/99 Initial implementation. [email protected].3*-----------------------------------------------------------------------4* This program is free software; you can redistribute it and/or modify5* it under the terms of the GNU Library General Public License as published6* by the Free Software Foundation; either version 2 of the License, or7* (at your option) any later version.8*9* This program is distributed in the hope that it will be useful,10* but WITHOUT ANY WARRANTY; without even the implied warranty of11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12* GNU Library General Public License for more details.13*14* You should have received a copy of the GNU Library General Public15* License along with this program; if not, write to the Free Software16* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.17*----------------------------------------------------------------------18*/1920package javazoom.jl.decoder;212223/**24* A Type-safe representation of the the supported output channel25* constants.26*27* This class is immutable and, hence, is thread safe.28*29* @author Mat McGowan 12/12/9930* @since 0.0.731*/32public class OutputChannels33{34/**35* Flag to indicate output should include both channels.36*/37public static final int BOTH_CHANNELS = 0;3839/**40* Flag to indicate output should include the left channel only.41*/42public static final int LEFT_CHANNEL = 1;4344/**45* Flag to indicate output should include the right channel only.46*/47public static final int RIGHT_CHANNEL = 2;4849/**50* Flag to indicate output is mono.51*/52public static final int DOWNMIX_CHANNELS = 3;535455public static final OutputChannels LEFT = new OutputChannels(LEFT_CHANNEL);56public static final OutputChannels RIGHT = new OutputChannels(RIGHT_CHANNEL);57public static final OutputChannels BOTH = new OutputChannels(BOTH_CHANNELS);58public static final OutputChannels DOWNMIX = new OutputChannels(DOWNMIX_CHANNELS);596061private /*final*/ int outputChannels;6263/**64* Creates an <code>OutputChannels</code> instance65* corresponding to the given channel code.66*67* @param code one of the OutputChannels channel code constants.68*69* @throws IllegalArgumentException if code is not a valid70* channel code.71*/72public static OutputChannels fromInt(int code)73{74switch (code)75{76case LEFT_CHANNEL:77return LEFT;78case RIGHT_CHANNEL:79return RIGHT;80case BOTH_CHANNELS:81return BOTH;82case DOWNMIX_CHANNELS:83return DOWNMIX;84default:85throw new IllegalArgumentException("Invalid channel code: "+code);86}87}8889private OutputChannels(int channels)90{91outputChannels = channels;9293if (channels<0 || channels>3)94throw new IllegalArgumentException("channels");95}9697/**98* Retrieves the code representing the desired output channels.99* Will be one of LEFT_CHANNEL, RIGHT_CHANNEL, BOTH_CHANNELS100* or DOWNMIX_CHANNELS.101*102* @return the channel code represented by this instance.103*/104public int getChannelsOutputCode()105{106return outputChannels;107}108109/**110* Retrieves the number of output channels represented111* by this channel output type.112*113* @return The number of output channels for this channel output114* type. This will be 2 for BOTH_CHANNELS only, and 1115* for all other types.116*/117public int getChannelCount()118{119int count = (outputChannels==BOTH_CHANNELS) ? 2 : 1;120return count;121}122123124public boolean equals(Object o)125{126boolean equals = false;127128if (o instanceof OutputChannels)129{130OutputChannels oc = (OutputChannels)o;131equals = (oc.outputChannels == outputChannels);132}133134return equals;135}136137public int hashCode()138{139return outputChannels;140}141142}143144145