當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioFileFormat.getFormat方法代碼示例

本文整理匯總了Java中javax.sound.sampled.AudioFileFormat.getFormat方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioFileFormat.getFormat方法的具體用法?Java AudioFileFormat.getFormat怎麽用?Java AudioFileFormat.getFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.sound.sampled.AudioFileFormat的用法示例。


在下文中一共展示了AudioFileFormat.getFormat方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAudioInputStream

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
public AudioInputStream getAudioInputStream(InputStream stream)
        throws UnsupportedAudioFileException, IOException {

    AudioFileFormat format = getAudioFileFormat(stream);
    RIFFReader riffiterator = new RIFFReader(stream);
    if (!riffiterator.getFormat().equals("RIFF"))
        throw new UnsupportedAudioFileException();
    if (!riffiterator.getType().equals("WAVE"))
        throw new UnsupportedAudioFileException();
    while (riffiterator.hasNextChunk()) {
        RIFFReader chunk = riffiterator.nextChunk();
        if (chunk.getFormat().equals("data")) {
            return new AudioInputStream(chunk, format.getFormat(), chunk
                    .getSize());
        }
    }
    throw new UnsupportedAudioFileException();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:19,代碼來源:WaveExtensibleFileReader.java

示例2: getAudioInputStream

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
public AudioInputStream getAudioInputStream(InputStream stream)
        throws UnsupportedAudioFileException, IOException {

    AudioFileFormat format = getAudioFileFormat(stream);
    RIFFReader riffiterator = new RIFFReader(stream);
    if (!riffiterator.getFormat().equals("RIFF"))
        throw new UnsupportedAudioFileException();
    if (!riffiterator.getType().equals("WAVE"))
        throw new UnsupportedAudioFileException();
    while (riffiterator.hasNextChunk()) {
        RIFFReader chunk = riffiterator.nextChunk();
        if (chunk.getFormat().equals("data")) {
            return new AudioInputStream(chunk, format.getFormat(),
                    chunk.getSize());
        }
    }
    throw new UnsupportedAudioFileException();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:WaveFloatFileReader.java

示例3: getAudioInputStream

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
/**
 * Obtains an audio stream from the File provided.  The File must
 * point to valid audio file data.
 * @param file the File for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the File
 * @throws UnsupportedAudioFileException if the File does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public AudioInputStream getAudioInputStream(File file)
    throws UnsupportedAudioFileException, IOException {

    FileInputStream fis = new FileInputStream(file); // throws IOException
    AudioFileFormat fileFormat = null;
    // part of fix for 4325421
    try {
        fileFormat = getCOMM(fis, false);
    } finally {
        if (fileFormat == null) {
            fis.close();
        }
    }
    return new AudioInputStream(fis, fileFormat.getFormat(), fileFormat.getFrameLength());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:27,代碼來源:AiffFileReader.java

示例4: getAudioInputStream

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
/**
 * Obtains an audio stream from the URL provided.  The URL must
 * point to valid audio file data.
 * @param url the URL for which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data pointed
 * to by the URL
 * @throws UnsupportedAudioFileException if the URL does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 */
public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException {
    InputStream urlStream = url.openStream();  // throws IOException
    AudioFileFormat fileFormat = null;
    try {
        fileFormat = getFMT(urlStream, false);
    } finally {
        if (fileFormat == null) {
            urlStream.close();
        }
    }
    return new AudioInputStream(urlStream, fileFormat.getFormat(), fileFormat.getFrameLength());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:24,代碼來源:WaveFileReader.java

示例5: testAFF

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
/**
 * Tests the {@code AudioFileFormat} fetched from the fake header.
 * <p>
 * Note that the frameLength and byteLength are stored as int which means
 * that {@code AudioFileFormat} will store the data above {@code MAX_INT} as
 * NOT_SPECIFIED.
 */
private static void testAFF(final byte[] type, final int rate,
                            final int channel, final long size)
        throws Exception {
    final byte[] header = createHeader(type, rate, channel, size);
    final ByteArrayInputStream fake = new ByteArrayInputStream(header);
    final AudioFileFormat aff = AudioSystem.getAudioFileFormat(fake);
    final AudioFormat format = aff.getFormat();

    if (aff.getType() != AudioFileFormat.Type.WAVE) {
        throw new RuntimeException("Error");
    }

    final long frameLength = size / format.getFrameSize();
    if (frameLength <= Integer.MAX_VALUE) {
        if (aff.getFrameLength() != frameLength) {
            System.err.println("Expected: " + frameLength);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    } else {
        if (aff.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
            System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    }
    validateFormat(type[1], rate, channel, aff.getFormat());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:RecognizeHugeWaveFiles.java

示例6: testAFF

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
/**
 * Tests the {@code AudioFileFormat} fetched from the fake header.
 * <p>
 * Note that the frameLength and byteLength are stored as int which means
 * that {@code AudioFileFormat} will store the data above {@code MAX_INT} as
 * NOT_SPECIFIED.
 */
private static void testAFF(final int[] type, final int rate,
                            final int channel, final long size)
        throws Exception {
    final byte[] header = createHeader(type, rate, channel, size);
    final ByteArrayInputStream fake = new ByteArrayInputStream(header);
    final AudioFileFormat aff = AudioSystem.getAudioFileFormat(fake);
    final AudioFormat format = aff.getFormat();

    if (aff.getType() != AudioFileFormat.Type.WAVE) {
        throw new RuntimeException("Error");
    }

    final long frameLength = size / format.getFrameSize();
    if (frameLength <= Integer.MAX_VALUE) {
        if (aff.getFrameLength() != frameLength) {
            System.err.println("Expected: " + frameLength);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    } else {
        if (aff.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
            System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    }
    validateFormat(type[1], rate, channel, aff.getFormat());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:RecognizeHugeWaveExtFiles.java

示例7: testAFF

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
/**
 * Tests the {@code AudioFileFormat} fetched from the fake header.
 * <p>
 * Note that the frameLength and byteLength are stored as int which means
 * that {@code AudioFileFormat} will store the data above {@code  MAX_INT}
 * as NOT_SPECIFIED.
 */
private static void testAFF(final byte[] type, final int rate,
                            final int channel, final long size)
        throws Exception {
    final byte[] header = createHeader(type, rate, channel, size);
    final ByteArrayInputStream fake = new ByteArrayInputStream(header);
    final AudioFileFormat aff = AudioSystem.getAudioFileFormat(fake);
    final AudioFormat format = aff.getFormat();

    if (aff.getType() != AudioFileFormat.Type.AU) {
        throw new RuntimeException("Error");
    }

    final long frameLength = size / format.getFrameSize();
    if (size != MAX_UNSIGNED_INT && frameLength <= Integer.MAX_VALUE) {
        if (aff.getFrameLength() != frameLength) {
            System.err.println("Expected: " + frameLength);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    } else {
        if (aff.getFrameLength() != AudioSystem.NOT_SPECIFIED) {
            System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED);
            System.err.println("Actual: " + aff.getFrameLength());
            throw new RuntimeException();
        }
    }

    final long byteLength = size + AU_HEADER;
    if (byteLength <= Integer.MAX_VALUE) {
        if (aff.getByteLength() != byteLength) {
            System.err.println("Expected: " + byteLength);
            System.err.println("Actual: " + aff.getByteLength());
            throw new RuntimeException();
        }
    } else {
        if (aff.getByteLength() != AudioSystem.NOT_SPECIFIED) {
            System.err.println("Expected: " + AudioSystem.NOT_SPECIFIED);
            System.err.println("Actual: " + aff.getByteLength());
            throw new RuntimeException();
        }
    }
    validateFormat(type[1], rate, channel, aff.getFormat());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:51,代碼來源:RecognizeHugeAuFiles.java

示例8: getAIS

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
private static AudioInputStream getAIS(final Type type, Encoding encoding) {
    AudioFormat af = new AudioFormat(encoding, 44100.0f, 16, 2, 1, 1, true);
    AudioFileFormat aif = new AudioFileFormat(type, af, 0);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[1024]);
    return new AudioInputStream(bais, aif.getFormat(), 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:7,代碼來源:ExpectedNPEOnNull.java

示例9: AiffFileFormat

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
AiffFileFormat( AudioFileFormat aff ) {
    this( aff.getType(), aff.getByteLength(), aff.getFormat(), aff.getFrameLength() );
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:4,代碼來源:AiffFileFormat.java

示例10: getAudioInputStream

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
/**
 * Obtains an audio stream from the input stream provided.  The stream must
 * point to valid audio file data.  In general, audio file providers may
 * need to read some data from the stream before determining whether they
 * support it.  These parsers must
 * be able to mark the stream, read enough data to determine whether they
 * support the stream, and, if not, reset the stream's read pointer to its original
 * position.  If the input stream does not support this, this method may fail
 * with an IOException.
 * @param stream the input stream from which the <code>AudioInputStream</code> should be
 * constructed
 * @return an <code>AudioInputStream</code> object based on the audio file data contained
 * in the input stream.
 * @throws UnsupportedAudioFileException if the stream does not point to valid audio
 * file data recognized by the system
 * @throws IOException if an I/O exception occurs
 * @see InputStream#markSupported
 * @see InputStream#mark
 */
public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException {
    // getCOMM leaves the input stream at the beginning of the audio data
    AudioFileFormat fileFormat = getCOMM(stream, true);     // throws UnsupportedAudioFileException, IOException

    // we've got everything, and the stream is at the
    // beginning of the audio data, so return an AudioInputStream.
    return new AudioInputStream(stream, fileFormat.getFormat(), fileFormat.getFrameLength());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:AiffFileReader.java

示例11: WaveFileFormat

import javax.sound.sampled.AudioFileFormat; //導入方法依賴的package包/類
WaveFileFormat( AudioFileFormat aff ) {

        this( aff.getType(), aff.getByteLength(), aff.getFormat(), aff.getFrameLength() );
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:5,代碼來源:WaveFileFormat.java


注:本文中的javax.sound.sampled.AudioFileFormat.getFormat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。