提交 78958667 编写于 作者: A amenkov

4937708: AudioFormat.matches should allow NOT_SPECIFY in all fields

Reviewed-by: denis
上级 e417482c
...@@ -431,34 +431,36 @@ public class AudioFormat { ...@@ -431,34 +431,36 @@ public class AudioFormat {
/** /**
* Indicates whether this format matches the one specified. To match, * Indicates whether this format matches the one specified.
* two formats must have the same encoding, the same number of channels, * To match, two formats must have the same encoding,
* and the same number of bits per sample and bytes per frame. * and consistent values of the number of channels, sample rate, sample size,
* The two formats must also have the same sample rate, * frame rate, and frame size.
* unless the specified format has the sample rate value <code>AudioSystem.NOT_SPECIFIED</code>, * The values of the property are consistent if they are equal
* which any sample rate will match. The frame rates must * or the specified format has the property value
* similarly be equal, unless the specified format has the frame rate * {@code AudioSystem.NOT_SPECIFIED}.
* value <code>AudioSystem.NOT_SPECIFIED</code>. The byte order (big-endian or little-endian) * The byte order (big-endian or little-endian) must be the same
* must match if the sample size is greater than one byte. * if the sample size is greater than one byte.
* *
* @param format format to test for match * @param format format to test for match
* @return <code>true</code> if this format matches the one specified, * @return {@code true} if this format matches the one specified,
* <code>false</code> otherwise. * {@code false} otherwise.
*/
/*
* $$kk: 04.20.99: i changed the semantics of this.
*/ */
public boolean matches(AudioFormat format) { public boolean matches(AudioFormat format) {
if (format.getEncoding().equals(getEncoding())
if (format.getEncoding().equals(getEncoding()) && && (format.getChannels() == AudioSystem.NOT_SPECIFIED
( (format.getSampleRate() == (float)AudioSystem.NOT_SPECIFIED) || (format.getSampleRate() == getSampleRate()) ) && || format.getChannels() == getChannels())
(format.getSampleSizeInBits() == getSampleSizeInBits()) && && (format.getSampleRate() == (float)AudioSystem.NOT_SPECIFIED
(format.getChannels() == getChannels() && || format.getSampleRate() == getSampleRate())
(format.getFrameSize() == getFrameSize()) && && (format.getSampleSizeInBits() == AudioSystem.NOT_SPECIFIED
( (format.getFrameRate() == (float)AudioSystem.NOT_SPECIFIED) || (format.getFrameRate() == getFrameRate()) ) && || format.getSampleSizeInBits() == getSampleSizeInBits())
( (format.getSampleSizeInBits() <= 8) || (format.isBigEndian() == isBigEndian()) ) ) ) && (format.getFrameRate() == (float)AudioSystem.NOT_SPECIFIED
|| format.getFrameRate() == getFrameRate())
&& (format.getFrameSize() == AudioSystem.NOT_SPECIFIED
|| format.getFrameSize() == getFrameSize())
&& (getSampleSizeInBits() <= 8
|| format.isBigEndian() == isBigEndian())) {
return true; return true;
}
return false; return false;
} }
......
/*
* Copyright (c) 2010, 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
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 4937708
* @summary Tests that AudioFormat.matches handle NOT_SPECIFIED value in all fields
* @run main Matches_NOT_SPECIFIED
* @author Alex Menkov
*
*/
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.sampled.AudioSystem;
public class Matches_NOT_SPECIFIED {
static boolean success = true;
static AudioFormat f1;
static AudioFormat f2;
public static void main(String[] args) throws Exception {
AudioFormat f3;
f1 = new AudioFormat(44100, 16, 2, true, false);
f2 = new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED, false);
test(true);
// f1 = new AudioFormat(44100, 8, 16, true, false);
f2 = new AudioFormat(Encoding.PCM_SIGNED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED,
AudioSystem.NOT_SPECIFIED, true);
test(false);
f1 = new AudioFormat(44100, 8, 8, true, false);
test(true);
if (success) {
out("The test PASSED.");
} else {
out("The test FAILED.");
throw new Exception("The test FAILED");
}
}
static void test(boolean shouldMatch) {
out("testing:");
out(" - " + f1.toString());
out(" - " + f2.toString());
if (f1.matches(f2)) {
if (shouldMatch) {
out(" (OK) MATCHES");
} else {
out(" (ERROR) MATCHES");
success = false;
}
} else {
if (shouldMatch) {
out(" (ERROR) DOESNT MATCH!");
success = false;
} else {
out(" (OK) DOESNT MATCH!");
}
}
}
static void out(String s) {
System.out.println(s);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册