本文整理匯總了Java中javax.sound.sampled.AudioFormat.Encoding.ALAW屬性的典型用法代碼示例。如果您正苦於以下問題:Java Encoding.ALAW屬性的具體用法?Java Encoding.ALAW怎麽用?Java Encoding.ALAW使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類javax.sound.sampled.AudioFormat.Encoding
的用法示例。
在下文中一共展示了Encoding.ALAW屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSourceEncodings
@Override
public AudioFormat.Encoding[] getSourceEncodings() {
return new Encoding[]{Encoding.ALAW, Encoding.PCM_SIGNED};
}
示例2: isFormatValid
private boolean isFormatValid(AudioFormat format) {
final int sampleSizeBits = format.getSampleSizeInBits();
final int numChannels = format.getChannels();
if(numChannels != 2)
return false;
if(sampleSizeBits != 8 && sampleSizeBits != 16 && sampleSizeBits != 32)
return false;
//if(format.getFrameRate() <= 0)
//return false;
final Encoding encoding = format.getEncoding();
if(encoding == Encoding.ALAW || encoding == Encoding.ULAW)
return false;
return true;
}
示例3: convertFormat
/**
* 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;
}
示例4: createAuHeader
/**
* Used to create a "fake" AU header for fakeHeader. See
* http://en.wikipedia.org/wiki/Au_file_format. The Au file format is a
* simple audio file format that consists of a header of 6 32-bit words and
* then the data (high-order byte comes first). The format was introduced by
* Sun Microsystems.
*/
public static byte[] createAuHeader(javax.sound.sampled.AudioFormat f)
{
byte[] result = new byte[4 * 6];
encodeIntBE(0x2e736e64, result, 0); // the value 0x2e736e64 (four ASCII
// characters ".snd")
encodeIntBE(result.length, result, 4); // the offset to the data in
// bytes. The minimum valid
// number is 24 (decimal).
encodeIntBE(0xffffffff, result, 8); // data size in bytes. If unknown,
// the value 0xffffffff should be
// used.
// Data encoding format:
// 1=8-bit ISDN u-law, 2=8-bit linear PCM [REF-PCM], 3=16-bit linear
// PCM, 4=24-bit linear PCM,
// 5=32-bit linear PCM, 6=32-bit IEEE floating point, 7=64-bit IEEE
// floating point,
// 23=8-bit ISDN u-law compressed using the UIT-T G.721 ADPCM voice data
// encoding scheme.
final int encoding;
if (f.getEncoding() == Encoding.ALAW)
{
if (f.getSampleSizeInBits() == 8)
encoding = 27;
else
return null;
} else if (f.getEncoding() == Encoding.ULAW)
{
if (f.getSampleSizeInBits() == 8)
encoding = 1;
else
return null;
} else if (f.getEncoding() == Encoding.PCM_SIGNED)
{
// AU appears to be signed when it uses PCM
if (f.getSampleSizeInBits() == 8)
encoding = 2;
else if (f.getSampleSizeInBits() == 16)
encoding = 3;
else if (f.getSampleSizeInBits() == 24)
encoding = 4;
else if (f.getSampleSizeInBits() == 32)
encoding = 5;
else
return null;
if (f.getSampleSizeInBits() > 8 && !f.isBigEndian())
return null; // must be big-endian
} else if (f.getEncoding() == Encoding.PCM_UNSIGNED)
{
// AU appears to be signed when it uses PCM
return null;
} else
{
return null;
}
encodeIntBE(encoding, result, 12);
// sample rate - the number of samples/second (e.g., 8000)
if (f.getSampleRate() < 0)
return null;
encodeIntBE((int) f.getSampleRate(), result, 16);
// channels the number of interleaved channels (e.g., 1 for mono, 2 for
// stereo)
if (f.getChannels() < 0)
return null;
encodeIntBE(f.getChannels(), result, 20);
return result;
}