This patch allows some more workflow to be used when writing sound applications. This is also somewhat useful when writing audio files (under way, but not yet possible, sorry!)
This also removes some unused stuff from GStreamerMixer. Mario 2007-08-19 Mario Torre <[EMAIL PROTECTED]> * gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java: (getAudioFileFormat (File)): method implemented. (getAudioFileFormat (InputStream)): likewise. (getAudioFileFormat(InputStream, String)): new method. (getAudioInputStream): better exception handling. * gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java (getAudioFormat): added basic extension detection for known files. * gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java: -- Lima Software - http://www.limasoftware.net/ GNU Classpath Developer - http://www.classpath.org/ Fedora Ambassador - http://fedoraproject.org/wiki/MarioTorre Jabber: [EMAIL PROTECTED] pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF Fingerprint: BA39 9666 94EC 8B73 27FA FC7C 4086 63E3 80F2 40CF Please, support open standards: http://opendocumentfellowship.org/petition/ http://www.nosoftwarepatents.com/
### Eclipse Workspace Patch 1.0 #P classpath Index: gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java =================================================================== RCS file: /sources/classpath/classpath/gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java,v retrieving revision 1.2 diff -u -r1.2 GStreamerMixer.java --- gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java 18 Aug 2007 15:23:13 -0000 1.2 +++ gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java 19 Aug 2007 18:57:39 -0000 @@ -79,28 +79,11 @@ super(name, vendor, desc, vers); } } - + public static final String GST_BACKEND = GstInfo.name; public static final String GST_DECODER = "decoder"; - - private static AudioFormat[] BASIC_FORMATS = - { - new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED, - AudioSystem.NOT_SPECIFIED, - AudioSystem.NOT_SPECIFIED, - AudioSystem.NOT_SPECIFIED, - AudioSystem.NOT_SPECIFIED, - AudioSystem.NOT_SPECIFIED, - true), - - new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED, - AudioSystem.NOT_SPECIFIED, - AudioSystem.NOT_SPECIFIED, - AudioSystem.NOT_SPECIFIED, - AudioSystem.NOT_SPECIFIED, - AudioSystem.NOT_SPECIFIED, - false), - }; + public static final String GST_TYPE_NAME = "type"; + public static final String GST_FILE_EXTENSION = "ext"; /** Mixer Info */ private static final Mixer.Info INFO = new GStreamerMixer.GstInfo(); Index: gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java =================================================================== RCS file: /sources/classpath/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java,v retrieving revision 1.2 diff -u -r1.2 GstAudioFileReader.java --- gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java 18 Aug 2007 15:23:15 -0000 1.2 +++ gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java 19 Aug 2007 18:57:39 -0000 @@ -37,12 +37,15 @@ package gnu.javax.sound.sampled.gstreamer.io; +import gnu.javax.sound.sampled.gstreamer.GStreamerMixer; + 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.Map; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; @@ -64,16 +67,56 @@ public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException { - throw new UnsupportedAudioFileException("Unsupported encoding."); + StringBuffer name = new StringBuffer(file.getName()); + String _name = name.substring(name.lastIndexOf(".") + 1); + + return getAudioFileFormat( + new BufferedInputStream(new FileInputStream(file)), _name); } @Override public AudioFileFormat getAudioFileFormat(InputStream is) throws UnsupportedAudioFileException, IOException { - throw new UnsupportedAudioFileException("Unsupported encoding."); + return getAudioFileFormat(is, null); } + private AudioFileFormat getAudioFileFormat(InputStream is, String extension) + throws UnsupportedAudioFileException + { + AudioFormat format = null; + try + { + format = GstAudioFileReaderNativePeer.getAudioFormat(is); + } + catch (Exception e) + { + UnsupportedAudioFileException ex = + new UnsupportedAudioFileException("Unsupported encoding."); + + ex.initCause(ex.getCause()); + throw ex; + } + + if (format == null) + throw new UnsupportedAudioFileException("Unsupported encoding."); + + String name = format.getProperty(GStreamerMixer.GST_DECODER).toString(); + + if (extension == null) + { + extension = + format.getProperty(GStreamerMixer.GST_FILE_EXTENSION).toString(); + } + + AudioFileFormat.Type type = + new AudioFileFormat.Type(name, extension); + + // TODO: we should calculate this in some way. We don't need it, but + // application may want to use this data. + return new AudioFileFormat(type, format, AudioSystem.NOT_SPECIFIED); + } + @Override public AudioFileFormat getAudioFileFormat(URL url) throws UnsupportedAudioFileException, IOException @@ -96,8 +139,11 @@ } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + UnsupportedAudioFileException ex = + new UnsupportedAudioFileException("Unsupported encoding."); + + ex.initCause(ex.getCause()); + throw ex; } // get the header size Index: gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java =================================================================== RCS file: /sources/classpath/classpath/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java,v retrieving revision 1.2 diff -u -r1.2 GstAudioFileReaderNativePeer.java --- gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java 18 Aug 2007 15:23:15 -0000 1.2 +++ gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java 19 Aug 2007 18:57:39 -0000 @@ -200,6 +200,8 @@ bigEndian = true; } + String ext = null; + int frameSize = na; float frameRate = na; String lowerCase = header.name.toLowerCase(); @@ -210,16 +212,19 @@ { frameSize = (sampleSizeInBits >> 3) * channels; frameRate = sampleRate; + ext = "au"; } else if (lowerCase.contains("wav")) { frameSize = ((sampleSizeInBits + 7) / 8) * channels; frameRate = sampleRate; + ext = "wav"; } else if (lowerCase.contains("iff")) { frameSize = (sampleSizeInBits * channels) / 8; frameRate = sampleRate; + ext = "aiff"; } // write all the additional properties we got to identify @@ -227,6 +232,9 @@ Map<String, Object> properties = new HashMap<String, Object>(); properties.put(GStreamerMixer.GST_BACKEND, true); properties.put(GStreamerMixer.GST_DECODER, header.name); + properties.put(GStreamerMixer.GST_TYPE_NAME, encoding.toString()); + if (ext != null) + properties.put(GStreamerMixer.GST_FILE_EXTENSION, ext); /* now we put in some of the additional properties if we have them */ if (header.type != null) properties.put("type", header.type);