当前位置: 首页>>代码示例>>Java>>正文


Java AudioFormat.getSampleSizeInBits方法代码示例

本文整理汇总了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;
}
 
开发者ID:JacobRoth,项目名称:romanov,代码行数:27,代码来源:FloatSampleTools.java

示例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);
	}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:25,代码来源:SoundInputDeviceControl.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:DirectAudioDevice.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:AudioFloatConverter.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:AudioFloatFormatConverter.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:BothEndiansAndSigns.java

示例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;
            }
        }

    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:AuFileFormat.java

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:AuFileWriter.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:WaveFloatFileWriter.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:SoftMixingDataLine.java

示例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())));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:Toolkit.java

示例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());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:AudioFloatFormatConverter.java

示例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);
}
 
开发者ID:EndlessBot,项目名称:jLib,代码行数:5,代码来源:JavaSoundAudioDevice.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:AudioFloatFormatConverter.java


注:本文中的javax.sound.sampled.AudioFormat.getSampleSizeInBits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。