From c3b060be6db421543b83c11613b114e80e775427 Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Wed, 6 Apr 2011 01:23:35 +0000 Subject: [PATCH] * Fixed bug with WAV audio getting truncated on import git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7197 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/audio/plugins/WAVLoader.java | 17 ++- .../src/core/com/jme3/util/LittleEndien.java | 117 ++++++++++-------- .../jme3/audio/lwjgl/LwjglAudioRenderer.java | 2 +- 3 files changed, 73 insertions(+), 63 deletions(-) diff --git a/engine/src/core/com/jme3/audio/plugins/WAVLoader.java b/engine/src/core/com/jme3/audio/plugins/WAVLoader.java index 39bb133f9..3e7a5d8d8 100644 --- a/engine/src/core/com/jme3/audio/plugins/WAVLoader.java +++ b/engine/src/core/com/jme3/audio/plugins/WAVLoader.java @@ -38,13 +38,13 @@ import com.jme3.audio.AudioStream; import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetLoader; import com.jme3.audio.AudioKey; -import com.jme3.asset.TextureKey; import com.jme3.util.BufferUtils; import com.jme3.util.LittleEndien; import java.io.DataInput; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; +import java.util.logging.Level; import java.util.logging.Logger; public class WAVLoader implements AssetLoader { @@ -84,8 +84,7 @@ public class WAVLoader implements AssetLoader { private int dataLength; private float duration; - private DataInput in; - private InputStream stream; + private LittleEndien in; private boolean adpcm = false; private int predictor; @@ -116,7 +115,8 @@ public class WAVLoader implements AssetLoader { int expectedBytesPerSec = (bitsPerSample * channels * sampleRate) / 8; if (expectedBytesPerSec != bytesPerSec){ - logger.warning("Expected "+expectedBytesPerSec+" bytes per second, got "+bytesPerSec); + logger.log(Level.WARNING, "Expected {0} bytes per second, got {1}", + new Object[]{expectedBytesPerSec, bytesPerSec}); } duration = dataLength / bytesPerSec; @@ -178,17 +178,16 @@ public class WAVLoader implements AssetLoader { ByteBuffer data = BufferUtils.createByteBuffer(dataLength); byte[] buf = new byte[512]; int read = 0; - while ( (read = stream.read(buf)) > 0){ + while ( (read = in.read(buf)) > 0){ data.put(buf, 0, read); } data.flip(); audioBuffer.updateData(data); - stream.close(); + in.close(); } public Object load(AssetInfo info) throws IOException { - this.stream = info.openStream(); - in = new LittleEndien(stream); + this.in = new LittleEndien(info.openStream()); int sig = in.readInt(); if (sig != i_RIFF) @@ -219,7 +218,7 @@ public class WAVLoader implements AssetLoader { break; case i_data: if (readStream){ - audioStream.updateData(stream, duration); + audioStream.updateData(in, duration); }else{ readDataChunkForBuffer(len); } diff --git a/engine/src/core/com/jme3/util/LittleEndien.java b/engine/src/core/com/jme3/util/LittleEndien.java index 6834d9a45..7e6c74b9d 100644 --- a/engine/src/core/com/jme3/util/LittleEndien.java +++ b/engine/src/core/com/jme3/util/LittleEndien.java @@ -29,7 +29,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package com.jme3.util; import java.io.BufferedInputStream; @@ -45,7 +44,7 @@ import java.io.InputStreamReader; * assume they come from a LittleEndien input stream. Currently used to read .ms3d and .3ds files. * @author Jack Lindamood */ -public class LittleEndien implements DataInput{ +public class LittleEndien extends InputStream implements DataInput { private BufferedInputStream in; private BufferedReader inRead; @@ -55,100 +54,112 @@ public class LittleEndien implements DataInput{ * stream is wrapped in a BufferedReader automatically. * @param in The input stream to read from. */ - public LittleEndien(InputStream in){ + public LittleEndien(InputStream in) { this.in = new BufferedInputStream(in); - inRead=new BufferedReader(new InputStreamReader(in)); + inRead = new BufferedReader(new InputStreamReader(in)); + } + + public int read() throws IOException { + return in.read(); + } + + @Override + public int read(byte[] buf) throws IOException { + return in.read(buf); + } + + @Override + public int read(byte[] buf, int off, int len) throws IOException { + return in.read(buf, off, len); } - public final int readUnsignedShort() throws IOException{ - return (in.read()&0xff) | ((in.read()&0xff) << 8); + public int readUnsignedShort() throws IOException { + return (in.read() & 0xff) | ((in.read() & 0xff) << 8); } - + /** * read an unsigned int as a long */ - public final long readUInt() throws IOException{ - return ((in.read()&0xff) | - ((in.read()&0xff) << 8) | - ((in.read()&0xff) << 16) | - (((long)(in.read()&0xff)) << 24) - ); + public long readUInt() throws IOException { + return ((in.read() & 0xff) + | ((in.read() & 0xff) << 8) + | ((in.read() & 0xff) << 16) + | (((long) (in.read() & 0xff)) << 24)); } - - public final boolean readBoolean() throws IOException{ - return (in.read()!=0); + + public boolean readBoolean() throws IOException { + return (in.read() != 0); } - public final byte readByte() throws IOException{ + public byte readByte() throws IOException { return (byte) in.read(); } - public final int readUnsignedByte() throws IOException{ + public int readUnsignedByte() throws IOException { return in.read(); } - public final short readShort() throws IOException{ + public short readShort() throws IOException { return (short) this.readUnsignedShort(); } - public final char readChar() throws IOException{ + public char readChar() throws IOException { return (char) this.readUnsignedShort(); } - public final int readInt() throws IOException{ - return ( - (in.read()&0xff) | - ((in.read()&0xff) << 8) | - ((in.read()&0xff) << 16) | - ((in.read()&0xff) << 24) - ); - } - - public final long readLong() throws IOException{ - return ( - (in.read()&0xff) | - ((long)(in.read()&0xff) << 8) | - ((long)(in.read()&0xff) << 16) | - ((long)(in.read()&0xff) << 24) | - ((long)(in.read()&0xff) << 32) | - ((long)(in.read()&0xff) << 40) | - ((long)(in.read()&0xff) << 48) | - ((long)(in.read()&0xff) << 56) - ); - } - - public final float readFloat() throws IOException{ + + public int readInt() throws IOException { + return ((in.read() & 0xff) + | ((in.read() & 0xff) << 8) + | ((in.read() & 0xff) << 16) + | ((in.read() & 0xff) << 24)); + } + + public long readLong() throws IOException { + return ((in.read() & 0xff) + | ((long) (in.read() & 0xff) << 8) + | ((long) (in.read() & 0xff) << 16) + | ((long) (in.read() & 0xff) << 24) + | ((long) (in.read() & 0xff) << 32) + | ((long) (in.read() & 0xff) << 40) + | ((long) (in.read() & 0xff) << 48) + | ((long) (in.read() & 0xff) << 56)); + } + + public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); } - public final double readDouble() throws IOException{ + public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); } - public final void readFully(byte b[]) throws IOException{ + public void readFully(byte b[]) throws IOException { in.read(b, 0, b.length); } - public final void readFully(byte b[], int off, int len) throws IOException{ + public void readFully(byte b[], int off, int len) throws IOException { in.read(b, off, len); } - public final int skipBytes(int n) throws IOException{ + public int skipBytes(int n) throws IOException { return (int) in.skip(n); } - public final String readLine() throws IOException{ + public String readLine() throws IOException { return inRead.readLine(); } - public final String readUTF() throws IOException{ + public String readUTF() throws IOException { throw new IOException("Unsupported operation"); } - public final void close() throws IOException{ + @Override + public void close() throws IOException { in.close(); } - - public final int available() throws IOException{ + + @Override + public int available() throws IOException { return in.available(); } -} \ No newline at end of file +} diff --git a/engine/src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java b/engine/src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java index 97201c79b..b9cb26d86 100644 --- a/engine/src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java +++ b/engine/src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java @@ -841,7 +841,7 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable { // allocate channel to this source int index = newChannel(); if (index == -1) { - logger.log(Level.WARNING, "No channel available to play " + src); + logger.log(Level.WARNING, "No channel available to play {0}", src); return; } clearChannel(index);