diff options
author | Sven Gothel <[email protected]> | 2023-05-04 01:17:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-05-04 01:17:02 +0200 |
commit | 159cd98994f199c014c14c048fe4d18270057e49 (patch) | |
tree | 7ce8176a6a1eb998b8e139e45ea444ce5f9099aa /src/java/com/jogamp/openal/util/WAVData.java | |
parent | bfba3d564cfb53ea879d5050abf0384c5f438c20 (diff) |
Fix Bug 1280: WAVData.loadFromStream(..) *API Change*: Only take expected byteCount (2nd arg) using IOUtil.copyStreamChunk2ByteBuffer(..)
This fix is inspired by Bug 1280, <https://github.com/sgothel/joal/pull/16>,
'copy only needed bytes' for JOAL's com.jogamp.openal.util.WAVData.loadFromStream(..).
This GlueGen IOUtil.copyStreamChunk2ByteBuffer() method is a revised version of the proposed IOHelpers.copyFromStream2ByteBuffer(..),
see <https://github.com/OndrejSpanel/joal/commit/1616659e98904270af4faca25b770d0983609735>
Diffstat (limited to 'src/java/com/jogamp/openal/util/WAVData.java')
-rw-r--r-- | src/java/com/jogamp/openal/util/WAVData.java | 16 |
1 files changed, 6 insertions, 10 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; |