类javax.sound.sampled.AudioFileFormat.Type源码实例Demo

下面列出了怎么用javax.sound.sampled.AudioFileFormat.Type的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dragonwell8_jdk   文件: AutoCloseTimeCheck.java
public static void main(final String[] args) throws Exception {
    // Prepare the audio file
    File file = new File("audio.wav");
    try {
        AudioFormat format =
                new AudioFormat(PCM_SIGNED, 44100, 8, 1, 1, 44100, false);
        AudioSystem.write(getStream(format), Type.WAVE, file);
    } catch (final Exception ignored) {
        return; // the test is not applicable
    }
    try {
        testSmallDelay(file);
        testBigDelay(file);
    } finally {
        Files.delete(file.toPath());
    }
}
 
源代码2 项目: TencentKona-8   文件: AutoCloseTimeCheck.java
public static void main(final String[] args) throws Exception {
    // Prepare the audio file
    File file = new File("audio.wav");
    try {
        AudioFormat format =
                new AudioFormat(PCM_SIGNED, 44100, 8, 1, 1, 44100, false);
        AudioSystem.write(getStream(format), Type.WAVE, file);
    } catch (final Exception ignored) {
        return; // the test is not applicable
    }
    try {
        testSmallDelay(file);
        testBigDelay(file);
    } finally {
        Files.delete(file.toPath());
    }
}
 
源代码3 项目: openjdk-jdk8u   文件: AutoCloseTimeCheck.java
public static void main(final String[] args) throws Exception {
    // Prepare the audio file
    File file = new File("audio.wav");
    try {
        AudioFormat format =
                new AudioFormat(PCM_SIGNED, 44100, 8, 1, 1, 44100, false);
        AudioSystem.write(getStream(format), Type.WAVE, file);
    } catch (final Exception ignored) {
        return; // the test is not applicable
    }
    try {
        testSmallDelay(file);
        testBigDelay(file);
    } finally {
        Files.delete(file.toPath());
    }
}
 
源代码4 项目: Bytecoder   文件: WaveFloatFileWriter.java
@Override
public int write(AudioInputStream stream, Type fileType, OutputStream out)
        throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    try (final RIFFWriter writer = new RIFFWriter(
            new NoCloseOutputStream(out), "WAVE")) {
        write(stream, writer);
        return (int) writer.getFilePointer();
    }
}
 
源代码5 项目: Bytecoder   文件: AuFileWriter.java
@Override
public Type[] getAudioFileTypes(AudioInputStream stream) {

    Type[] filetypes = new Type[types.length];
    System.arraycopy(types, 0, filetypes, 0, types.length);

    // make sure we can write this stream
    AudioFormat format = stream.getFormat();
    AudioFormat.Encoding encoding = format.getEncoding();

    if (AudioFormat.Encoding.ALAW.equals(encoding)
            || AudioFormat.Encoding.ULAW.equals(encoding)
            || AudioFormat.Encoding.PCM_SIGNED.equals(encoding)
            || AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding)
            || AudioFormat.Encoding.PCM_FLOAT.equals(encoding)) {
        return filetypes;
    }

    return new Type[0];
}
 
源代码6 项目: Bytecoder   文件: AuFileWriter.java
@Override
public int write(AudioInputStream stream, Type fileType, OutputStream out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    // we must know the total data length to calculate the file length
    //$$fb 2001-07-13: fix for bug 4351296: do not throw an exception
    //if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) {
    //      throw new IOException("stream length not specified");
    //}

    // throws IllegalArgumentException if not supported
    AuFileFormat auFileFormat = (AuFileFormat)getAudioFileFormat(fileType, stream);
    return writeAuFile(stream, auFileFormat, out);
}
 
