diff options
Diffstat (limited to 'src')
4 files changed, 12 insertions, 16 deletions
diff --git a/src/java/com/jogamp/openal/util/WAVData.java b/src/java/com/jogamp/openal/util/WAVData.java index a69782a..fdf21db 100644 --- a/src/java/com/jogamp/openal/util/WAVData.java +++ b/src/java/com/jogamp/openal/util/WAVData.java @@ -84,14 +84,12 @@ public final class WAVData { /** * This method loads a (.wav) file into a WAVData object. - * @param initialCapacity initial buffer capacity in bytes, if > available bytes + * @param aIn An InputStream for the .WAV stream + * @param byteCount byte count of expected wav data to be read * @param numChannels * @param bits * @param sampleRate * @param byteOrder - * @param aIn An InputStream for the .WAV stream - * @param size Amount of data to load from buffer (or zero for all available) - * * @return a WAVData object containing the audio data * * @throws UnsupportedAudioFileException if the format of the audio if not @@ -99,7 +97,7 @@ public final class WAVData { * @throws IOException If the file can no be found or some other IO error * occurs */ - public static WAVData loadFromStream(InputStream aIn, final int initialCapacity, final int numChannels, final int bits, final int sampleRate, final ByteOrder byteOrder, final boolean loop, int size) + public static WAVData loadFromStream(InputStream aIn, final int byteCount, final int numChannels, final int bits, final int sampleRate, final ByteOrder byteOrder, final boolean loop) throws IOException { if( !(aIn instanceof BufferedInputStream) ) { aIn = new BufferedInputStream(aIn); @@ -116,10 +114,8 @@ public final class WAVData { } else if ((bits == 16) && (numChannels == 2)) { format = ALConstants.AL_FORMAT_STEREO16; } - final ByteBuffer buffer = IOUtil.copyStream2ByteBuffer(aIn, initialCapacity); - if (size==0) { - size = buffer.limit(); - } + final ByteBuffer buffer = IOUtil.copyStreamChunk2ByteBuffer(aIn, 0, byteCount); + final int actualSize = buffer.limit(); // Must byte swap in case endianess mismatch if ( bits == 16 && ByteOrder.nativeOrder() != byteOrder ) { @@ -132,7 +128,7 @@ public final class WAVData { } } - final WAVData result = new WAVData(buffer, format, size, sampleRate, loop); + final WAVData result = new WAVData(buffer, format, actualSize, sampleRate, loop); aIn.close(); return result; diff --git a/src/java/com/jogamp/openal/util/WAVLoader.java b/src/java/com/jogamp/openal/util/WAVLoader.java index 48ff62a..0b88cc6 100644 --- a/src/java/com/jogamp/openal/util/WAVLoader.java +++ b/src/java/com/jogamp/openal/util/WAVLoader.java @@ -163,7 +163,7 @@ public class WAVLoader { final int sampleSizeInBits = sSampleSizeInBits; final float fSampleRate = sampleRate; return WAVData.loadFromStream(bs.getSubStream(), dataLength, channels, sampleSizeInBits, - Math.round(fSampleRate), bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN, false, dataLength); + Math.round(fSampleRate), bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN, false); } finally { bs.close(); } diff --git a/src/test/com/jogamp/openal/test/junit/ALutWAVLoaderTest.java b/src/test/com/jogamp/openal/test/junit/ALutWAVLoaderTest.java index 1e6f30f..29035da 100644 --- a/src/test/com/jogamp/openal/test/junit/ALutWAVLoaderTest.java +++ b/src/test/com/jogamp/openal/test/junit/ALutWAVLoaderTest.java @@ -41,19 +41,19 @@ public class ALutWAVLoaderTest extends UITestCase { @Test public void testWAVDataLoadStream() throws IOException { - final WAVData wd0 = WAVData.loadFromStream(ResourceLocation.getTestStream0(), ResourceLocation.getTestStream0Size(), 1, 8, 22050, ByteOrder.LITTLE_ENDIAN, true, 0); + final WAVData wd0 = WAVData.loadFromStream(ResourceLocation.getTestStream0(), ResourceLocation.getTestStream0Size(), 1, 8, 22050, ByteOrder.LITTLE_ENDIAN, true); System.out.println("*** WAVData.loadFrom Stream0 size "+wd0.data.limit()); assertEquals(wd0.data.limit(), ResourceLocation.getTestStream0Size()); - final WAVData wd1 = WAVData.loadFromStream(ResourceLocation.getTestStream1(), ResourceLocation.getTestStream1Size(), 2, 16, 44100, ByteOrder.BIG_ENDIAN, true, 0); + final WAVData wd1 = WAVData.loadFromStream(ResourceLocation.getTestStream1(), ResourceLocation.getTestStream1Size(), 2, 16, 44100, ByteOrder.BIG_ENDIAN, true); System.out.println("*** WAVData.loadFrom Stream1 size "+wd1.data.limit()); assertEquals(wd1.data.limit(), ResourceLocation.getTestStream1Size()); - final WAVData wd2 = WAVData.loadFromStream(ResourceLocation.getTestStream2(), ResourceLocation.getTestStream2Size(), 2, 16, 44100, ByteOrder.LITTLE_ENDIAN, true, 0); + final WAVData wd2 = WAVData.loadFromStream(ResourceLocation.getTestStream2(), ResourceLocation.getTestStream2Size(), 2, 16, 44100, ByteOrder.LITTLE_ENDIAN, true); System.out.println("*** WAVData.loadFrom Stream2 size "+wd2.data.limit()); assertEquals(wd2.data.limit(), ResourceLocation.getTestStream2Size()); - final WAVData wd3 = WAVData.loadFromStream(ResourceLocation.getTestStream3(), ResourceLocation.getTestStream3Size(), 2, 16, 44100, ByteOrder.LITTLE_ENDIAN, true, 0); + final WAVData wd3 = WAVData.loadFromStream(ResourceLocation.getTestStream3(), ResourceLocation.getTestStream3Size(), 2, 16, 44100, ByteOrder.LITTLE_ENDIAN, true); System.out.println("*** WAVData.loadFrom Stream3 size "+wd3.data.limit()); assertEquals(wd3.data.limit(), ResourceLocation.getTestStream3Size()); diff --git a/src/test/com/jogamp/openal/test/manual/OpenALTest.java b/src/test/com/jogamp/openal/test/manual/OpenALTest.java index 9b48560..1981326 100644 --- a/src/test/com/jogamp/openal/test/manual/OpenALTest.java +++ b/src/test/com/jogamp/openal/test/manual/OpenALTest.java @@ -102,7 +102,7 @@ public class OpenALTest { // WAVData wd = WAVData.loadFromStream(ResourceLocation.getTestStream0(), ResourceLocation.getTestStream0Size(), 1, 8, 22050, ByteOrder.LITTLE_ENDIAN, true); // WAVData wd = WAVData.loadFromStream(ResourceLocation.getTestStream1(), ResourceLocation.getTestStream1Size(), 2, 16, 44100, ByteOrder.BIG_ENDIAN, true); - final WAVData wd = WAVData.loadFromStream(ResourceLocation.getTestStream2(), ResourceLocation.getTestStream2Size(), 2, 16, 44100, ByteOrder.LITTLE_ENDIAN, true, 0); + final WAVData wd = WAVData.loadFromStream(ResourceLocation.getTestStream2(), ResourceLocation.getTestStream2Size(), 2, 16, 44100, ByteOrder.LITTLE_ENDIAN, true); // WAVData wd = WAVData.loadFromStream(ResourceLocation.getTestStream3(), ResourceLocation.getTestStream3Size(), 2, 16, 44100, ByteOrder.LITTLE_ENDIAN, true); System.out.println("*** size "+wd.data.limit()); |