< prev index next >

src/java.desktop/share/classes/javax/sound/sampled/AudioFormat.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2017, 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


 250              sampleRate,
 251              sampleSizeInBits,
 252              channels,
 253              (channels == AudioSystem.NOT_SPECIFIED || sampleSizeInBits == AudioSystem.NOT_SPECIFIED)?
 254              AudioSystem.NOT_SPECIFIED:
 255              ((sampleSizeInBits + 7) / 8) * channels,
 256              sampleRate,
 257              bigEndian);
 258     }
 259 
 260     /**
 261      * Obtains the type of encoding for sounds in this format.
 262      *
 263      * @return the encoding type
 264      * @see Encoding#PCM_SIGNED
 265      * @see Encoding#PCM_UNSIGNED
 266      * @see Encoding#ULAW
 267      * @see Encoding#ALAW
 268      */
 269     public Encoding getEncoding() {
 270 
 271         return encoding;
 272     }
 273 
 274     /**
 275      * Obtains the sample rate. For compressed formats, the return value is the
 276      * sample rate of the uncompressed audio data. When this {@code AudioFormat}
 277      * is used for queries (e.g.
 278      * {@link AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
 279      * AudioSystem.isConversionSupported}) or capabilities (e.g.
 280      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a sample rate
 281      * of {@code AudioSystem.NOT_SPECIFIED} means that any sample rate is
 282      * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
 283      * sample rate is not defined for this audio format.
 284      *
 285      * @return the number of samples per second, or
 286      *         {@code AudioSystem.NOT_SPECIFIED}
 287      * @see #getFrameRate()
 288      * @see AudioSystem#NOT_SPECIFIED
 289      */
 290     public float getSampleRate() {
 291 
 292         return sampleRate;
 293     }
 294 
 295     /**
 296      * Obtains the size of a sample. For compressed formats, the return value is
 297      * the sample size of the uncompressed audio data. When this
 298      * {@code AudioFormat} is used for queries (e.g.
 299      * {@link AudioSystem#isConversionSupported(AudioFormat,AudioFormat)
 300      * AudioSystem.isConversionSupported}) or capabilities (e.g.
 301      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a sample size
 302      * of {@code AudioSystem.NOT_SPECIFIED} means that any sample size is
 303      * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
 304      * sample size is not defined for this audio format.
 305      *
 306      * @return the number of bits in each sample, or
 307      *         {@code AudioSystem.NOT_SPECIFIED}
 308      * @see #getFrameSize()
 309      * @see AudioSystem#NOT_SPECIFIED
 310      */
 311     public int getSampleSizeInBits() {
 312 
 313         return sampleSizeInBits;
 314     }
 315 
 316     /**
 317      * Obtains the number of channels. When this {@code AudioFormat} is used for
 318      * queries (e.g. {@link AudioSystem#isConversionSupported(AudioFormat,
 319      * AudioFormat) AudioSystem.isConversionSupported}) or capabilities (e.g.
 320      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a return
 321      * value of {@code AudioSystem.NOT_SPECIFIED} means that any (positive)
 322      * number of channels is acceptable.
 323      *
 324      * @return The number of channels (1 for mono, 2 for stereo, etc.), or
 325      *         {@code AudioSystem.NOT_SPECIFIED}
 326      * @see AudioSystem#NOT_SPECIFIED
 327      */
 328     public int getChannels() {
 329 
 330         return channels;
 331     }
 332 
 333     /**
 334      * Obtains the frame size in bytes. When this {@code AudioFormat} is used
 335      * for queries (e.g. {@link AudioSystem#isConversionSupported(AudioFormat,
 336      * AudioFormat) AudioSystem.isConversionSupported}) or capabilities (e.g.
 337      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a frame size
 338      * of {@code AudioSystem.NOT_SPECIFIED} means that any frame size is
 339      * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
 340      * frame size is not defined for this audio format.
 341      *
 342      * @return the number of bytes per frame, or
 343      *         {@code AudioSystem.NOT_SPECIFIED}
 344      * @see #getSampleSizeInBits()
 345      * @see AudioSystem#NOT_SPECIFIED
 346      */
 347     public int getFrameSize() {
 348 
 349         return frameSize;
 350     }
 351 
 352     /**
 353      * Obtains the frame rate in frames per second. When this
 354      * {@code AudioFormat} is used for queries (e.g.
 355      * {@link AudioSystem#isConversionSupported(AudioFormat,AudioFormat)
 356      * AudioSystem.isConversionSupported}) or capabilities (e.g.
 357      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a frame rate
 358      * of {@code AudioSystem.NOT_SPECIFIED} means that any frame rate is
 359      * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
 360      * frame rate is not defined for this audio format.
 361      *
 362      * @return the number of frames per second, or
 363      *         {@code AudioSystem.NOT_SPECIFIED}
 364      * @see #getSampleRate()
 365      * @see AudioSystem#NOT_SPECIFIED
 366      */
 367     public float getFrameRate() {
 368 
 369         return frameRate;
 370     }
 371 
 372     /**
 373      * Indicates whether the audio data is stored in big-endian or little-endian
 374      * byte order. If the sample size is not more than one byte, the return
 375      * value is irrelevant.
 376      *
 377      * @return {@code true} if the data is stored in big-endian byte order,
 378      *         {@code false} if little-endian
 379      */
 380     public boolean isBigEndian() {
 381 
 382         return bigEndian;
 383     }
 384 
 385     /**
 386      * Obtain an unmodifiable map of properties. The concept of properties is
 387      * further explained in the {@link AudioFileFormat class description}.
 388      *
 389      * @return a {@code Map<String, Object>} object containing all properties.
 390      *         If no properties are recognized, an empty map is returned.
 391      * @see #getProperty(String)
 392      * @since 1.5
 393      */
 394     @SuppressWarnings("unchecked") // Cast of result of clone.
 395     public Map<String,Object> properties() {
 396         Map<String,Object> ret;
 397         if (properties == null) {
 398             ret = new HashMap<>(0);
 399         } else {
 400             ret = (Map<String,Object>) (properties.clone());
 401         }


   1 /*
   2  * Copyright (c) 1999, 2018, 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


 250              sampleRate,
 251              sampleSizeInBits,
 252              channels,
 253              (channels == AudioSystem.NOT_SPECIFIED || sampleSizeInBits == AudioSystem.NOT_SPECIFIED)?
 254              AudioSystem.NOT_SPECIFIED:
 255              ((sampleSizeInBits + 7) / 8) * channels,
 256              sampleRate,
 257              bigEndian);
 258     }
 259 
 260     /**
 261      * Obtains the type of encoding for sounds in this format.
 262      *
 263      * @return the encoding type
 264      * @see Encoding#PCM_SIGNED
 265      * @see Encoding#PCM_UNSIGNED
 266      * @see Encoding#ULAW
 267      * @see Encoding#ALAW
 268      */
 269     public Encoding getEncoding() {

 270         return encoding;
 271     }
 272 
 273     /**
 274      * Obtains the sample rate. For compressed formats, the return value is the
 275      * sample rate of the uncompressed audio data. When this {@code AudioFormat}
 276      * is used for queries (e.g.
 277      * {@link AudioSystem#isConversionSupported(AudioFormat, AudioFormat)
 278      * AudioSystem.isConversionSupported}) or capabilities (e.g.
 279      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a sample rate
 280      * of {@code AudioSystem.NOT_SPECIFIED} means that any sample rate is
 281      * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
 282      * sample rate is not defined for this audio format.
 283      *
 284      * @return the number of samples per second, or
 285      *         {@code AudioSystem.NOT_SPECIFIED}
 286      * @see #getFrameRate()
 287      * @see AudioSystem#NOT_SPECIFIED
 288      */
 289     public float getSampleRate() {

 290         return sampleRate;
 291     }
 292 
 293     /**
 294      * Obtains the size of a sample. For compressed formats, the return value is
 295      * the sample size of the uncompressed audio data. When this
 296      * {@code AudioFormat} is used for queries (e.g.
 297      * {@link AudioSystem#isConversionSupported(AudioFormat,AudioFormat)
 298      * AudioSystem.isConversionSupported}) or capabilities (e.g.
 299      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a sample size
 300      * of {@code AudioSystem.NOT_SPECIFIED} means that any sample size is
 301      * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
 302      * sample size is not defined for this audio format.
 303      *
 304      * @return the number of bits in each sample, or
 305      *         {@code AudioSystem.NOT_SPECIFIED}
 306      * @see #getFrameSize()
 307      * @see AudioSystem#NOT_SPECIFIED
 308      */
 309     public int getSampleSizeInBits() {

 310         return sampleSizeInBits;
 311     }
 312 
 313     /**
 314      * Obtains the number of channels. When this {@code AudioFormat} is used for
 315      * queries (e.g. {@link AudioSystem#isConversionSupported(AudioFormat,
 316      * AudioFormat) AudioSystem.isConversionSupported}) or capabilities (e.g.
 317      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a return
 318      * value of {@code AudioSystem.NOT_SPECIFIED} means that any (positive)
 319      * number of channels is acceptable.
 320      *
 321      * @return The number of channels (1 for mono, 2 for stereo, etc.), or
 322      *         {@code AudioSystem.NOT_SPECIFIED}
 323      * @see AudioSystem#NOT_SPECIFIED
 324      */
 325     public int getChannels() {

 326         return channels;
 327     }
 328 
 329     /**
 330      * Obtains the frame size in bytes. When this {@code AudioFormat} is used
 331      * for queries (e.g. {@link AudioSystem#isConversionSupported(AudioFormat,
 332      * AudioFormat) AudioSystem.isConversionSupported}) or capabilities (e.g.
 333      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a frame size
 334      * of {@code AudioSystem.NOT_SPECIFIED} means that any frame size is
 335      * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
 336      * frame size is not defined for this audio format.
 337      *
 338      * @return the number of bytes per frame, or
 339      *         {@code AudioSystem.NOT_SPECIFIED}
 340      * @see #getSampleSizeInBits()
 341      * @see AudioSystem#NOT_SPECIFIED
 342      */
 343     public int getFrameSize() {

 344         return frameSize;
 345     }
 346 
 347     /**
 348      * Obtains the frame rate in frames per second. When this
 349      * {@code AudioFormat} is used for queries (e.g.
 350      * {@link AudioSystem#isConversionSupported(AudioFormat,AudioFormat)
 351      * AudioSystem.isConversionSupported}) or capabilities (e.g.
 352      * {@link DataLine.Info#getFormats DataLine.Info.getFormats}), a frame rate
 353      * of {@code AudioSystem.NOT_SPECIFIED} means that any frame rate is
 354      * acceptable. {@code AudioSystem.NOT_SPECIFIED} is also returned when the
 355      * frame rate is not defined for this audio format.
 356      *
 357      * @return the number of frames per second, or
 358      *         {@code AudioSystem.NOT_SPECIFIED}
 359      * @see #getSampleRate()
 360      * @see AudioSystem#NOT_SPECIFIED
 361      */
 362     public float getFrameRate() {

 363         return frameRate;
 364     }
 365 
 366     /**
 367      * Indicates whether the audio data is stored in big-endian or little-endian
 368      * byte order. If the sample size is not more than one byte, the return
 369      * value is irrelevant.
 370      *
 371      * @return {@code true} if the data is stored in big-endian byte order,
 372      *         {@code false} if little-endian
 373      */
 374     public boolean isBigEndian() {

 375         return bigEndian;
 376     }
 377 
 378     /**
 379      * Obtain an unmodifiable map of properties. The concept of properties is
 380      * further explained in the {@link AudioFileFormat class description}.
 381      *
 382      * @return a {@code Map<String, Object>} object containing all properties.
 383      *         If no properties are recognized, an empty map is returned.
 384      * @see #getProperty(String)
 385      * @since 1.5
 386      */
 387     @SuppressWarnings("unchecked") // Cast of result of clone.
 388     public Map<String,Object> properties() {
 389         Map<String,Object> ret;
 390         if (properties == null) {
 391             ret = new HashMap<>(0);
 392         } else {
 393             ret = (Map<String,Object>) (properties.clone());
 394         }


< prev index next >