源代码7 项目: openjdk-jdk9   文件: WaveFloatFileWriter.java
@Override
public int write(AudioInputStream stream, Type fileType, OutputStream out)
        throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(new NoCloseOutputStream(out), "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码8 项目: openjdk-jdk9   文件: WaveFloatFileWriter.java
@Override
public int write(AudioInputStream stream, Type fileType, File out)
        throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(out, "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码9 项目: openjdk-jdk9   文件: AuFileWriter.java
@Override
public Type[] getAudioFileTypes(AudioInputStream stream) {

    Type[] filetypes = new Type[types.length];
    System.arraycopy(types, 0, filetypes, 0, types.length);

    // make sure we can write this stream
    AudioFormat format = stream.getFormat();
    AudioFormat.Encoding encoding = format.getEncoding();

    if (AudioFormat.Encoding.ALAW.equals(encoding)
            || AudioFormat.Encoding.ULAW.equals(encoding)
            || AudioFormat.Encoding.PCM_SIGNED.equals(encoding)
            || AudioFormat.Encoding.PCM_UNSIGNED.equals(encoding)
            || AudioFormat.Encoding.PCM_FLOAT.equals(encoding)) {
        return filetypes;
    }

    return new Type[0];
}
 
源代码10 项目: openjdk-jdk9   文件: AuFileWriter.java
@Override
public int write(AudioInputStream stream, Type fileType, OutputStream out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    // we must know the total data length to calculate the file length
    //$$fb 2001-07-13: fix for bug 4351296: do not throw an exception
    //if( stream.getFrameLength() == AudioSystem.NOT_SPECIFIED ) {
    //      throw new IOException("stream length not specified");
    //}

    // throws IllegalArgumentException if not supported
    AuFileFormat auFileFormat = (AuFileFormat)getAudioFileFormat(fileType, stream);
    return writeAuFile(stream, auFileFormat, out);
}
 
源代码11 项目: dragonwell8_jdk   文件: WaveFloatFileWriter.java
private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) {
    if (!Type.WAVE.equals(type))
        throw new IllegalArgumentException("File type " + type
                + " not supported.");
    if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
        throw new IllegalArgumentException("File format "
                + stream.getFormat() + " not supported.");
}
 
源代码12 项目: dragonwell8_jdk   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, OutputStream out)
        throws IOException {

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(new NoCloseOutputStream(out), "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码13 项目: dragonwell8_jdk   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, File out)
        throws IOException {
    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(out, "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码14 项目: TencentKona-8   文件: WaveFloatFileWriter.java
private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) {
    if (!Type.WAVE.equals(type))
        throw new IllegalArgumentException("File type " + type
                + " not supported.");
    if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
        throw new IllegalArgumentException("File format "
                + stream.getFormat() + " not supported.");
}
 
源代码15 项目: TencentKona-8   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, OutputStream out)
        throws IOException {

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(new NoCloseOutputStream(out), "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码16 项目: jdk8u60   文件: WaveFloatFileWriter.java
private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) {
    if (!Type.WAVE.equals(type))
        throw new IllegalArgumentException("File type " + type
                + " not supported.");
    if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
        throw new IllegalArgumentException("File format "
                + stream.getFormat() + " not supported.");
}
 
源代码17 项目: jdk8u60   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, OutputStream out)
        throws IOException {

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(new NoCloseOutputStream(out), "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码18 项目: jdk8u60   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, File out)
        throws IOException {
    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(out, "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码19 项目: openjdk-jdk8u   文件: WaveFloatFileWriter.java
private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) {
    if (!Type.WAVE.equals(type))
        throw new IllegalArgumentException("File type " + type
                + " not supported.");
    if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
        throw new IllegalArgumentException("File format "
                + stream.getFormat() + " not supported.");
}
 
源代码20 项目: openjdk-jdk8u   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, OutputStream out)
        throws IOException {

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(new NoCloseOutputStream(out), "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码21 项目: openjdk-jdk8u   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, File out)
        throws IOException {
    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(out, "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码22 项目: jdk8u-jdk   文件: WaveFloatFileWriter.java
private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) {
    if (!Type.WAVE.equals(type))
        throw new IllegalArgumentException("File type " + type
                + " not supported.");
    if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
        throw new IllegalArgumentException("File format "
                + stream.getFormat() + " not supported.");
}
 
源代码23 项目: openjdk-jdk8u-backup   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, OutputStream out)
        throws IOException {

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(new NoCloseOutputStream(out), "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码24 项目: openjdk-jdk8u-backup   文件: WaveFloatFileWriter.java
public int write(AudioInputStream stream, Type fileType, File out)
        throws IOException {
    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    RIFFWriter writer = new RIFFWriter(out, "WAVE");
    write(stream, writer);
    int fpointer = (int) writer.getFilePointer();
    writer.close();
    return fpointer;
}
 
源代码25 项目: Bytecoder   文件: WaveFloatFileWriter.java
@Override
public Type[] getAudioFileTypes(AudioInputStream stream) {

    if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
        return new Type[0];
    return new Type[] { Type.WAVE };
}
 
源代码26 项目: Bytecoder   文件: WaveFloatFileWriter.java
private void checkFormat(AudioFileFormat.Type type, AudioInputStream stream) {
    if (!Type.WAVE.equals(type))
        throw new IllegalArgumentException("File type " + type
                + " not supported.");
    if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
        throw new IllegalArgumentException("File format "
                + stream.getFormat() + " not supported.");
}
 
源代码27 项目: Bytecoder   文件: WaveFloatFileWriter.java
@Override
public int write(AudioInputStream stream, Type fileType, File out)
        throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    checkFormat(fileType, stream);
    if (stream.getFormat().isBigEndian())
        stream = toLittleEndian(stream);
    try (final RIFFWriter writer = new RIFFWriter(out, "WAVE")) {
        write(stream, writer);
        return (int) writer.getFilePointer();
    }
}
 
源代码28 项目: Bytecoder   文件: AuFileWriter.java
@Override
public int write(AudioInputStream stream, Type fileType, File out) throws IOException {
    Objects.requireNonNull(stream);
    Objects.requireNonNull(fileType);
    Objects.requireNonNull(out);

    // throws IllegalArgumentException if not supported
    AuFileFormat auFileFormat = (AuFileFormat)getAudioFileFormat(fileType, stream);

    // first write the file without worrying about length fields
    final int bytesWritten;
    try (final FileOutputStream fos = new FileOutputStream(out);
         final BufferedOutputStream bos = new BufferedOutputStream(fos)) {
        bytesWritten = writeAuFile(stream, auFileFormat, bos);
    }

    // now, if length fields were not specified, calculate them,
    // open as a random access file, write the appropriate fields,
    // close again....
    if( auFileFormat.getByteLength()== AudioSystem.NOT_SPECIFIED ) {

        // $$kk: 10.22.99: jan: please either implement this or throw an exception!
        // $$fb: 2001-07-13: done. Fixes Bug 4479981
        try (final RandomAccessFile raf = new RandomAccessFile(out, "rw")) {
            if (raf.length() <= 0x7FFFFFFFl) {
                // skip AU magic and data offset field
                raf.skipBytes(8);
                raf.writeInt(bytesWritten - AuFileFormat.AU_HEADERSIZE);
                // that's all
            }
        }
    }

    return bytesWritten;
}
 
源代码29 项目: Bytecoder   文件: AuFileWriter.java
/**
 * 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());
}
 
源代码30 项目: openjdk-jdk9   文件: WaveFloatFileWriter.java
@Override
public Type[] getAudioFileTypes(AudioInputStream stream) {

    if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
        return new Type[0];
    return new Type[] { Type.WAVE };
}