< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/WaveExtensibleFileReader.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 20,78 **** * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.media.sound; - import java.io.BufferedInputStream; - import java.io.File; - import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; - import java.net.URL; import java.util.HashMap; import java.util.Map; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; - import javax.sound.sampled.AudioFormat.Encoding; - import javax.sound.sampled.spi.AudioFileReader; /** * WAVE file reader for files using format WAVE_FORMAT_EXTENSIBLE (0xFFFE). * * @author Karl Helgason */ ! public final class WaveExtensibleFileReader extends AudioFileReader { ! ! static private class GUID { ! long i1; ! ! int s1; ! ! int s2; ! ! int x1; ! ! int x2; ! ! int x3; ! ! int x4; ! ! int x5; ! ! int x6; ! ! int x7; ! ! int x8; private GUID() { } GUID(long i1, int s1, int s2, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) { --- 20,63 ---- * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ + package com.sun.media.sound; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.Map; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; + import javax.sound.sampled.AudioFormat.Encoding; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; /** * WAVE file reader for files using format WAVE_FORMAT_EXTENSIBLE (0xFFFE). * * @author Karl Helgason */ ! public final class WaveExtensibleFileReader extends SunFileReader { + private static class GUID { + private long i1; + private int s1; + private int s2; + private int x1; + private int x2; + private int x3; + private int x4; + private int x5; + private int x6; + private int x7; + private int x8; private GUID() { } GUID(long i1, int s1, int s2, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) {
*** 103,116 **** --- 88,103 ---- d.x7 = riff.readUnsignedByte(); d.x8 = riff.readUnsignedByte(); return d; } + @Override public int hashCode() { return (int) i1; } + @Override public boolean equals(Object obj) { if (!(obj instanceof GUID)) return false; GUID t = (GUID) obj; if (i1 != t.i1)
*** 159,169 **** 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); private static final GUID SUBTYPE_IEEE_FLOAT = new GUID(0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); ! private String decodeChannelMask(long channelmask) { StringBuilder sb = new StringBuilder(); long m = 1; for (int i = 0; i < allchannelnames.length; i++) { if ((channelmask & m) != 0L) { if (i < channelnames.length) { --- 146,156 ---- 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); private static final GUID SUBTYPE_IEEE_FLOAT = new GUID(0x00000003, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71); ! private static String decodeChannelMask(long channelmask) { StringBuilder sb = new StringBuilder(); long m = 1; for (int i = 0; i < allchannelnames.length; i++) { if ((channelmask & m) != 0L) { if (i < channelnames.length) {
*** 178,201 **** return null; return sb.substring(0, sb.length() - 1); } ! public AudioFileFormat getAudioFileFormat(InputStream stream) ! throws UnsupportedAudioFileException, IOException { ! ! stream.mark(200); ! AudioFileFormat format; ! try { ! format = internal_getAudioFileFormat(stream); ! } finally { ! stream.reset(); ! } ! return format; ! } ! ! private AudioFileFormat internal_getAudioFileFormat(InputStream stream) throws UnsupportedAudioFileException, IOException { RIFFReader riffiterator = new RIFFReader(stream); if (!riffiterator.getFormat().equals("RIFF")) throw new UnsupportedAudioFileException(); --- 165,176 ---- return null; return sb.substring(0, sb.length() - 1); } ! @Override ! AudioFileFormat getAudioFileFormatImpl(final InputStream stream) throws UnsupportedAudioFileException, IOException { RIFFReader riffiterator = new RIFFReader(stream); if (!riffiterator.getFormat().equals("RIFF")) throw new UnsupportedAudioFileException();
*** 242,257 **** if (chunk.getFormat().equals("data")) { data_found = true; break; } } ! ! if (!fmt_found) ! throw new UnsupportedAudioFileException(); ! if (!data_found) throw new UnsupportedAudioFileException(); ! Map<String, Object> p = new HashMap<String, Object>(); String s_channelmask = decodeChannelMask(channelMask); if (s_channelmask != null) p.put("channelOrder", s_channelmask); if (channelMask != 0) --- 217,229 ---- if (chunk.getFormat().equals("data")) { data_found = true; break; } } ! if (!fmt_found || !data_found) { throw new UnsupportedAudioFileException(); ! } Map<String, Object> p = new HashMap<String, Object>(); String s_channelmask = decodeChannelMask(channelMask); if (s_channelmask != null) p.put("channelOrder", s_channelmask); if (channelMask != 0)
*** 271,339 **** bits, channels, framesize, samplerate, false, p); } } else if (subFormat.equals(SUBTYPE_IEEE_FLOAT)) { audioformat = new AudioFormat(Encoding.PCM_FLOAT, samplerate, bits, channels, framesize, samplerate, false, p); ! } else throw new UnsupportedAudioFileException(); ! ! AudioFileFormat fileformat = new AudioFileFormat( ! AudioFileFormat.Type.WAVE, audioformat, AudioSystem.NOT_SPECIFIED); - return fileformat; } ! 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(); } - - 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; - } - - public AudioFileFormat getAudioFileFormat(File file) - throws UnsupportedAudioFileException, IOException { - InputStream stream = new FileInputStream(file); - AudioFileFormat format; - try { - format = getAudioFileFormat(new BufferedInputStream(stream)); - } finally { - stream.close(); - } - return format; - } - - public AudioInputStream getAudioInputStream(URL url) - throws UnsupportedAudioFileException, IOException { - return getAudioInputStream(new BufferedInputStream(url.openStream())); - } - - public AudioInputStream getAudioInputStream(File file) - throws UnsupportedAudioFileException, IOException { - return getAudioInputStream(new BufferedInputStream(new FileInputStream( - file))); - } - } --- 243,273 ---- bits, channels, framesize, samplerate, false, p); } } else if (subFormat.equals(SUBTYPE_IEEE_FLOAT)) { audioformat = new AudioFormat(Encoding.PCM_FLOAT, samplerate, bits, channels, framesize, samplerate, false, p); ! } else { throw new UnsupportedAudioFileException(); ! } ! return new AudioFileFormat(AudioFileFormat.Type.WAVE, audioformat, AudioSystem.NOT_SPECIFIED); } ! @Override ! public AudioInputStream getAudioInputStream(final InputStream stream) throws UnsupportedAudioFileException, IOException { AudioFileFormat format = getAudioFileFormat(stream); + // we've got everything, the stream is supported and it is at the + // beginning of the header, so find the data chunk again and return an + // AudioInputStream RIFFReader riffiterator = new RIFFReader(stream); while (riffiterator.hasNextChunk()) { RIFFReader chunk = riffiterator.nextChunk(); if (chunk.getFormat().equals("data")) { return new AudioInputStream(chunk, format.getFormat(), chunk .getSize()); } } throw new UnsupportedAudioFileException(); } }
< prev index next >