javax.sound.sampled.AudioFormat#getFrameSize ( )源码实例Demo

下面列出了javax.sound.sampled.AudioFormat#getFrameSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bytecoder   文件: Toolkit.java
static boolean isFullySpecifiedPCMFormat(AudioFormat format) {
    if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
        && !format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) {
        return false;
    }
    if ((format.getFrameRate() <= 0)
        || (format.getSampleRate() <= 0)
        || (format.getSampleSizeInBits() <= 0)
        || (format.getFrameSize() <= 0)
        || (format.getChannels() <= 0)) {
        return false;
    }
    return true;
}
 
源代码2 项目: jdk8u-jdk   文件: AudioFloatFormatConverter.java
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());
}
 
源代码3 项目: Bytecoder   文件: AuFileWriter.java
private InputStream getFileStream(AuFileFormat auFileFormat, AudioInputStream audioStream) throws IOException {

        // private method ... assumes auFileFormat is a supported file type

        AudioFormat format            = auFileFormat.getFormat();

        int headerSize     = AuFileFormat.AU_HEADERSIZE;
        long dataSize       = auFileFormat.getFrameLength();
        //$$fb fix for Bug 4351296
        //int dataSizeInBytes = dataSize * format.getFrameSize();
        long dataSizeInBytes = (dataSize==AudioSystem.NOT_SPECIFIED)?UNKNOWN_SIZE:dataSize * format.getFrameSize();
        if (dataSizeInBytes>0x7FFFFFFFl) {
            dataSizeInBytes=UNKNOWN_SIZE;
        }
        int auType = auFileFormat.getAuType();
        int sampleRate     = (int)format.getSampleRate();
        int channels       = format.getChannels();

        // if we need to do any format conversion, we do it here.
        //$$ fb 2001-07-13: Bug 4391108
        audioStream = AudioSystem.getAudioInputStream(format, audioStream);

        final byte[] header;
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
             DataOutputStream dos = new DataOutputStream(baos)) {
            dos.writeInt(AuFileFormat.AU_SUN_MAGIC);
            dos.writeInt(headerSize);
            dos.writeInt((int) dataSizeInBytes);
            dos.writeInt(auType);
            dos.writeInt(sampleRate);
            dos.writeInt(channels);
            header = baos.toByteArray();
        }
        // Now create a new InputStream from headerStream and the InputStream
        // in audioStream
        return new SequenceInputStream(new ByteArrayInputStream(header),
                                       new NoCloseInputStream(audioStream));
    }
 
源代码4 项目: TencentKona-8   文件: WaveFloatFileWriter.java
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);
}
 
源代码5 项目: Bytecoder   文件: SoftMixingSourceDataLine.java
@Override
public void open(AudioFormat format) throws LineUnavailableException {
    if (bufferSize == -1)
        bufferSize = ((int) (format.getFrameRate() / 2))
                * format.getFrameSize();
    open(format, bufferSize);
}
 
源代码6 项目: jdk8u_jdk   文件: AudioFloatFormatConverter.java
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());
}
 
源代码7 项目: jdk8u_jdk   文件: AudioFloatInputStream.java
public static AudioFloatInputStream getInputStream(AudioFormat format,
        byte[] buffer, int offset, int len) {
    AudioFloatConverter converter = AudioFloatConverter
            .getConverter(format);
    if (converter != null)
        return new BytaArrayAudioFloatInputStream(converter, buffer,
                offset, len);

    InputStream stream = new ByteArrayInputStream(buffer, offset, len);
    long aLen = format.getFrameSize() == AudioSystem.NOT_SPECIFIED
            ? AudioSystem.NOT_SPECIFIED : len / format.getFrameSize();
    AudioInputStream astream = new AudioInputStream(stream, format, aLen);
    return getInputStream(astream);
}
 
源代码8 项目: jdk8u-jdk   文件: DummySourceDataLine.java
public void open(AudioFormat format, int bufferSize)
        throws LineUnavailableException {
    this.format = format;
    this.bufferSize = bufferSize;
    this.framesize = format.getFrameSize();
    opened = true;
}
 
