Search in sources :

Example 26 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class WaveFileReader method getAudioFileFormat.

/**
     * Obtains the audio file format of the File provided.  The File must
     * point to valid audio file data.
     * @param file the File from which file format information should be
     * extracted
     * @return an <code>AudioFileFormat</code> object describing the audio file format
     * @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 AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException {
    AudioFileFormat fileFormat = null;
    // throws IOException
    FileInputStream fis = new FileInputStream(file);
    // part of fix for 4325421
    try {
        fileFormat = getFMT(fis, false);
    } finally {
        fis.close();
    }
    return fileFormat;
}
Also used : AudioFileFormat(javax.sound.sampled.AudioFileFormat) FileInputStream(java.io.FileInputStream)

Example 27 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class WaveFileReader method getAudioFileFormat.

/**
     * Obtains the audio file format of the URL provided.  The URL must
     * point to valid audio file data.
     * @param url the URL from which file format information should be
     * extracted
     * @return an <code>AudioFileFormat</code> object describing the audio file format
     * @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 AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException {
    // throws IOException
    InputStream urlStream = url.openStream();
    AudioFileFormat fileFormat = null;
    try {
        fileFormat = getFMT(urlStream, false);
    } finally {
        urlStream.close();
    }
    return fileFormat;
}
Also used : DataInputStream(java.io.DataInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 28 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class WaveFileReader method getAudioFileFormat.

/**
     * Obtains the audio file format of 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 file format information should be
     * extracted
     * @return an <code>AudioFileFormat</code> object describing the audio file format
     * @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 AudioFileFormat getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException {
    // fix for 4489272: AudioSystem.getAudioFileFormat() fails for InputStream, but works for URL
    AudioFileFormat aff = getFMT(stream, true);
    // the following is not strictly necessary - but was implemented like that in 1.3.0 - 1.4.1
    // so I leave it as it was. May remove this for 1.5.0
    stream.reset();
    return aff;
}
Also used : AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 29 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class WaveFloatFileReader method internal_getAudioFileFormat.

private AudioFileFormat internal_getAudioFileFormat(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;
    while (riffiterator.hasNextChunk()) {
        RIFFReader chunk = riffiterator.nextChunk();
        if (chunk.getFormat().equals("fmt ")) {
            fmt_found = true;
            int format = chunk.readUnsignedShort();
            if (// WAVE_FORMAT_IEEE_FLOAT only
            format != 3)
                throw new UnsupportedAudioFileException();
            channels = chunk.readUnsignedShort();
            samplerate = chunk.readUnsignedInt();
            /* framerate = */
            chunk.readUnsignedInt();
            framesize = chunk.readUnsignedShort();
            bits = chunk.readUnsignedShort();
        }
        if (chunk.getFormat().equals("data")) {
            data_found = true;
            break;
        }
    }
    if (!fmt_found)
        throw new UnsupportedAudioFileException();
    if (!data_found)
        throw new UnsupportedAudioFileException();
    AudioFormat audioformat = new AudioFormat(Encoding.PCM_FLOAT, samplerate, bits, channels, framesize, samplerate, false);
    AudioFileFormat fileformat = new AudioFileFormat(AudioFileFormat.Type.WAVE, audioformat, AudioSystem.NOT_SPECIFIED);
    return fileformat;
}
Also used : UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) AudioFormat(javax.sound.sampled.AudioFormat) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Example 30 with AudioFileFormat

use of javax.sound.sampled.AudioFileFormat in project jdk8u_jdk by JetBrains.

the class WaveFloatFileReader method getAudioFileFormat.

public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException {
    InputStream stream = url.openStream();
    AudioFileFormat format;
    try {
        format = getAudioFileFormat(new BufferedInputStream(stream));
    } finally {
        stream.close();
    }
    return format;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) AudioInputStream(javax.sound.sampled.AudioInputStream) InputStream(java.io.InputStream) AudioFileFormat(javax.sound.sampled.AudioFileFormat)

Aggregations

AudioFileFormat (javax.sound.sampled.AudioFileFormat)32 AudioInputStream (javax.sound.sampled.AudioInputStream)20 FileInputStream (java.io.FileInputStream)18 InputStream (java.io.InputStream)13 BufferedInputStream (java.io.BufferedInputStream)11 AudioFormat (javax.sound.sampled.AudioFormat)10 DataInputStream (java.io.DataInputStream)9 UnsupportedAudioFileException (javax.sound.sampled.UnsupportedAudioFileException)8 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 PushbackInputStream (java.io.PushbackInputStream)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Type (javax.sound.sampled.AudioFileFormat.Type)1 LineUnavailableException (javax.sound.sampled.LineUnavailableException)1 Mixer (javax.sound.sampled.Mixer)1