summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/java/com/jogamp/openal/util/WAVData.java29
-rw-r--r--src/java/com/jogamp/openal/util/WAVLoader.java5
-rw-r--r--src/test/com/jogamp/openal/test/manual/OpenALTest.java18
-rw-r--r--src/test/com/jogamp/openal/test/resources/ResourceLocation.java38
-rw-r--r--src/test/com/jogamp/openal/test/resources/aa.cdbin0 -> 846704 bytes
-rw-r--r--src/test/com/jogamp/openal/test/resources/aa.cdrbin0 -> 846704 bytes
-rw-r--r--src/test/com/jogamp/openal/test/resources/aa.wavbin0 -> 846748 bytes
7 files changed, 69 insertions, 21 deletions
diff --git a/src/java/com/jogamp/openal/util/WAVData.java b/src/java/com/jogamp/openal/util/WAVData.java
index d470643..43c217d 100644
--- a/src/java/com/jogamp/openal/util/WAVData.java
+++ b/src/java/com/jogamp/openal/util/WAVData.java
@@ -34,6 +34,7 @@
package com.jogamp.openal.util;
+import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -41,6 +42,7 @@ import java.nio.ByteOrder;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
+import com.jogamp.common.util.IOUtil;
import com.jogamp.openal.ALConstants;
import com.jogamp.openal.UnsupportedAudioFileException;
@@ -84,11 +86,12 @@ public final class WAVData {
/**
* This method loads a (.wav) file into a WAVData object.
- *
- * @param stream An InputStream for the .WAV stream
+ * @param initialCapacity initial buffer capacity in bytes, if > available bytes
* @param numChannels
* @param bits
* @param sampleRate
+ * @param byteOrder
+ * @param stream An InputStream for the .WAV stream
*
* @return a WAVData object containing the audio data
*
@@ -97,9 +100,12 @@ 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, int numChannels, int bits, int sampleRate)
+ public static WAVData loadFromStream(InputStream aIn, int initialCapacity, int numChannels, int bits, int sampleRate, ByteOrder byteOrder, boolean loop)
throws IOException {
- ReadableByteChannel aChannel = Channels.newChannel(aIn);
+ if( !(aIn instanceof BufferedInputStream) ) {
+ aIn = new BufferedInputStream(aIn);
+ }
+ // ReadableByteChannel aChannel = Channels.newChannel(aIn);
int format = ALConstants.AL_FORMAT_MONO8;
if ((bits == 8) && (numChannels == 1)) {
@@ -112,16 +118,11 @@ public final class WAVData {
format = ALConstants.AL_FORMAT_STEREO16;
}
- int size = aIn.available();
- ByteBuffer buffer = ByteBuffer.allocateDirect(size);
- while (buffer.remaining() > 0) {
- aChannel.read(buffer);
- }
- buffer.rewind();
+ ByteBuffer buffer = IOUtil.copyStream2ByteBuffer(aIn, initialCapacity);
+ int size = buffer.limit();
- // Must byte swap on big endian platforms
- // Thanks to swpalmer on javagaming.org forums for hint at fix
- if ((bits == 16) && (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)) {
+ // Must byte swap in case endianess mismatch
+ if ( bits == 16 && ByteOrder.nativeOrder() != byteOrder ) {
int len = buffer.remaining();
for (int i = 0; i < len; i += 2) {
byte a = buffer.get(i);
@@ -131,7 +132,7 @@ public final class WAVData {
}
}
- WAVData result = new WAVData(buffer, format, size, sampleRate, false);
+ WAVData result = new WAVData(buffer, format, size, 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 40ad99e..f997eb4 100644
--- a/src/java/com/jogamp/openal/util/WAVLoader.java
+++ b/src/java/com/jogamp/openal/util/WAVLoader.java
@@ -37,6 +37,7 @@ package com.jogamp.openal.util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteOrder;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
@@ -103,7 +104,9 @@ public class WAVLoader {
private static WAVData loadFromStreamImpl(AudioInputStream aIn)
throws UnsupportedAudioFileException, IOException {
final AudioFormat fmt = aIn.getFormat();
- return WAVData.loadFromStream(aIn, fmt.getChannels(), fmt.getSampleSizeInBits(), Math.round(fmt.getSampleRate()));
+ return WAVData.loadFromStream(aIn, -1, fmt.getChannels(), fmt.getSampleSizeInBits(),
+ Math.round(fmt.getSampleRate()),
+ fmt.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN, false);
}
}
diff --git a/src/test/com/jogamp/openal/test/manual/OpenALTest.java b/src/test/com/jogamp/openal/test/manual/OpenALTest.java
index 1bc8b78..eac1d46 100644
--- a/src/test/com/jogamp/openal/test/manual/OpenALTest.java
+++ b/src/test/com/jogamp/openal/test/manual/OpenALTest.java
@@ -34,6 +34,7 @@ package com.jogamp.openal.test.manual;
* design, construction, operation or maintenance of any nuclear facility.
*/
import java.io.IOException;
+import java.nio.ByteOrder;
import java.nio.IntBuffer;
import com.jogamp.common.nio.Buffers;
@@ -70,8 +71,7 @@ public class OpenALTest {
device = alc.alcOpenDevice(null);
context = alc.alcCreateContext(device, null);
alc.alcMakeContextCurrent(context);
- al = ALFactory.getAL();
-
+ al = ALFactory.getAL();
System.out.println("output devices:");
{
final String[] outDevices = alc.alcGetDeviceSpecifiers();
@@ -98,7 +98,12 @@ public class OpenALTest {
int[] buffers = new int[1];
al.alGenBuffers(1, buffers, 0);
- WAVData wd = WAVData.loadFromStream(ResourceLocation.getTestStream0(), 1, 8, 22050);
+ // 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);
+ 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());
+
al.alBufferData(buffers[0], wd.format, wd.data, wd.size, wd.freq);
sources = new int[1];
@@ -126,6 +131,7 @@ public class OpenALTest {
return;
}
System.out.println("play direct");
+ al.alSourceRewind(sources[0]);
al.alSourcePlay(sources[0]);
}
@@ -134,6 +140,8 @@ public class OpenALTest {
return;
}
System.out.println("play3f "+x+", "+y+", "+z);
+ al.alSourceRewind(sources[0]);
+ al.alSourcePlay(sources[0]);
al.alSource3f(sources[0], AL.AL_POSITION, x, y, z);
}
@@ -150,7 +158,7 @@ public class OpenALTest {
}
if( null != sources ) {
al.alSourceStop(sources[0]);
- al.alDeleteSources(1, sources, 0);
+ al.alDeleteSources(1, sources, 0);
sources = null;
}
if( null != context ) {
@@ -178,7 +186,7 @@ public class OpenALTest {
Thread.sleep(5000);
demo.play3f(0f, 0f, 0f);
- Thread.sleep(10000);
+ Thread.sleep(5000);
demo.dispose();
}
diff --git a/src/test/com/jogamp/openal/test/resources/ResourceLocation.java b/src/test/com/jogamp/openal/test/resources/ResourceLocation.java
index 9b2eb75..ba4ea99 100644
--- a/src/test/com/jogamp/openal/test/resources/ResourceLocation.java
+++ b/src/test/com/jogamp/openal/test/resources/ResourceLocation.java
@@ -10,8 +10,19 @@ import com.jogamp.common.util.IOUtil;
/** just a tag to locate the resources */
public class ResourceLocation {
+ /** WAV 22050Hz, 1 channel, S8_LE */
public static final String lewiscarrol_wav = "lewiscarroll.wav";
-
+ public static final int lewiscarrol_wav_size = 1025476;
+ /** CDR 44100Hz, 2 channels, S16_BE */
+ public static final String aa_cdr = "aa.cdr";
+ public static final int aa_cdr_size = 846704;
+ /** CDR 44100Hz, 2 channels, S16_LE */
+ public static final String aa_cd = "aa.cd";
+ public static final int aa_cd_size = 846704;
+ /** CDR 44100Hz, 2 channels, S16_LE */
+ public static final String aa_wav = "aa.wav";
+ public static final int aa_wav_size = 846748;
+
static final ResourceLocation rl;
static {
@@ -19,9 +30,34 @@ public class ResourceLocation {
}
+ /** WAV 22050Hz, 1 channel, S8_LE */
public static InputStream getTestStream0() {
return getInputStream(lewiscarrol_wav, true);
}
+ public static int getTestStream0Size() {
+ return lewiscarrol_wav_size;
+ }
+ /** CDR 44100Hz, 2 channels, S16_BE */
+ public static InputStream getTestStream1() {
+ return getInputStream(aa_cdr, true);
+ }
+ public static int getTestStream1Size() {
+ return aa_cdr_size;
+ }
+ /** CDR 44100Hz, 2 channels, S16_LE */
+ public static InputStream getTestStream2() {
+ return getInputStream(aa_cd, true);
+ }
+ public static int getTestStream2Size() {
+ return aa_cd_size;
+ }
+ /** WAV 44100Hz, 2 channels, S16_LE */
+ public static InputStream getTestStream3() {
+ return getInputStream(aa_wav, true);
+ }
+ public static int getTestStream3Size() {
+ return aa_wav_size;
+ }
public static InputStream getInputStream(String fileName) {
return getInputStream(fileName, false);
diff --git a/src/test/com/jogamp/openal/test/resources/aa.cd b/src/test/com/jogamp/openal/test/resources/aa.cd
new file mode 100644
index 0000000..497831c
--- /dev/null
+++ b/src/test/com/jogamp/openal/test/resources/aa.cd
Binary files differ
diff --git a/src/test/com/jogamp/openal/test/resources/aa.cdr b/src/test/com/jogamp/openal/test/resources/aa.cdr
new file mode 100644
index 0000000..21e8a53
--- /dev/null
+++ b/src/test/com/jogamp/openal/test/resources/aa.cdr
Binary files differ
diff --git a/src/test/com/jogamp/openal/test/resources/aa.wav b/src/test/com/jogamp/openal/test/resources/aa.wav
new file mode 100644
index 0000000..8d607c2
--- /dev/null
+++ b/src/test/com/jogamp/openal/test/resources/aa.wav
Binary files differ