diff options
Diffstat (limited to 'src/java')
-rw-r--r-- | src/java/com/jogamp/openal/JoalVersion.java | 87 | ||||
-rw-r--r-- | src/java/com/jogamp/openal/UnsupportedAudioFileException.java | 21 | ||||
-rw-r--r-- | src/java/com/jogamp/openal/sound3d/AudioSystem3D.java | 17 | ||||
-rw-r--r-- | src/java/com/jogamp/openal/util/WAVData.java | 71 | ||||
-rw-r--r-- | src/java/com/jogamp/openal/util/WAVLoader.java | 86 |
5 files changed, 217 insertions, 65 deletions
diff --git a/src/java/com/jogamp/openal/JoalVersion.java b/src/java/com/jogamp/openal/JoalVersion.java new file mode 100644 index 0000000..41c333a --- /dev/null +++ b/src/java/com/jogamp/openal/JoalVersion.java @@ -0,0 +1,87 @@ +/** + * Copyright 2013 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.openal; + +import com.jogamp.common.GlueGenVersion; + +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.common.util.JogampVersion; + +import java.util.jar.Manifest; + +public class JoalVersion extends JogampVersion { + protected static volatile JoalVersion jogampCommonVersionInfo; + + protected JoalVersion(String packageName, Manifest mf) { + super(packageName, mf); + } + + public static JoalVersion getInstance() { + if(null == jogampCommonVersionInfo) { // volatile: ok + synchronized(JoalVersion.class) { + if( null == jogampCommonVersionInfo ) { + final String packageName = "com.jogamp.openal"; + final Manifest mf = VersionUtil.getManifest(JoalVersion.class.getClassLoader(), packageName); + jogampCommonVersionInfo = new JoalVersion(packageName, mf); + } + } + } + return jogampCommonVersionInfo; + } + + public StringBuilder toString(StringBuilder sb) { + sb = super.toString(sb).append(Platform.getNewline()); + // getGLInfo(gl, sb); + return sb; + } + + public String toString() { + return toString(null).toString(); + } + + public StringBuilder getBriefOSALBuildInfo(StringBuilder sb) { + if(null==sb) { + sb = new StringBuilder(); + } + sb.append("OS: ").append(Platform.getOSName()).append(", version ").append(Platform.getOSVersion()).append(", arch ").append(Platform.getArchName()); + sb.append(Platform.getNewline()); + sb.append("JOAL GIT sha1 ").append(getImplementationCommit()); + sb.append(Platform.getNewline()); + return sb; + } + + public static void main(String args[]) { + System.err.println(VersionUtil.getPlatformInfo()); + System.err.println(GlueGenVersion.getInstance()); + // System.err.println(NativeWindowVersion.getInstance()); + System.err.println(JoalVersion.getInstance()); + } +} + diff --git a/src/java/com/jogamp/openal/UnsupportedAudioFileException.java b/src/java/com/jogamp/openal/UnsupportedAudioFileException.java new file mode 100644 index 0000000..a371191 --- /dev/null +++ b/src/java/com/jogamp/openal/UnsupportedAudioFileException.java @@ -0,0 +1,21 @@ +package com.jogamp.openal; + +public class UnsupportedAudioFileException extends Exception { + + public UnsupportedAudioFileException (String message) { + super(message); + } + + public UnsupportedAudioFileException () { + super(); + } + + public UnsupportedAudioFileException (String message, Throwable cause) { + super(message, cause); + } + + public UnsupportedAudioFileException (Throwable cause) { + super(cause); + } + +} diff --git a/src/java/com/jogamp/openal/sound3d/AudioSystem3D.java b/src/java/com/jogamp/openal/sound3d/AudioSystem3D.java index 1070d21..4d7b2b1 100644 --- a/src/java/com/jogamp/openal/sound3d/AudioSystem3D.java +++ b/src/java/com/jogamp/openal/sound3d/AudioSystem3D.java @@ -33,15 +33,20 @@ package com.jogamp.openal.sound3d; -import com.jogamp.openal.*; +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; + +import com.jogamp.openal.AL; +import com.jogamp.openal.ALC; +import com.jogamp.openal.ALCcontext; +import com.jogamp.openal.ALCdevice; +import com.jogamp.openal.ALException; +import com.jogamp.openal.ALFactory; +import com.jogamp.openal.UnsupportedAudioFileException; import com.jogamp.openal.util.WAVData; import com.jogamp.openal.util.WAVLoader; -import java.io.*; - -import javax.sound.sampled.UnsupportedAudioFileException; - - /** * The AudioSystem3D class provides a set of methods for creating and * manipulating a 3D audio environment. diff --git a/src/java/com/jogamp/openal/util/WAVData.java b/src/java/com/jogamp/openal/util/WAVData.java index 345c675..d470643 100644 --- a/src/java/com/jogamp/openal/util/WAVData.java +++ b/src/java/com/jogamp/openal/util/WAVData.java @@ -1,5 +1,6 @@ /** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* Copyright (c) 2011 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -33,13 +34,21 @@ package com.jogamp.openal.util; +import java.io.IOException; +import java.io.InputStream; import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import com.jogamp.openal.ALConstants; +import com.jogamp.openal.UnsupportedAudioFileException; /** - * This class is a holder for WAV (.wav )file Data returned from the WavLoader + * This class is a holder for WAV (.wav ) file Data returned from the WavLoader, + * or directly via {@link #loadFromStream(InputStream, int, int, int)}. * - * @author Athomas Goldberg + * @author Athomas Goldberg, et.al. */ public final class WAVData { /** The audio data */ @@ -65,11 +74,67 @@ public final class WAVData { /** flag indicating whether or not the sound in the data should loop */ public final boolean loop; - WAVData(ByteBuffer data, int format, int size, int freq, boolean loop) { + public WAVData(ByteBuffer data, int format, int size, int freq, boolean loop) { this.data = data; this.format = format; this.size = size; this.freq = freq; this.loop = loop; } + + /** + * This method loads a (.wav) file into a WAVData object. + * + * @param stream An InputStream for the .WAV stream + * @param numChannels + * @param bits + * @param sampleRate + * + * @return a WAVData object containing the audio data + * + * @throws UnsupportedAudioFileException if the format of the audio if not + * supported. + * @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) + throws IOException { + ReadableByteChannel aChannel = Channels.newChannel(aIn); + int format = ALConstants.AL_FORMAT_MONO8; + + if ((bits == 8) && (numChannels == 1)) { + format = ALConstants.AL_FORMAT_MONO8; + } else if ((bits == 16) && (numChannels == 1)) { + format = ALConstants.AL_FORMAT_MONO16; + } else if ((bits == 8) && (numChannels == 2)) { + format = ALConstants.AL_FORMAT_STEREO8; + } else if ((bits == 16) && (numChannels == 2)) { + format = ALConstants.AL_FORMAT_STEREO16; + } + + int size = aIn.available(); + ByteBuffer buffer = ByteBuffer.allocateDirect(size); + while (buffer.remaining() > 0) { + aChannel.read(buffer); + } + buffer.rewind(); + + // 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)) { + int len = buffer.remaining(); + for (int i = 0; i < len; i += 2) { + byte a = buffer.get(i); + byte b = buffer.get(i+1); + buffer.put(i, b); + buffer.put(i+1, a); + } + } + + WAVData result = new WAVData(buffer, format, size, sampleRate, false); + 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 4ee2305..40ad99e 100644 --- a/src/java/com/jogamp/openal/util/WAVLoader.java +++ b/src/java/com/jogamp/openal/util/WAVLoader.java @@ -1,5 +1,6 @@ /** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. +* Copyright (c) 2011 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -33,21 +34,24 @@ package com.jogamp.openal.util; -import java.io.*; -import java.nio.*; -import java.nio.channels.*; -import javax.sound.sampled.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; -import com.jogamp.openal.*; +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; + +import com.jogamp.openal.UnsupportedAudioFileException; /** * A Loader utility for (.wav) files. Creates a WAVData object containing the * data used by the AL.alBufferData method. * - * @author Athomas Goldberg + * @author Athomas Goldberg, et.al */ -public class WAVLoader implements ALConstants { - private static final int BUFFER_SIZE = 128000; +public class WAVLoader { + // private static final int BUFFER_SIZE = 128000; /** * This method loads a (.wav) file into a WAVData object. @@ -63,16 +67,19 @@ public class WAVLoader implements ALConstants { */ public static WAVData loadFromFile(String filename) throws UnsupportedAudioFileException, IOException { - WAVData result = null; File soundFile = new File(filename); - AudioInputStream aIn = AudioSystem.getAudioInputStream(soundFile); - return readFromStream(aIn); + try { + AudioInputStream aIn = AudioSystem.getAudioInputStream(soundFile); + return loadFromStreamImpl(aIn); + } catch (javax.sound.sampled.UnsupportedAudioFileException e) { + throw new UnsupportedAudioFileException(e); + } } /** * This method loads a (.wav) file into a WAVData object. * - * @param stream An InputStream for the .WAV file. + * @param stream An InputStream for the .WAV stream. * * @return a WAVData object containing the audio data * @@ -83,53 +90,20 @@ public class WAVLoader implements ALConstants { */ public static WAVData loadFromStream(InputStream stream) throws UnsupportedAudioFileException, IOException { - WAVData result = null; - AudioInputStream aIn = AudioSystem.getAudioInputStream(stream); - return readFromStream(aIn); + AudioInputStream aIn; + try { + aIn = AudioSystem.getAudioInputStream(stream); + return loadFromStreamImpl(aIn); + } catch (javax.sound.sampled.UnsupportedAudioFileException e) { + throw new UnsupportedAudioFileException(e); + } } - private static WAVData readFromStream(AudioInputStream aIn) + private static WAVData loadFromStreamImpl(AudioInputStream aIn) throws UnsupportedAudioFileException, IOException { - ReadableByteChannel aChannel = Channels.newChannel(aIn); - AudioFormat fmt = aIn.getFormat(); - int numChannels = fmt.getChannels(); - int bits = fmt.getSampleSizeInBits(); - int format = AL_FORMAT_MONO8; - - if ((bits == 8) && (numChannels == 1)) { - format = AL_FORMAT_MONO8; - } else if ((bits == 16) && (numChannels == 1)) { - format = AL_FORMAT_MONO16; - } else if ((bits == 8) && (numChannels == 2)) { - format = AL_FORMAT_STEREO8; - } else if ((bits == 16) && (numChannels == 2)) { - format = AL_FORMAT_STEREO16; - } - - int freq = Math.round(fmt.getSampleRate()); - int size = aIn.available(); - ByteBuffer buffer = ByteBuffer.allocateDirect(size); - while (buffer.remaining() > 0) { - aChannel.read(buffer); - } - buffer.rewind(); - - // 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)) { - int len = buffer.remaining(); - for (int i = 0; i < len; i += 2) { - byte a = buffer.get(i); - byte b = buffer.get(i+1); - buffer.put(i, b); - buffer.put(i+1, a); - } - } - - WAVData result = new WAVData(buffer, format, size, freq, false); - aIn.close(); - - return result; + final AudioFormat fmt = aIn.getFormat(); + return WAVData.loadFromStream(aIn, fmt.getChannels(), fmt.getSampleSizeInBits(), Math.round(fmt.getSampleRate())); } + } |