源代码9 项目: hottub   文件: AudioFloatFormatConverter.java
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;
}
 
源代码10 项目: jdk8u-dev-jdk   文件: AudioFloatFormatConverter.java
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());
}
 
源代码11 项目: dragonwell8_jdk   文件: Toolkit.java
static boolean isFullySpecifiedPCMFormat(AudioFormat format) {
    if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
        && !format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) {
        return false;
    }
    if ((format.getFrameRate() <= 0)
        || (format.getSampleRate() <= 0)
        || (format.getSampleSizeInBits() <= 0)
        || (format.getFrameSize() <= 0)
        || (format.getChannels() <= 0)) {
        return false;
    }
    return true;
}
 
源代码12 项目: openjdk-jdk9   文件: Toolkit.java
static boolean isFullySpecifiedPCMFormat(AudioFormat format) {
    if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)
        && !format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) {
        return false;
    }
    if ((format.getFrameRate() <= 0)
        || (format.getSampleRate() <= 0)
        || (format.getSampleSizeInBits() <= 0)
        || (format.getFrameSize() <= 0)
        || (format.getChannels() <= 0)) {
        return false;
    }
    return true;
}
 
源代码13 项目: TencentKona-8   文件: UlawCodec.java
UlawCodecStream(AudioInputStream stream, AudioFormat outputFormat) {
    super(stream, outputFormat, AudioSystem.NOT_SPECIFIED);

    AudioFormat inputFormat = stream.getFormat();

    // throw an IllegalArgumentException if not ok
    if (!(isConversionSupported(outputFormat, inputFormat))) {
        throw new IllegalArgumentException("Unsupported conversion: " + inputFormat.toString() + " to " + outputFormat.toString());
    }

    //$$fb 2002-07-18: fix for 4714846: JavaSound ULAW (8-bit) encoder erroneously depends on endian-ness
    boolean PCMIsBigEndian;

    // determine whether we are encoding or decoding
    if (AudioFormat.Encoding.ULAW.equals(inputFormat.getEncoding())) {
        encode = false;
        encodeFormat = inputFormat;
        decodeFormat = outputFormat;
        PCMIsBigEndian = outputFormat.isBigEndian();
    } else {
        encode = true;
        encodeFormat = outputFormat;
        decodeFormat = inputFormat;
        PCMIsBigEndian = inputFormat.isBigEndian();
        tempBuffer = new byte[tempBufferSize];
    }

    // setup tables according to byte order
    if (PCMIsBigEndian) {
        tabByte1 = ULAW_TABH;
        tabByte2 = ULAW_TABL;
        highByte = 0;
        lowByte  = 1;
    } else {
        tabByte1 = ULAW_TABL;
        tabByte2 = ULAW_TABH;
        highByte = 1;
        lowByte  = 0;
    }

    // set the AudioInputStream length in frames if we know it
    if (stream instanceof AudioInputStream) {
        frameLength = ((AudioInputStream)stream).getFrameLength();
    }
    // set framePos to zero
    framePos = 0;
    frameSize = inputFormat.getFrameSize();
    if (frameSize == AudioSystem.NOT_SPECIFIED) {
        frameSize = 1;
    }
}
 
源代码14 项目: dragonwell8_jdk   文件: EmergencySoundbank.java
static public byte[] toBytes(float[] in, AudioFormat format) {
    byte[] out = new byte[in.length * format.getFrameSize()];
    return AudioFloatConverter.getConverter(format).toByteArray(in, out);
}
 
