Revision: 3274
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3274&view=rev
Author: matzon
Date: 2010-02-20 10:43:22 +0000 (Sat, 20 Feb 2010)
Log Message:
-----------
cleanup and better logging - no longer prints stacktrace
changed AudioInputStream method to use available() instead of calculating it.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/WaveData.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/WaveData.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/WaveData.java 2010-02-14 17:06:15 UTC (rev 3273)
+++ trunk/LWJGL/src/java/org/lwjgl/util/WaveData.java 2010-02-20 10:43:22 UTC (rev 3274)
@@ -96,8 +96,7 @@
AudioSystem.getAudioInputStream(
new BufferedInputStream(path.openStream())));
} catch (Exception e) {
- org.lwjgl.LWJGLUtil.log("Unable to create from: " + path);
- e.printStackTrace();
+ org.lwjgl.LWJGLUtil.log("Unable to create from: " + path + ", " + e.getMessage());
return null;
}
}
@@ -123,8 +122,7 @@
return create(
AudioSystem.getAudioInputStream(is));
} catch (Exception e) {
- org.lwjgl.LWJGLUtil.log("Unable to create from inputstream");
- e.printStackTrace();
+ org.lwjgl.LWJGLUtil.log("Unable to create from inputstream, " + e.getMessage());
return null;
}
}
@@ -141,7 +139,7 @@
AudioSystem.getAudioInputStream(
new BufferedInputStream(new ByteArrayInputStream(buffer))));
} catch (Exception e) {
- e.printStackTrace();
+ org.lwjgl.LWJGLUtil.log("Unable to create from byte array, " + e.getMessage());
return null;
}
}
@@ -166,7 +164,7 @@
}
return create(bytes);
} catch (Exception e) {
- e.printStackTrace();
+ org.lwjgl.LWJGLUtil.log("Unable to create from ByteBuffer, " + e.getMessage());
return null;
}
}
@@ -204,26 +202,23 @@
}
//read data into buffer
- byte[] buf =
- new byte[audioformat.getChannels()
- * (int) ais.getFrameLength()
- * audioformat.getSampleSizeInBits()
- / 8];
- int read = 0, total = 0;
+ ByteBuffer buffer = null;
try {
+ int available = ais.available();
+ if(available <= 0) {
+ available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
+ }
+ byte[] buf = new byte[ais.available()];
+ int read = 0, total = 0;
while ((read = ais.read(buf, total, buf.length - total)) != -1
&& total < buf.length) {
total += read;
}
+ buffer = convertAudioBytes(buf, audioformat.getSampleSizeInBits() == 16);
} catch (IOException ioe) {
return null;
}
- //insert data into bytebuffer
- ByteBuffer buffer = convertAudioBytes(buf, audioformat.getSampleSizeInBits() == 16);
-/* ByteBuffer buffer = ByteBuffer.allocateDirect(buf.length);
- buffer.put(buf);
- buffer.rewind();*/
//create our result
WaveData wavedata =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|