|
From: Brian M. <ma...@us...> - 2005-08-18 20:09:08
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2534/src/java/org/lwjgl/util Modified Files: WaveData.java Log Message: added everything but the kitchen sink Index: WaveData.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/util/WaveData.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- WaveData.java 29 Mar 2005 18:09:32 -0000 1.2 +++ WaveData.java 18 Aug 2005 11:27:44 -0000 1.3 @@ -34,6 +34,8 @@ import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ShortBuffer; @@ -83,24 +85,51 @@ } /** - * Creates a WaveData container from the specified filename + * Creates a WaveData container from the specified url * - * @param filepath path to file (relative, and in classpath) + * @param path URL to file * @return WaveData containing data, or null if a failure occured */ - public static WaveData create(String filepath) { + public static WaveData create(URL path) { try { return create( AudioSystem.getAudioInputStream( - new BufferedInputStream(WaveData.class.getClassLoader().getResourceAsStream(filepath)))); + new BufferedInputStream(path.openStream()))); } catch (Exception e) { - org.lwjgl.LWJGLUtil.log("Unable to load file: " + filepath); + org.lwjgl.LWJGLUtil.log("Unable to create from: " + path); e.printStackTrace(); return null; } } /** + * Creates a WaveData container from the specified in the classpath + * + * @param path path to file (relative, and in classpath) + * @return WaveData containing data, or null if a failure occured + */ + public static WaveData create(String path) { + return create(WaveData.class.getClassLoader().getResource(path)); + } + + /** + * Creates a WaveData container from the specified inputstream + * + * @param is InputStream to read from + * @return WaveData containing data, or null if a failure occured + */ + public static WaveData create(InputStream is) { + try { + return create( + AudioSystem.getAudioInputStream(is)); + } catch (Exception e) { + org.lwjgl.LWJGLUtil.log("Unable to create from inputstream"); + e.printStackTrace(); + return null; + } + } + + /** * Creates a WaveData container from the specified bytes * * @param buffer array of bytes containing the complete wave file @@ -115,6 +144,31 @@ e.printStackTrace(); return null; } + } + + /** + * Creates a WaveData container from the specified ByetBuffer. + * If the buffer is backed by an array, it will be used directly, + * else the contents of the buffer will be copied using get(byte[]). + * + * @param buffer ByteBuffer containing sound file + * @return WaveData containing data, or null if a failure occured + */ + public static WaveData create(ByteBuffer buffer) { + try { + byte[] bytes = null; + + if(buffer.hasArray()) { + bytes = buffer.array(); + } else { + bytes = new byte[buffer.capacity()]; + buffer.get(bytes); + } + return create(bytes); + } catch (Exception e) { + e.printStackTrace(); + return null; + } } /** |