源代码15 项目: jdk8u_jdk   文件: SoftMixingClip.java
public void open(AudioFormat format, byte[] data, int offset, int bufferSize)
        throws LineUnavailableException {
    synchronized (control_mutex) {
        if (isOpen()) {
            throw new IllegalStateException(
                    "Clip is already open with format " + getFormat()
                            + " and frame lengh of " + getFrameLength());
        }
        if (AudioFloatConverter.getConverter(format) == null)
            throw new IllegalArgumentException("Invalid format : "
                    + format.toString());
        if (bufferSize % format.getFrameSize() != 0)
            throw new IllegalArgumentException(
                    "Buffer size does not represent an integral number of sample frames!");

        if (data != null) {
            this.data = Arrays.copyOf(data, data.length);
        }
        this.offset = offset;
        this.bufferSize = bufferSize;
        this.format = format;
        this.framesize = format.getFrameSize();

        loopstart = 0;
        loopend = -1;
        loop_sg = true;

        if (!mixer.isOpen()) {
            mixer.open();
            mixer.implicitOpen = true;
        }

        outputformat = mixer.getFormat();
        out_nrofchannels = outputformat.getChannels();
        in_nrofchannels = format.getChannels();

        open = true;

        mixer.getMainMixer().openLine(this);
    }

}
 
源代码16 项目: jdk8u-jdk   文件: Toolkit.java
static long micros2bytes(AudioFormat format, long micros) {
    long result = (long) (micros * format.getFrameRate() / 1000000.0f * format.getFrameSize());
    return align(result, format.getFrameSize());
}
 
源代码17 项目: Bytecoder   文件: WaveFloatFileReader.java
@Override
StandardFileFormat getAudioFileFormatImpl(final InputStream stream)
        throws UnsupportedAudioFileException, IOException {

    RIFFReader riffiterator = new RIFFReader(stream);
    if (!riffiterator.getFormat().equals("RIFF"))
        throw new UnsupportedAudioFileException();
    if (!riffiterator.getType().equals("WAVE"))
        throw new UnsupportedAudioFileException();

    boolean fmt_found = false;
    boolean data_found = false;

    int channels = 1;
    long samplerate = 1;
    int framesize = 1;
    int bits = 1;
    long dataSize = 0;

    while (riffiterator.hasNextChunk()) {
        RIFFReader chunk = riffiterator.nextChunk();
        if (chunk.getFormat().equals("fmt ")) {
            fmt_found = true;

            int format = chunk.readUnsignedShort();
            if (format != WaveFileFormat.WAVE_FORMAT_IEEE_FLOAT) {
                throw new UnsupportedAudioFileException();
            }
            channels = chunk.readUnsignedShort();
            samplerate = chunk.readUnsignedInt();
            /* framerate = */chunk.readUnsignedInt();
            framesize = chunk.readUnsignedShort();
            bits = chunk.readUnsignedShort();
        }
        if (chunk.getFormat().equals("data")) {
            dataSize = chunk.getSize();
            data_found = true;
            break;
        }
    }
    if (!fmt_found || !data_found) {
        throw new UnsupportedAudioFileException();
    }
    AudioFormat audioformat = new AudioFormat(
            Encoding.PCM_FLOAT, samplerate, bits, channels,
            framesize, samplerate, false);
    return new StandardFileFormat(AudioFileFormat.Type.WAVE, audioformat,
                                  dataSize / audioformat.getFrameSize());
}
 
源代码18 项目: jdk8u60   文件: SoftMixingSourceDataLine.java
public void open(AudioFormat format) throws LineUnavailableException {
    if (bufferSize == -1)
        bufferSize = ((int) (format.getFrameRate() / 2))
                * format.getFrameSize();
    open(format, bufferSize);
}
 
源代码19 项目: openjdk-8   文件: Toolkit.java
static long millis2bytes(AudioFormat format, long millis) {
    long result = (long) (millis * format.getFrameRate() / 1000.0f * format.getFrameSize());
    return align(result, format.getFrameSize());
}
 
源代码20 项目: dragonwell8_jdk   文件: DummySourceDataLine.java
public void open(AudioFormat format) throws LineUnavailableException {
    if (bufferSize == -1)
        bufferSize = ((int) (format.getFrameRate() / 2))
                * format.getFrameSize();
    open(format, bufferSize);
}