Package javax.sound.sampled

Examples of javax.sound.sampled.AudioFileFormat


        String[] testPropsAFF = {"duration", "title", "author", "album", "date", "comment",
            "copyright", "ogg.bitrate.min", "ogg.bitrate.nominal", "ogg.bitrate.max"};
        String[] testPropsAF = {"vbr", "bitrate"};
        try {
            URL url = new URL(fileurl);
            AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(url);
            AudioFormat baseFormat = baseFileFormat.getFormat();
            System.out.println("-> URL : " + fileurl + " <-");
            System.out.println(baseFileFormat);
            if (baseFileFormat instanceof TAudioFileFormat) {
                Map properties = ((TAudioFileFormat) baseFileFormat).properties();
                System.out.println(properties);
View Full Code Here


     */
    private void _testGetAudioFileFormatFile(String filename) {
        System.out.println("*** testGetAudioFileFormatFile ***");
        try {
            File file = new File(filename);
            AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(file);
            dumpAudioFileFormat(baseFileFormat, file.toString());
            // TODO : Add assert();
        } catch (UnsupportedAudioFileException | IOException e) {
            // TODO e.printStackTrace();
        }
View Full Code Here

     */
    private void _testGetAudioFileFormatURL(String fileurl) {
        System.out.println("*** testGetAudioFileFormatURL ***");
        try {
            URL url = new URL(fileurl);
            AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(url);
            dumpAudioFileFormat(baseFileFormat, url.toString());
            // TODO : Add assert();
        } catch (UnsupportedAudioFileException | IOException e) {
            // TODO e.printStackTrace();
        }
View Full Code Here

     * Test for AudioFileFormat getAudioFileFormat(InputStream)
     */
    private void _testGetAudioFileFormatInputStream(String filename) {
        System.out.println("*** testGetAudioFileFormatInputStream ***");
        try (InputStream in = new BufferedInputStream(new FileInputStream(filename))) {
            AudioFileFormat baseFileFormat = AudioSystem.getAudioFileFormat(in);
            dumpAudioFileFormat(baseFileFormat, in.toString());
        } catch (UnsupportedAudioFileException | IOException e) {
            // TODO e.printStackTrace();
        }
    }
View Full Code Here

    public void testPlayFile() {
        try {
            System.out.println("Start : " + filename);
            File file = new File(filename);

            AudioFileFormat aff = AudioSystem.getAudioFileFormat(file);
            System.out.println(" Audio Type : " + aff.getType());

            AudioInputStream in = AudioSystem.getAudioInputStream(file);
            if (in != null) {
                AudioFormat baseFormat = in.getFormat();
                System.out.println(" Source Format : " + baseFormat.toString());
View Full Code Here

    public void testPlayURL() {
        try {
            System.out.println("Start : " + fileurl);
            URL url = new URL(fileurl);

            AudioFileFormat aff = AudioSystem.getAudioFileFormat(url);
            System.out.println(" Audio Type : " + aff.getType());

            AudioInputStream in = AudioSystem.getAudioInputStream(url);
            if (in != null) {
                AudioFormat baseFormat = in.getFormat();
                System.out.println(" Source Format : " + baseFormat.toString());
View Full Code Here

    private static void dumpStreamChunk(File file, String dstPath,
                                        long offset, long length)
        throws UnsupportedAudioFileException, IOException
    {
        AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(file);
        AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);
        AudioFormat audioFormat = fileFormat.getFormat();
        int bitrate = Math.round(audioFormat.getFrameSize() *
                audioFormat.getFrameRate() / 1000);

        inputStream.skip(offset * bitrate);
        AudioInputStream chunkStream =
            new AudioInputStream(inputStream, audioFormat, length * bitrate);
        AudioSystem.write(chunkStream, fileFormat.getType(), new File(dstPath));
        inputStream.close();
        chunkStream.close();
    }
View Full Code Here

         }
         else
         if (filename!=null)
         {  File file=new File(filename);
            if (filename.indexOf(".wav")>0)
            {  AudioFileFormat format=AudioSystem.getAudioFileFormat(file);
               System.out.println("File audio format: "+format);
               AudioInputStream audio_input_stream=AudioSystem.getAudioInputStream(file);
               sender=new RtpStreamSender(audio_input_stream,true,payload_type,frame_rate,frame_size,daddr,dport);
            }
            else
View Full Code Here

         else
         if (dir>=0 && audiofile_in!=null)
         {  printLog("new audio sender to "+remote_addr+":"+remote_port,LogLevel.MEDIUM);
            File file=new File(audiofile_in);
            if (audiofile_in.indexOf(".wav")>0)
            {  AudioFileFormat format=AudioSystem.getAudioFileFormat(file);
               printLog("File audio format: "+format);
               AudioInputStream input_stream=AudioSystem.getAudioInputStream(file);
               sender=new RtpStreamSender(input_stream,true,payload_type,frame_rate,frame_size,socket,remote_addr,remote_port);
            }
            else
View Full Code Here

        // AudioSystem expects the stream to support the mark feature
        if (!stream.markSupported()) {
            stream = new BufferedInputStream(stream);
        }
        try {
            AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(stream);
            Type type = fileFormat.getType();
            if (type == Type.AIFC || type == Type.AIFF) {
                metadata.set(Metadata.CONTENT_TYPE, "audio/x-aiff");
            } else if (type == Type.AU || type == Type.SND) {
                metadata.set(Metadata.CONTENT_TYPE, "audio/basic");
            } else if (type == Type.WAVE) {
                metadata.set(Metadata.CONTENT_TYPE, "audio/x-wav");
            }

            AudioFormat audioFormat = fileFormat.getFormat();
            int channels = audioFormat.getChannels();
            if (channels != AudioSystem.NOT_SPECIFIED) {
                metadata.set("channels", String.valueOf(channels));
                // TODO: Use XMPDM.TRACKS? (see also frame rate in AudioFormat)
            }
            float rate = audioFormat.getSampleRate();
            if (rate != AudioSystem.NOT_SPECIFIED) {
                metadata.set("samplerate", String.valueOf(rate));
                metadata.set(
                        XMPDM.AUDIO_SAMPLE_RATE,
                        Integer.toString((int) rate));
            }
            int bits = audioFormat.getSampleSizeInBits();
            if (bits != AudioSystem.NOT_SPECIFIED) {
                metadata.set("bits", String.valueOf(bits));
                if (bits == 8) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "8Int");
                } else if (bits == 16) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "16Int");
                } else if (bits == 32) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "32Int");
                }
            }
            metadata.set("encoding", audioFormat.getEncoding().toString());

            // Javadoc suggests that some of the following properties might
            // be available, but I had no success in finding any:

            // "duration" Long playback duration of the file in microseconds
            // "author" String name of the author of this file
            // "title" String title of this file
            // "copyright" String copyright message
            // "date" Date date of the recording or release
            // "comment" String an arbitrary text

            addMetadata(metadata, fileFormat.properties());
            addMetadata(metadata, audioFormat.properties());
        } catch (UnsupportedAudioFileException e) {
            // There is no way to know whether this exception was
            // caused by the document being corrupted or by the format
            // just being unsupported. So we do nothing.
View Full Code Here

TOP

Related Classes of javax.sound.sampled.AudioFileFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.