本文整理匯總了Java中javax.sound.sampled.AudioFormat.getSampleSizeInBits方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioFormat.getSampleSizeInBits方法的具體用法?Java AudioFormat.getSampleSizeInBits怎麽用?Java AudioFormat.getSampleSizeInBits使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.sound.sampled.AudioFormat
的用法示例。
在下文中一共展示了AudioFormat.getSampleSizeInBits方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFormatType
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
/**
* Get the formatType code from the given format.
*
* @throws IllegalArgumentException
*/
static int getFormatType(AudioFormat format) {
boolean signed = format.getEncoding().equals(
AudioFormat.Encoding.PCM_SIGNED);
if (!signed
&& !format.getEncoding().equals(
AudioFormat.Encoding.PCM_UNSIGNED)) {
throw new IllegalArgumentException(
"unsupported encoding: only PCM encoding supported.");
}
if (!signed && format.getSampleSizeInBits() != 8) {
throw new IllegalArgumentException(
"unsupported encoding: only 8-bit can be unsigned");
}
checkSupportedSampleSize(format.getSampleSizeInBits(),
format.getChannels(), format.getFrameSize());
int formatType = getFormatType(format.getSampleSizeInBits(),
format.getFrameSize() / format.getChannels(), signed,
format.isBigEndian());
return formatType;
}
示例2: getAudioFormat
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
private AudioFormat getAudioFormat(HashSet<AudioFormat> inputFormats) {
for (AudioFormat audioFormat : inputFormats) {
if((audioFormat.getSampleSizeInBits() == 16 || audioFormat.getSampleSizeInBits() == 8)
// && (audioFormat.getSampleRate() == 16000.0F)
&& (audioFormat.getChannels() == 1)
&& (audioFormat.isBigEndian())
&& (audioFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED))){
return new AudioFormat(16000.0F, audioFormat.getSampleSizeInBits(), audioFormat.getChannels(), true, true);
}
}
return null;
// float sampleRate = 16000.0F;
// // 8000,11025,16000,22050,44100
// int sampleSizeInBits = 16;
// // 8,16
// int channels = 1;
// // 1,2
// boolean signed = true;
// // true,false
// boolean bigEndian = true;
// // true,false
// return new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian);
}
示例3: getSignOrEndianChangedFormat
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
protected static AudioFormat getSignOrEndianChangedFormat(AudioFormat format) {
boolean isSigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED);
boolean isUnsigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED);
if (format.getSampleSizeInBits() > 8 && isSigned) {
// if this is PCM_SIGNED and 16-bit or higher, then try with endian-ness magic
return new AudioFormat(format.getEncoding(),
format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(),
format.getFrameSize(), format.getFrameRate(), !format.isBigEndian());
}
else if (format.getSampleSizeInBits() == 8 && (isSigned || isUnsigned)) {
// if this is PCM and 8-bit, then try with signed-ness magic
return new AudioFormat(isSigned?AudioFormat.Encoding.PCM_UNSIGNED:AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(), format.getSampleSizeInBits(), format.getChannels(),
format.getFrameSize(), format.getFrameRate(), format.isBigEndian());
}
return null;
}
示例4: AudioFloatLSBFilter
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
AudioFloatLSBFilter(AudioFloatConverter converter, AudioFormat format) {
int bits = format.getSampleSizeInBits();
boolean bigEndian = format.isBigEndian();
this.converter = converter;
stepsize = (bits + 7) / 8;
offset = bigEndian ? (stepsize - 1) : 0;
int lsb_bits = bits % 8;
if (lsb_bits == 0)
mask = (byte) 0x00;
else if (lsb_bits == 1)
mask = (byte) 0x80;
else if (lsb_bits == 2)
mask = (byte) 0xC0;
else if (lsb_bits == 3)
mask = (byte) 0xE0;
else if (lsb_bits == 4)
mask = (byte) 0xF0;
else if (lsb_bits == 5)
mask = (byte) 0xF8;
else if (lsb_bits == 6)
mask = (byte) 0xFC;
else if (lsb_bits == 7)
mask = (byte) 0xFE;
else
mask = (byte) 0xFF;
}
示例5: AudioFloatInputStreamResampler
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
AudioFloatInputStreamResampler(AudioFloatInputStream ais,
AudioFormat format) {
this.ais = ais;
AudioFormat sourceFormat = ais.getFormat();
targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
.getSampleRate(), sourceFormat.getSampleSizeInBits(),
sourceFormat.getChannels(), sourceFormat.getFrameSize(),
format.getSampleRate(), sourceFormat.isBigEndian());
nrofchannels = targetFormat.getChannels();
Object interpolation = format.getProperty("interpolation");
if (interpolation != null && (interpolation instanceof String)) {
String resamplerType = (String) interpolation;
if (resamplerType.equalsIgnoreCase("point"))
this.resampler = new SoftPointResampler();
if (resamplerType.equalsIgnoreCase("linear"))
this.resampler = new SoftLinearResampler2();
if (resamplerType.equalsIgnoreCase("linear1"))
this.resampler = new SoftLinearResampler();
if (resamplerType.equalsIgnoreCase("linear2"))
this.resampler = new SoftLinearResampler2();
if (resamplerType.equalsIgnoreCase("cubic"))
this.resampler = new SoftCubicResampler();
if (resamplerType.equalsIgnoreCase("lanczos"))
this.resampler = new SoftLanczosResampler();
if (resamplerType.equalsIgnoreCase("sinc"))
this.resampler = new SoftSincResampler();
}
if (resampler == null)
resampler = new SoftLinearResampler2(); // new
// SoftLinearResampler2();
pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
pad = resampler.getPadding();
pad2 = pad * 2;
ibuffer = new float[nrofchannels][buffer_len + pad2];
ibuffer2 = new float[nrofchannels * buffer_len];
ibuffer_index = buffer_len + pad;
ibuffer_len = buffer_len;
}
示例6: getOtherEndianOrSign
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public static AudioFormat getOtherEndianOrSign(AudioFormat format) {
AudioFormat.Encoding newEnc = null;
boolean newEndian = format.isBigEndian();
boolean isSigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED);
boolean isUnsigned = format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED);
if ((isSigned || isUnsigned) && format.getSampleSizeInBits() > 0) {
if (format.getSampleSizeInBits() == 8) {
// return the other signed'ness
if (isSigned) {
newEnc = AudioFormat.Encoding.PCM_UNSIGNED;
} else {
newEnc = AudioFormat.Encoding.PCM_SIGNED;
}
} else {
newEnc = format.getEncoding();
newEndian = !newEndian;
}
if (newEnc != null) {
return new AudioFormat(newEnc, format.getSampleRate(),
format.getSampleSizeInBits(),
format.getChannels(),
format.getFrameSize(),
format.getFrameRate(),
newEndian);
}
}
return null;
}
示例7: AuFileFormat
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
AuFileFormat(AudioFileFormat.Type type, int lengthInBytes, AudioFormat format, int lengthInFrames) {
super(type,lengthInBytes,format,lengthInFrames);
AudioFormat.Encoding encoding = format.getEncoding();
auType = -1;
if( AudioFormat.Encoding.ALAW.equals(encoding) ) {
if( format.getSampleSizeInBits()==8 ) {
auType = AU_ALAW_8;
}
} else if( AudioFormat.Encoding.ULAW.equals(encoding) ) {
if( format.getSampleSizeInBits()==8 ) {
auType = AU_ULAW_8;
}
} else if( AudioFormat.Encoding.PCM_SIGNED.equals(encoding) ) {
if( format.getSampleSizeInBits()==8 ) {
auType = AU_LINEAR_8;
} else if( format.getSampleSizeInBits()==16 ) {
auType = AU_LINEAR_16;
} else if( format.getSampleSizeInBits()==24 ) {
auType = AU_LINEAR_24;
} else if( format.getSampleSizeInBits()==32 ) {
auType = AU_LINEAR_32;
}
}
}
示例8: getAudioFileFormat
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
/**
* Returns the AudioFileFormat describing the file that will be written from this AudioInputStream.
* Throws IllegalArgumentException if not supported.
*/
private AudioFileFormat getAudioFileFormat(Type type, AudioInputStream stream) {
if (!isFileTypeSupported(type, stream)) {
throw new IllegalArgumentException("File type " + type + " not supported.");
}
AudioFormat streamFormat = stream.getFormat();
AudioFormat.Encoding encoding = streamFormat.getEncoding();
if (AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding)) {
encoding = AudioFormat.Encoding.PCM_SIGNED;
}
// We always write big endian au files, this is by far the standard
AudioFormat format = new AudioFormat(encoding,
streamFormat.getSampleRate(),
streamFormat.getSampleSizeInBits(),
streamFormat.getChannels(),
streamFormat.getFrameSize(),
streamFormat.getFrameRate(), true);
int fileSize;
if (stream.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
fileSize = (int)stream.getFrameLength()*streamFormat.getFrameSize() + AuFileFormat.AU_HEADERSIZE;
} else {
fileSize = AudioSystem.NOT_SPECIFIED;
}
return new AuFileFormat(Type.AU, fileSize, format,
(int) stream.getFrameLength());
}
示例9: toLittleEndian
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
private AudioInputStream toLittleEndian(AudioInputStream ais) {
AudioFormat format = ais.getFormat();
AudioFormat targetFormat = new AudioFormat(format.getEncoding(), format
.getSampleRate(), format.getSampleSizeInBits(), format
.getChannels(), format.getFrameSize(), format.getFrameRate(),
false);
return AudioSystem.getAudioInputStream(targetFormat, ais);
}
示例10: AudioFloatInputStreamResampler
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public AudioFloatInputStreamResampler(AudioFloatInputStream ais,
AudioFormat format) {
this.ais = ais;
AudioFormat sourceFormat = ais.getFormat();
targetFormat = new AudioFormat(sourceFormat.getEncoding(), format
.getSampleRate(), sourceFormat.getSampleSizeInBits(),
sourceFormat.getChannels(), sourceFormat.getFrameSize(),
format.getSampleRate(), sourceFormat.isBigEndian());
nrofchannels = targetFormat.getChannels();
Object interpolation = format.getProperty("interpolation");
if (interpolation != null && (interpolation instanceof String)) {
String resamplerType = (String) interpolation;
if (resamplerType.equalsIgnoreCase("point"))
this.resampler = new SoftPointResampler();
if (resamplerType.equalsIgnoreCase("linear"))
this.resampler = new SoftLinearResampler2();
if (resamplerType.equalsIgnoreCase("linear1"))
this.resampler = new SoftLinearResampler();
if (resamplerType.equalsIgnoreCase("linear2"))
this.resampler = new SoftLinearResampler2();
if (resamplerType.equalsIgnoreCase("cubic"))
this.resampler = new SoftCubicResampler();
if (resamplerType.equalsIgnoreCase("lanczos"))
this.resampler = new SoftLanczosResampler();
if (resamplerType.equalsIgnoreCase("sinc"))
this.resampler = new SoftSincResampler();
}
if (resampler == null)
resampler = new SoftLinearResampler2(); // new
// SoftLinearResampler2();
pitch[0] = sourceFormat.getSampleRate() / format.getSampleRate();
pad = resampler.getPadding();
pad2 = pad * 2;
ibuffer = new float[nrofchannels][buffer_len + pad2];
ibuffer2 = new float[nrofchannels * buffer_len];
ibuffer_index = buffer_len + pad;
ibuffer_len = buffer_len;
}
示例11: isFullySpecifiedAudioFormat
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
static void isFullySpecifiedAudioFormat(AudioFormat format) {
if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
&& !format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)
&& !format.getEncoding().equals(AudioFormat.Encoding.ULAW)
&& !format.getEncoding().equals(AudioFormat.Encoding.ALAW)) {
// we don't know how to verify possibly non-linear encodings
return;
}
if (format.getFrameRate() <= 0) {
throw new IllegalArgumentException("invalid frame rate: "
+((format.getFrameRate()==-1)?
"NOT_SPECIFIED":String.valueOf(format.getFrameRate())));
}
if (format.getSampleRate() <= 0) {
throw new IllegalArgumentException("invalid sample rate: "
+((format.getSampleRate()==-1)?
"NOT_SPECIFIED":String.valueOf(format.getSampleRate())));
}
if (format.getSampleSizeInBits() <= 0) {
throw new IllegalArgumentException("invalid sample size in bits: "
+((format.getSampleSizeInBits()==-1)?
"NOT_SPECIFIED":String.valueOf(format.getSampleSizeInBits())));
}
if (format.getFrameSize() <= 0) {
throw new IllegalArgumentException("invalid frame size: "
+((format.getFrameSize()==-1)?
"NOT_SPECIFIED":String.valueOf(format.getFrameSize())));
}
if (format.getChannels() <= 0) {
throw new IllegalArgumentException("invalid number of channels: "
+((format.getChannels()==-1)?
"NOT_SPECIFIED":String.valueOf(format.getChannels())));
}
}
示例12: AudioFloatInputStreamChannelMixer
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
AudioFloatInputStreamChannelMixer(AudioFloatInputStream ais,
int targetChannels) {
this.sourceChannels = ais.getFormat().getChannels();
this.targetChannels = targetChannels;
this.ais = ais;
AudioFormat format = ais.getFormat();
targetFormat = new AudioFormat(format.getEncoding(), format
.getSampleRate(), format.getSampleSizeInBits(),
targetChannels, (format.getFrameSize() / sourceChannels)
* targetChannels, format.getFrameRate(), format
.isBigEndian());
}
示例13: millisecondsToBytes
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
public int millisecondsToBytes(AudioFormat fmt, int time)
{
return (int)(time*(fmt.getSampleRate()*fmt.getChannels()*fmt.getSampleSizeInBits())/8000.0);
}
示例14: AudioFloatFormatConverterInputStream
import javax.sound.sampled.AudioFormat; //導入方法依賴的package包/類
AudioFloatFormatConverterInputStream(AudioFormat targetFormat,
AudioFloatInputStream stream) {
this.stream = stream;
converter = AudioFloatConverter.getConverter(targetFormat);
fsize = ((targetFormat.getSampleSizeInBits() + 7) / 8);
}