< prev index next >

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

Print this page
rev 57600 : 8236980: toString() cleanup in JavaSound
Reviewed-by: XXX

*** 1,7 **** /* ! * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 446,532 **** } return false; } /** ! * Returns a string that describes the format, such as: "PCM SIGNED 22050 Hz ! * 16 bit mono big-endian". The contents of the string may vary between ! * implementations of Java Sound. * ! * @return a string that describes the format parameters */ @Override public String toString() { ! String sEncoding = ""; ! if (getEncoding() != null) { ! sEncoding = getEncoding().toString() + " "; ! } ! String sSampleRate; ! if (getSampleRate() == (float) AudioSystem.NOT_SPECIFIED) { ! sSampleRate = "unknown sample rate, "; ! } else { ! sSampleRate = "" + getSampleRate() + " Hz, "; ! } ! String sSampleSizeInBits; ! if (getSampleSizeInBits() == (float) AudioSystem.NOT_SPECIFIED) { ! sSampleSizeInBits = "unknown bits per sample, "; ! } else { ! sSampleSizeInBits = "" + getSampleSizeInBits() + " bit, "; ! } ! String sChannels; ! if (getChannels() == 1) { ! sChannels = "mono, "; ! } else ! if (getChannels() == 2) { ! sChannels = "stereo, "; ! } else { ! if (getChannels() == AudioSystem.NOT_SPECIFIED) { ! sChannels = " unknown number of channels, "; ! } else { ! sChannels = ""+getChannels()+" channels, "; ! } ! } ! String sFrameSize; ! if (getFrameSize() == (float) AudioSystem.NOT_SPECIFIED) { ! sFrameSize = "unknown frame size, "; ! } else { ! sFrameSize = "" + getFrameSize()+ " bytes/frame, "; ! } ! ! String sFrameRate = ""; if (Math.abs(getSampleRate() - getFrameRate()) > 0.00001) { ! if (getFrameRate() == (float) AudioSystem.NOT_SPECIFIED) { ! sFrameRate = "unknown frame rate, "; ! } else { ! sFrameRate = getFrameRate() + " frames/second, "; ! } } ! String sEndian = ""; if ((getEncoding().equals(Encoding.PCM_SIGNED) || getEncoding().equals(Encoding.PCM_UNSIGNED)) && ((getSampleSizeInBits() > 8) || (getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED))) { ! if (isBigEndian()) { ! sEndian = "big-endian"; ! } else { ! sEndian = "little-endian"; } - } - - return sEncoding - + sSampleRate - + sSampleSizeInBits - + sChannels - + sFrameSize - + sFrameRate - + sEndian; } /** * The {@code Encoding} class names the specific type of data representation * used for an audio stream. The encoding includes aspects of the sound --- 446,496 ---- } return false; } /** ! * Returns a string that describes the audio format, such as: "PCM SIGNED ! * 22050 Hz 16 bit mono big-endian". The contents of the string may vary ! * between implementations of Java Sound. * ! * @return a string representation of the audio format */ @Override public String toString() { ! String sampleRate = getSampleRate() == AudioSystem.NOT_SPECIFIED ? ! "unknown sample rate" : getSampleRate() + " Hz"; ! String sampleSize = getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED ? ! "unknown bits per sample" : getSampleSizeInBits() + " bit"; ! String channels = switch (getChannels()) { ! case 1 -> "mono"; ! case 2 -> "stereo"; ! case AudioSystem.NOT_SPECIFIED -> "unknown number of channels"; ! default -> getChannels() + " channels"; ! }; ! String frameSize = getFrameSize() == AudioSystem.NOT_SPECIFIED ? ! "unknown frame size" : getFrameSize() + " bytes/frame"; ! String frameRate = ""; if (Math.abs(getSampleRate() - getFrameRate()) > 0.00001) { ! frameRate = getFrameRate() == AudioSystem.NOT_SPECIFIED ? ! ", unknown frame rate":", " + getFrameRate() + " frames/second"; } ! String bigEndian = ""; if ((getEncoding().equals(Encoding.PCM_SIGNED) || getEncoding().equals(Encoding.PCM_UNSIGNED)) && ((getSampleSizeInBits() > 8) || (getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED))) { ! bigEndian = isBigEndian() ? ", big-endian" : ", little-endian"; } + return String.format("%s %s, %s, %s, %s%s%s", getEncoding(), + sampleRate, sampleSize, channels, frameSize, + frameRate, bigEndian); } /** * The {@code Encoding} class names the specific type of data representation * used for an audio stream. The encoding includes aspects of the sound
*** 628,644 **** public final int hashCode() { return name != null ? name.hashCode() : 0; } /** ! * Provides the {@code String} representation of the encoding. This ! * {@code String} is the same name that was passed to the constructor. * For the predefined encodings, the name is similar to the encoding's * variable (field) name. For example, {@code PCM_SIGNED.toString()} * returns the name "PCM_SIGNED". * ! * @return the encoding name */ @Override public final String toString() { return name; } --- 592,607 ---- public final int hashCode() { return name != null ? name.hashCode() : 0; } /** ! * Returns encoding's name as the string representation of the encoding. * For the predefined encodings, the name is similar to the encoding's * variable (field) name. For example, {@code PCM_SIGNED.toString()} * returns the name "PCM_SIGNED". * ! * @return a string representation of the encoding */ @Override public final String toString() { return name; }
< prev index next >