1 /* 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.media.jfxmedia.track; 27 28 import java.util.Locale; 29 import com.sun.media.jfxmedia.Media; 30 31 /** 32 * A class representing an audio track in a media. 33 * 34 * @see Media 35 */ 36 public class AudioTrack extends Track { 37 38 /** 39 * Channel mask bit indicating the absence of any channel 40 */ 41 public static final int UNKNOWN = 0; 42 43 /** 44 * Channel mask bit indicating the presence of a front left channel. 45 */ 46 public static final int FRONT_LEFT = 0x01; 47 48 /** 49 * Channel mask bit indicating the presence of a front right channel. 50 */ 51 public static final int FRONT_RIGHT = 0x02; 52 53 /** 54 * Channel mask bit indicating the presence of a front center channel. 55 */ 56 public static final int FRONT_CENTER = 0x04; 57 58 /** 59 * Channel mask bit indicating the presence of a rear left channel. 60 */ 61 public static final int REAR_LEFT = 0x08; 62 63 /** 64 * Channel mask bit indicating the presence of a rear right channel. 65 */ 66 public static final int REAR_RIGHT = 0x10; 67 68 /** 69 * Channel mask bit indicating the presence of a rear center channel. 70 */ 71 public static final int REAR_CENTER = 0x20; 72 73 private int numChannels; 74 private int channelMask; 75 private float encodedSampleRate; 76 77 /** 78 * Constructor. 79 * 80 * @param enabled Whether this track is enabled by default or not (if the container supports it) 81 * @param trackID A unique identifier for this track 82 * @param name The name of the track. 83 * @param encoding The encoding of the track. 84 * @param locale The language information for the track. 85 * @param numChannels The number of audio channels in the track. 86 * @param channelMask The channel mask of the track. 87 * @param encodedSampleRate The encoded sample rate in samples per second. 88 * @throws IllegalArgumentException if <code>name</code> or 89 * <code>encoding</code> is <code>null</code>. 90 * @throws IllegalArgumentException if <code>numChannels < 1</code>. 91 * @throws IllegalArgumentException if <code>encodedSampleRate ≤ 0.0</code>. 92 */ 93 public AudioTrack(boolean enabled, long trackID, String name, Locale locale, Track.Encoding encoding, 94 int numChannels, int channelMask, float encodedSampleRate) 95 { 96 super(enabled, trackID, name, locale, encoding); 97 98 if (numChannels < 1) { 99 throw new IllegalArgumentException("numChannels < 1!"); 100 } 101 102 if (encodedSampleRate <= 0.0F) { 103 throw new IllegalArgumentException("encodedSampleRate <= 0.0"); 104 } 105 106 this.numChannels = numChannels; 107 this.channelMask = channelMask; 108 this.encodedSampleRate = encodedSampleRate; 109 } 110 111 /** 112 * Retrieve the number of audio channels in the track. 113 * 114 * @return The number of channels. 115 */ 116 public int getNumChannels() { 117 return this.numChannels; 118 } 119 120 /** 121 * Retrieve the channel mask of the track. 122 * 123 * @return The channel mask. 124 */ 125 public int getChannelMask() { 126 return this.channelMask; 127 } 128 129 /** 130 * Retrieve the encoded sample rate. 131 * 132 * @return The sample rate. 133 */ 134 public float getEncodedSampleRate() { 135 return this.encodedSampleRate; 136 } 137 138 @Override 139 public final String toString() { 140 return "AudioTrack {\n"+ 141 " name: "+this.getName()+"\n"+ 142 " encoding: "+this.getEncodingType()+"\n"+ 143 " language: "+getLocale()+"\n"+ 144 " numChannels: "+this.numChannels+"\n"+ 145 " channelMask: "+this.channelMask+"\n"+ 146 " encodedSampleRate: "+this.encodedSampleRate+"\n"+ 147 "}"; 148 } 149 }