本文整理匯總了Java中javax.sound.sampled.AudioFormat.Encoding.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java Encoding.toString方法的具體用法?Java Encoding.toString怎麽用?Java Encoding.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.sampled.AudioFormat.Encoding
的用法示例。
在下文中一共展示了Encoding.toString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAudioInputStream
import javax.sound.sampled.AudioFormat.Encoding; //導入方法依賴的package包/類
@Override
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
AudioInputStream sourceStream) {
if (!isConversionSupported(targetEncoding, sourceStream.getFormat())) {
throw new IllegalArgumentException(
"Unsupported conversion: " + sourceStream.getFormat()
.toString() + " to " + targetEncoding.toString());
}
if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
return sourceStream;
AudioFormat format = sourceStream.getFormat();
int channels = format.getChannels();
Encoding encoding = targetEncoding;
float samplerate = format.getSampleRate();
int bits = format.getSampleSizeInBits();
boolean bigendian = format.isBigEndian();
if (targetEncoding.equals(Encoding.PCM_FLOAT))
bits = 32;
AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
channels, channels * bits / 8, samplerate, bigendian);
return getAudioInputStream(targetFormat, sourceStream);
}
示例2: getAudioInputStream
import javax.sound.sampled.AudioFormat.Encoding; //導入方法依賴的package包/類
public AudioInputStream getAudioInputStream(Encoding targetEncoding,
AudioInputStream sourceStream) {
if (!isConversionSupported(targetEncoding, sourceStream.getFormat())) {
throw new IllegalArgumentException(
"Unsupported conversion: " + sourceStream.getFormat()
.toString() + " to " + targetEncoding.toString());
}
if (sourceStream.getFormat().getEncoding().equals(targetEncoding))
return sourceStream;
AudioFormat format = sourceStream.getFormat();
int channels = format.getChannels();
Encoding encoding = targetEncoding;
float samplerate = format.getSampleRate();
int bits = format.getSampleSizeInBits();
boolean bigendian = format.isBigEndian();
if (targetEncoding.equals(Encoding.PCM_FLOAT))
bits = 32;
AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
channels, channels * bits / 8, samplerate, bigendian);
return getAudioInputStream(targetFormat, sourceStream);
}
示例3: convertFormat
import javax.sound.sampled.AudioFormat.Encoding; //導入方法依賴的package包/類
/**
* Convert javax.sound.sampled.AudioFormat to
* javax.media.format.AudioFormat.
*/
public static AudioFormat convertFormat(
javax.sound.sampled.AudioFormat format)
{
Encoding encoding = format.getEncoding();
int channels = format.getChannels();
float frameRate = format.getFrameRate();
int frameSize = format.getFrameSize() < 0 ? format.getFrameSize()
: (format.getFrameSize() * 8);
float sampleRate = format.getSampleRate();
int sampleSize = format.getSampleSizeInBits();
int endian = format.isBigEndian() ? AudioFormat.BIG_ENDIAN
: AudioFormat.LITTLE_ENDIAN;
int signed = Format.NOT_SPECIFIED;
String encodingString = AudioFormat.LINEAR;
if (encoding == Encoding.PCM_SIGNED)
{
signed = AudioFormat.SIGNED;
encodingString = AudioFormat.LINEAR;
} else if (encoding == Encoding.PCM_UNSIGNED)
{
signed = AudioFormat.UNSIGNED;
encodingString = AudioFormat.LINEAR;
} else if (encoding == Encoding.ALAW)
{
encodingString = AudioFormat.ALAW;
} else if (encoding == Encoding.ULAW)
{
encodingString = AudioFormat.ULAW;
} else
{
encodingString = encoding.toString();
}
AudioFormat jmfFormat = new AudioFormat(encodingString, sampleRate,
sampleSize, channels, endian, signed, frameSize, frameRate,
Format.byteArray);
return jmfFormat;
}