diff options
author | kcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-02-01 01:33:24 +0000 |
---|---|---|
committer | kcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-02-01 01:33:24 +0000 |
commit | 39283191507259cb4dccba3441cdf16025179829 (patch) | |
tree | 29ad229325ab151a056d06fbe4c6f1fcd7b292d7 /src/classes/org/jdesktop/j3d/examples/sound | |
parent | 3d596b24b72677fbf264a22f3c0ff44aa9bb2baf (diff) |
Issue 206 : Example program cleanup
Item 4) Reorganized directory structure to make the examples a single project rather than a collection of independent apps.
. All example programs moved under src/classes, and all are now in a subpackage of org.jdesktop.j3d.examples.
. All resource files (geometry, images, audio) moved under src/resources
. ant script now exists only at top level
. Created netbeans project file for NetBeans IDE
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/sound')
6 files changed, 1361 insertions, 0 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/sound/AudioBehaviorMoveOne.java b/src/classes/org/jdesktop/j3d/examples/sound/AudioBehaviorMoveOne.java new file mode 100644 index 0000000..e5fc463 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/AudioBehaviorMoveOne.java @@ -0,0 +1,106 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package org.jdesktop.j3d.examples.sound; + +import javax.media.j3d.*; +import javax.vecmath.*; +import java.util.Enumeration; + +// User defined audio behavior class +public class AudioBehaviorMoveOne extends Behavior { + WakeupOnElapsedTime wt; + WakeupOnBehaviorPost wp; + PointSound psound = new PointSound(); + static int WAKEUP_SOUND = 0; + long dur; + // long time; + // long lastTime = -1; + boolean first_loop = true; + String fileName; + + // Override Behavior's initialize method to setup wakeup criteria + public void initialize() { + MediaContainer sample = new MediaContainer(); + sample.setCapability(MediaContainer.ALLOW_URL_WRITE); + sample.setCapability(MediaContainer.ALLOW_URL_READ); + sample.setURLString(fileName); + psound.setSoundData(sample); + // exaggerate the sound position now that viewPlatform + // tranform is taken into account + Point3f soundPos = new Point3f(-20.0f, 0.0f, 0.0f); + psound.setPosition(soundPos); + WakeupOnElapsedTime wp = new WakeupOnElapsedTime(5000); + wakeupOn(wp); + } + + // Override Behavior's stimulus method to handle the event + public void processStimulus(Enumeration criteria) { + // time = System.currentTimeMillis(); + if (first_loop) { + first_loop = false; + dur = psound.getDuration(); + if (dur == Sound.DURATION_UNKNOWN) + dur = 2000; // Force iterations every 2 seconds + // System.out.println(" sound duration time " + dur); + wt = new WakeupOnElapsedTime(dur); + } + else { + // System.out.println(" time between setEnables calls "+ + // (time - lastTime)); + psound.setEnable(false) ; + } + psound.setEnable(true); + // lastTime = time; + wakeupOn(wt); + } + + // + // Constructor for rotation behavior. Parameter: front and back Sound nodes + // + public AudioBehaviorMoveOne(PointSound psound, String filename) { + this.psound = psound; + this.fileName = filename; + } +} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/AudioReverberate.java b/src/classes/org/jdesktop/j3d/examples/sound/AudioReverberate.java new file mode 100644 index 0000000..1d83702 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/AudioReverberate.java @@ -0,0 +1,171 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package org.jdesktop.j3d.examples.sound; + +import javax.media.j3d.*; +import javax.vecmath.*; +import java.util.Enumeration; + +/* + * Pick the JavaSound reverb type that matches the input parameters + * as best as possible. + * + * Hae Reverb Types Size Persistance Delay + * ================ ----------- ------------ ----------- + * 1 None (dry) + * 2 "Closet" very small very short <.5 fast smooth + * 3 "Garage" med. large medium 1.0 medium + * 4 "Acoustic Lab" med. small short .5 med. fast + * 5 "Cavern" large long >2.0 very slow + * 6 "Dungeon" medium med. long 1.5 med. slow + * + * + * Order is NOT controllable, nor does it have a natural parallel. + * For this reason Order and Reflection are tied together as to + * affect 'Decay Speed'. This speed paired with the size of the + * space implied by the Delay parameter determine the JavaSound + * Reverb type that is set: + * + * | Short: Long: + * Speed | Coeff <= 0.9 Coeff > 0.9 + * Size | Order <= 8 Order > 8 + * --------------------------------------------------------------- + * small (<100ms) | 2 "Closet" 4 "Acoustic Lab" + * medium (<500ms) | 3 "Garage" 6 "Dungeon" + * large (>500ms) | 6 "Dungeon" 5 "Cavern" + */ +// User defined audio behavior class +public class AudioReverberate extends Behavior { + WakeupOnElapsedTime wt; + WakeupOnBehaviorPost wp; + PointSound psound = new PointSound(); + AuralAttributes sScape = null; + static int WAKEUP_SOUND = 0; + long dur; + long time; + boolean firstTime = true; + String fileName; + int lCount = 0; + int loopCount = 0; + + // Override Behavior's initialize method to setup wakeup criteria + public void initialize() { + MediaContainer sample = new MediaContainer(); + sample.setCacheEnable(true); + sample.setURLString(fileName); + psound.setSoundData(sample); + Point3f soundPos = new Point3f(-23.0f, 0.0f, 0.0f); + psound.setPosition(soundPos); + psound.setLoop(3); + firstTime = true; + System.out.println("Reverb Name Size Reflect Order Delay "); + System.out.println("----------- ---- ------- ----- ----- "); + WakeupOnElapsedTime wp = new WakeupOnElapsedTime(5000); + wakeupOn(wp); + } + + // Override Behavior's stimulus method to handle the event + public void processStimulus(Enumeration criteria) { + // time = System.currentTimeMillis(); + if (firstTime) { + wt = new WakeupOnElapsedTime(10000); + firstTime = false; + } + else + psound.setEnable(false) ; + + if (++lCount > 6) + lCount = 1; + + if (lCount == 1) { + sScape.setReverbDelay(10.0f) ; + sScape.setReflectionCoefficient(0.5f) ; + sScape.setReverbOrder(5) ; + System.out.println("Closet sm 0.5 5 10.0 "); + } + else if (lCount == 2) { + sScape.setReverbDelay(10.0f) ; + sScape.setReflectionCoefficient(0.999f) ; + sScape.setReverbOrder(9) ; + System.out.println("Acoustic Lab sm 0.999 9 10.0 "); + } + else if (lCount == 3) { + sScape.setReverbDelay(200.0f) ; + sScape.setReflectionCoefficient(0.4f) ; + sScape.setReverbOrder(3) ; + System.out.println("Garage med 0.4 3 200.0 "); + } + else if (lCount == 4) { + sScape.setReverbDelay(200.0f) ; + sScape.setReflectionCoefficient(0.99f) ; + sScape.setReverbOrder(10) ; + System.out.println("Dungeon med 0.99 10 200.0 "); + } + else if (lCount == 5) { + sScape.setReverbDelay(600.0f) ; + sScape.setReflectionCoefficient(0.33f) ; + sScape.setReverbOrder(7) ; + System.out.println("Dungeon lrg 0.33 7 600.0 "); + } + else if (lCount == 6) { + sScape.setReverbDelay(600.0f) ; + sScape.setReflectionCoefficient(1.0f) ; + sScape.setReverbOrder(20) ; + System.out.println("Cavern lrg 1.0 20 600.0 "); + } + psound.setEnable(true); + wakeupOn(wt); + } + + // + // Constructor for rotation behavior. Parameter: front and back Sound nodes + // + public AudioReverberate(PointSound psound, String filename, + AuralAttributes sscape) { + this.psound = psound; + this.fileName = filename; + this.sScape = sscape; + } +} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/MoveAppBoundingLeaf.java b/src/classes/org/jdesktop/j3d/examples/sound/MoveAppBoundingLeaf.java new file mode 100644 index 0000000..7de3b46 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/MoveAppBoundingLeaf.java @@ -0,0 +1,389 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package org.jdesktop.j3d.examples.sound; + +/* + * This Java3D program: + * Creates an instance of the JavaSoundMixer AudioDevice, initializing it + * and attaching it to the PhysicalEnvironment with a special version + * of UniverseBuilder (UniverseBuildJS). + * Creates one Point sound sources. + * Creates two Soundscapes with their own aural attributes. Each + * of these Soundscapes defines its own bounding leaf region. + * Creates and executes a custom behavior (AudioBehaviorMoveOne) that + * starts sound playing and transforms the AuralAttribute positions + * by modifying the TransformGroup that contains both soundscape + * nodes. + * Usage: java MoveAppBoundingLeaf [ URLpath [ name ]] + * + * The first optional command line parameter is the URL path to directory + * containing: + * (1) the files that will be named on the command line, or + * (2) the javaone/data/sounds directory that contains the default files + * If not given the default path is: + * file:/net/java3d/export/java3d/javaone/data/sounds + * NOTE: This default path is only valid on Solaris Eng Menlo Park network. + * A path must be supplied if sound files to be used are in a different + * directory location. + * NOTE: When running on Java3D Menlo Park Test WinTel platform path should + * be set to + * file:/java3d/export/java3d/javaone/data/sounds + * + * The second thru fourth optional command line parameters are sound file names + * If not given the default file name is: + * unicycle_close.au + */ + +import java.applet.Applet; +import java.net.URL; +import java.awt.*; +import java.awt.event.*; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.ColorCube; +import com.sun.j3d.utils.geometry.Sphere; +import com.sun.j3d.utils.universe.*; +import java.io.File; +import javax.media.j3d.*; +import javax.vecmath.*; + +public class MoveAppBoundingLeaf extends Applet { + + // File name of sound sample + private static int filenamesGiven = 0; + private static URL[] url = new URL[1]; + private static String[] filename = new String[1]; + private static String path = null; + private static boolean filenamesSet = false; + + private SimpleUniverse u = null; + + public BranchGroup createSceneGraph() { + // Create the root of the subgraph + BranchGroup objRoot = new BranchGroup(); + + // Create the transform group node and initialize it to the identity. + // Enable the TRANSFORM_WRITE capability so that our behavior code + // can modify it at runtime. Add it to the root of the subgraph. + TransformGroup objTrans = new TransformGroup(); + objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + objRoot.addChild(objTrans); + + // Create a simple shape leaf node and add it into the scene graph. + objTrans.addChild(new ColorCube(0.7)); + + // Create a new Behavior object that will perform the desired + // operation on the specified transform object and add it into the + // scene graph. + Transform3D yAxis = new Transform3D(); + Alpha rotation = new Alpha(-1, Alpha.INCREASING_ENABLE, + 0, 0, + 20000, 0, 0, + 0, 0, 0); + RotationInterpolator rotator = + new RotationInterpolator(rotation, + objTrans, yAxis, + 0.0f, (float) Math.PI*2.0f); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + rotator.setSchedulingBounds(bounds); + objTrans.addChild(rotator); + // + // Create a sound node and add it to the scene graph + // + PointSound sound = new PointSound(); + sound.setCapability(PointSound.ALLOW_ENABLE_WRITE); + sound.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE); + sound.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE); + sound.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_WRITE); + sound.setCapability(PointSound.ALLOW_CONT_PLAY_WRITE); + sound.setCapability(PointSound.ALLOW_RELEASE_WRITE); + sound.setCapability(PointSound.ALLOW_DURATION_READ); + sound.setCapability(PointSound.ALLOW_IS_PLAYING_READ); + sound.setCapability(PointSound.ALLOW_POSITION_WRITE); + sound.setCapability(PointSound.ALLOW_LOOP_WRITE); + + BoundingSphere soundBounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + sound.setSchedulingBounds(soundBounds); + objTrans.addChild(sound); + + /* + * Spheres denoting aural attribute regions + */ + TransformGroup objTransChild1 = new TransformGroup(); + TransformGroup objTransChild2 = new TransformGroup(); + objTransChild1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + objTransChild2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + Transform3D translate1 = new Transform3D(); + Transform3D translate2 = new Transform3D(); + Vector3f vector1 = new Vector3f( 2.0f, 0.0f, 0.0f); + Vector3f vector2 = new Vector3f(-2.0f, 0.0f, 0.0f); + translate1.setTranslation(vector1); + translate2.setTranslation(vector2); + objTransChild1.setTransform(translate1); + objTransChild2.setTransform(translate2); + Sphere sphere1 = new Sphere(0.42f); + Sphere sphere2 = new Sphere(0.38f); + + Appearance app = new Appearance(); + app.setCapability( Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE ); + sphere1.setAppearance( app ); + sphere2.setAppearance( app ); + objTransChild1.addChild(sphere1); + objTransChild2.addChild(sphere2); + + objTrans.addChild(objTransChild1); + objTrans.addChild(objTransChild2); + /** + * Define Soundscapes/AuralAttributes + */ + // First Aural Attributes + Point2f[] distanceFilter = new Point2f[2]; + distanceFilter[0] = new Point2f(6.0f, 6000f); + distanceFilter[1] = new Point2f(17.0f, 700f); + AuralAttributes attributes = new AuralAttributes(1.0f, 2.0f, 0.3f, + 4.0f, 5, distanceFilter, 0.8f, 0.0f); + attributes.setReverbDelay(90.0f) ; + attributes.setReflectionCoefficient(0.999f) ; + attributes.setReverbOrder(9) ; + + // SoundScape + BoundingSphere bounds1 = + new BoundingSphere(new Point3d(2.0,0.0,0.0), 3.5); + + BoundingLeaf sScapeBounds1 = new BoundingLeaf(bounds1); + Soundscape soundScape = new Soundscape(null, attributes); + soundScape.setApplicationBoundingLeaf(sScapeBounds1); + /** addChild of BoundingLeaf as well**/ + objTrans.addChild(sScapeBounds1); + + AuralAttributes queryAttribs = new AuralAttributes(); + if (queryAttribs == null) + System.out.println(" new AuralAttributes returned NULL"); + // else + // System.out.println(" new AuralAttributes returned " + queryAttribs); + queryAttribs = soundScape.getAuralAttributes(); + if (queryAttribs == null) + System.out.println("getAuralAttributes returned NULL"); + // else + // System.out.println("AuralAttributes for Soundscape 1:"); + float tmpFloat = queryAttribs.getAttributeGain(); + // System.out.println(" Gain = " + tmpFloat); + tmpFloat = queryAttribs.getRolloff(); + // System.out.println(" Rolloff = " + tmpFloat); + tmpFloat = queryAttribs.getReflectionCoefficient(); + // System.out.println(" Reflection Coeff = " + tmpFloat); + tmpFloat = queryAttribs.getReverbDelay(); + // System.out.println(" Delay = " + tmpFloat); + int tmpInt = queryAttribs.getReverbOrder(); + // System.out.println(" Order = " + tmpInt); + int length = queryAttribs.getDistanceFilterLength(); + // System.out.println(" Filter length = " + length); + Point2f[] tmpPoint = new Point2f[length]; + tmpPoint = new Point2f[length]; + for (int i=0; i< length; i++) + tmpPoint[i] = new Point2f(); + queryAttribs.getDistanceFilter(tmpPoint); + // for (int i=0; i< length; i++) + // System.out.println(" Distance Filter = (" + tmpPoint[i].x + + // ", " + tmpPoint[i].y + ")" ); + tmpFloat = queryAttribs.getFrequencyScaleFactor(); + // System.out.println(" Freq scalefactor = " + tmpFloat); + tmpFloat = queryAttribs.getVelocityScaleFactor(); + // System.out.println(" Velocity scalefactor= " + tmpFloat); + objTrans.addChild(soundScape); + + // System.out.println("SoundScape2**********************************"); + Soundscape soundScape2 = new Soundscape(); + distanceFilter = new Point2f[2]; + distanceFilter[0] = new Point2f(2.0f, 20000.0f); + distanceFilter[1] = new Point2f(20.0f, 2000.0f); + AuralAttributes attributes2 = new AuralAttributes(); + attributes2.setAttributeGain(1.2f); + attributes2.setRolloff(2.2f); + attributes2.setReverbDelay(1313.0f) ; + attributes2.setReflectionCoefficient(1.0f) ; + attributes2.setReverbOrder(15) ; + distanceFilter[0] = new Point2f(5.0f, 15000.0f); + distanceFilter[1] = new Point2f(15.0f, 500.0f); + attributes2.setDistanceFilter(distanceFilter); + attributes2.setFrequencyScaleFactor(0.8f); + attributes2.setVelocityScaleFactor(0.0f); + BoundingSphere bounds2 = + new BoundingSphere(new Point3d(-2.0,0.0,0.0), 0.38); + BoundingLeaf sScapeBounds2 = new BoundingLeaf(bounds2); + soundScape2.setApplicationBoundingLeaf(sScapeBounds2); + // set BoundingLeaf as a child of transform node + objTrans.addChild(sScapeBounds2); + soundScape2.setAuralAttributes(attributes2); + + queryAttribs = soundScape2.getAuralAttributes(); + if (queryAttribs == null) + System.out.println(" new AuralAttributes returned NULL"); + // else + // System.out.println(" new AuralAttributes returned " + queryAttribs); + // System.out.println("AuralAttributes for Soundscape 2:"); + tmpFloat = queryAttribs.getAttributeGain(); + // System.out.println(" Gain = " + tmpFloat); + tmpFloat = queryAttribs.getRolloff(); + // System.out.println(" Rolloff = " + tmpFloat); + tmpFloat = queryAttribs.getReflectionCoefficient(); + // System.out.println(" Reflection Coeff = " + tmpFloat); + tmpFloat = queryAttribs.getReverbDelay(); + // System.out.println(" Delay = " + tmpFloat); + tmpInt = queryAttribs.getReverbOrder(); + // System.out.println(" Order = " + tmpInt); + length = queryAttribs.getDistanceFilterLength(); + // System.out.println(" Filter length = " + length); + tmpPoint = new Point2f[length]; + for (int i=0; i< length; i++) + tmpPoint[i] = new Point2f(); + queryAttribs.getDistanceFilter(tmpPoint); + // for (int i=0; i< length; i++) + // System.out.println(" Distance Filter = (" + tmpPoint[i].x + + // ", " + tmpPoint[i].y + ")" ); + tmpFloat = queryAttribs.getFrequencyScaleFactor(); + // System.out.println(" Freq scalefactor = " + tmpFloat); + tmpFloat = queryAttribs.getVelocityScaleFactor(); + // System.out.println(" Velocity scalefactor= " + tmpFloat); + objTrans.addChild(soundScape2); + + // + // Create a new Behavior object that will play the sound + // + AudioBehaviorMoveOne player = new AudioBehaviorMoveOne(sound, + filename[0]); + player.setSchedulingBounds(soundBounds); + objTrans.addChild(player); + + return objRoot; + } + + public MoveAppBoundingLeaf() { + } + + public void init() { + if (!filenamesSet) { + // path is null if started from applet + if (path == null) { + path = getCodeBase().toString(); + } + + /* + * append given file name to given URL path + */ + if (filenamesGiven > 0) { + filename[0] = new String(path + "/" + filename[0]); + } + else { + // fill in default file names if all three not given + filename[0] = new String(path + "/techno_machine.au"); + } + filenamesSet = true; + } + + setLayout(new BorderLayout()); + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + Canvas3D c = new Canvas3D(config); + add("Center", c); + + /* + * Change filenames into URLs + */ + String substr = filename[0].substring(0,4); + try { + url[0] = new URL(filename[0]); + } + catch (Exception e) { + return; + } + /* + * Create a simple scene and attach it to the virtual universe + */ + u = new SimpleUniverse(c); + AudioDevice audioDev = u.getViewer().createAudioDevice(); + BranchGroup scene = createSceneGraph(); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + u.getViewingPlatform().setNominalViewingTransform(); + + u.addBranchGraph(scene); + } + + public void destroy() { + u.cleanup(); + } + + // + // The following allows AuralAttributes to be run as an application + // as well as an applet + // + public static void main(String[] args) { + if (args.length > 0) { + if ( (args[0].startsWith("file"+File.pathSeparator)) || + (args[0].startsWith("http"+File.pathSeparator)) ) { + path = args[0]; + } + else { + path = "file:" + args[0]; + } + } + else { + path = "file:."; + } + + if (args.length > 1) { + filename[0] = args[1]; + if (filename[0] != null) { + filenamesGiven++ ; + } + } + + new MainFrame(new MoveAppBoundingLeaf(), 256, 256); + } +} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/ReverberateSound.java b/src/classes/org/jdesktop/j3d/examples/sound/ReverberateSound.java new file mode 100644 index 0000000..ad6a2e3 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/ReverberateSound.java @@ -0,0 +1,222 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package org.jdesktop.j3d.examples.sound; + +/* + * ReverberateSound + * + * Same as MoveSound except this calls UniverseBuilderJS to use the + * JavaSoundMixer AudioDevice rather than the HolosketchMixer device. + * + * NOTE: To run this anywhere but the Solaris Eng Menlo Park network + * the URL path must be set to the java3d/javaone directory. + */ + +import java.applet.Applet; +import java.awt.*; +import java.awt.event.*; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.ColorCube; +import com.sun.j3d.utils.universe.*; +import java.io.File; +import javax.media.j3d.*; +import javax.vecmath.*; + +public class ReverberateSound extends Applet { + + // File name of sound sample + private static String[] filename = new String[1]; + private static String path = null; + private static int filenamesGiven = 0; + private static boolean filenamesSet = false; + + private SimpleUniverse u = null; + + public BranchGroup createSceneGraph() { + // Create the root of the subgraph + BranchGroup objRoot = new BranchGroup(); + + // Create the transform group node and initialize it to the identity. + // Enable the TRANSFORM_WRITE capability so that our behavior code + // can modify it at runtime. Add it to the root of the subgraph. + TransformGroup objTrans = new TransformGroup(); + objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + objRoot.addChild(objTrans); + + // Create a simple shape leaf node and add it into the scene graph. + objTrans.addChild(new ColorCube(0.4)); + + // Create a new Behavior object that will perform the desired + // operation on the specified transform object and add it into the + // scene graph. + Transform3D yAxis = new Transform3D(); + Alpha rotation = new Alpha(-1, Alpha.INCREASING_ENABLE, + 0, 0, + 20000, 0, 0, + 0, 0, 0); + RotationInterpolator rotator = + new RotationInterpolator(rotation, + objTrans, yAxis, + 0.0f, (float) Math.PI*2.0f); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + rotator.setSchedulingBounds(bounds); + objTrans.addChild(rotator); + + // + // Create an AuralAttribute with reverb params set + // + Soundscape soundScape2 = new Soundscape(); + AuralAttributes attributes2 = new AuralAttributes(); + attributes2.setReverbOrder(6); + attributes2.setCapability(AuralAttributes.ALLOW_REVERB_ORDER_WRITE); + attributes2.setCapability(AuralAttributes.ALLOW_REVERB_DELAY_WRITE); + attributes2.setCapability(AuralAttributes.ALLOW_REFLECTION_COEFFICIENT_WRITE); + soundScape2.setApplicationBounds(bounds); + soundScape2.setAuralAttributes(attributes2); + objRoot.addChild(soundScape2); + + // + // Create a sound node and add it to the scene graph + // + PointSound sound = new PointSound(); + sound.setCapability(PointSound.ALLOW_ENABLE_WRITE); + sound.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE); + sound.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE); + sound.setCapability(PointSound.ALLOW_DURATION_READ); + sound.setCapability(PointSound.ALLOW_POSITION_WRITE); + sound.setCapability(PointSound.ALLOW_LOOP_WRITE); + sound.setSchedulingBounds(bounds); + + objTrans.addChild(sound); + // + // Create a new Behavior object that will play the sound + // + AudioReverberate player = new AudioReverberate(sound, filename[0], + attributes2); + player.setSchedulingBounds(bounds); + objTrans.addChild(player); + + + return objRoot; + } + + public ReverberateSound() { + } + + public void init() { + if (!filenamesSet) { + // path is null if started from applet + if (path == null) { + // the path for an applet + path = getCodeBase().toString(); + } + + /* + * append given file name to given URL path + */ + if (filenamesGiven > 0) { + filename[0] = new String(path + "/" + filename[0]); + } + else { + // fill in default file names if all three not given + filename[0] = new String(path + "/hello_universe.au"); + } + filenamesSet = true; + } + + setLayout(new BorderLayout()); + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + Canvas3D c = new Canvas3D(config); + add("Center", c); + + /* + * Create a simple scene and attach it to the virtual universe + */ + u = new SimpleUniverse(c); + AudioDevice audioDev = u.getViewer().createAudioDevice(); + BranchGroup scene = createSceneGraph(); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + u.getViewingPlatform().setNominalViewingTransform(); + + u.addBranchGraph(scene); + } + + public void destroy() { + u.cleanup(); + } + + // + // The following allows ReverberateSound to be run as an application + // as well as an applet + // + public static void main(String[] args) { + if (args.length > 0) { + if ( (args[0].startsWith("file"+File.pathSeparator)) || + (args[0].startsWith("http"+File.pathSeparator)) ) { + path = args[0]; + } + else { + path = "file:" + args[0]; + } + } + else { + path = "file:."; + } + + if (args.length > 1) { + filename[0] = args[1]; + if (filename[0] != null) { + filenamesGiven++ ; + } + } + + new MainFrame(new ReverberateSound(), 256, 256); + } +} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/SimpleSounds.java b/src/classes/org/jdesktop/j3d/examples/sound/SimpleSounds.java new file mode 100644 index 0000000..d7c8c49 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/SimpleSounds.java @@ -0,0 +1,294 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package org.jdesktop.j3d.examples.sound; + +import java.applet.Applet; +import java.net.URL; +import java.awt.*; +import java.awt.event.*; +import com.sun.j3d.utils.applet.MainFrame; +import com.sun.j3d.utils.geometry.ColorCube; +import com.sun.j3d.utils.universe.*; +import java.io.File; +import java.security.*; +import javax.media.j3d.*; +import javax.vecmath.*; + +/* + * This Java3D program: + * Creates an instance of the JavaSoundMixer AudioDevice, initializing it + * and attaching it to the PhysicalEnvironment by using + * SimpleUniverse. + * Creates one cached Background and two cached Point sound sources. + * Creates and executes a custom behavior (SimpleSoundsBehavior) that + * starts the sound playing and transforms the PointSound source + * by modifying the TransformGroup that contains the Sound nodes. + * + * Usage: + * java SimpleSounds [URLpath [name1 [name2 [name2]]]] + * + * The first optional command line parameter is the URL path to directory + * containing "file:" or "http:" and then directory path string. + * If you are using the suppled default sound files in the same directory + * as this test program then only the URLpath need be supplied on the + * command line. + * If this parameter is not included then the current path to the directory + * this program is running in is used for an application + * and the codebase is used for an applet. + * The second thru fourth optional command line parameters are sound file names + * If not given, the default file names are: + * techno_machine.au + * hello_universe.au + * roar.au + * that correspond to the 3 'voice' quality, 8-bit, u-law, 8-kHz samples + * included in the same directory as this test program. + * + * Java Sound engine has been advertised to support the following 8- and 16- + * bit, linear and u-law, mono and stereo sound sample file formats: AU, + * AIFF, WAV, and PCM. Non-cached MIDI and RMF files are also supported. + * Neither compressed formats (DVI, GSM, MOD) nor A-law formated files are + * supported at this time, but they will be converted. + */ + +public class SimpleSounds extends Applet { + + // File name of sound sample + private static int filenamesGiven = 0; + private static URL[] url = new URL[3]; + private static String[] filename = new String[3]; + private static String path = null; + private static boolean filenamesSet = false; + + private SimpleUniverse u = null; + + public BranchGroup createSceneGraph() { + // Create the root of the subgraph + BranchGroup objRoot = new BranchGroup(); + + // Create the transform group node and initialize it to the identity. + // Enable the TRANSFORM_WRITE capability so that our behavior code + // can modify it at runtime. Add it to the root of the subgraph. + TransformGroup objTrans = new TransformGroup(); + objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); + objRoot.addChild(objTrans); + + // Create a simple shape leaf node and add it into the scene graph. + objTrans.addChild(new ColorCube(0.4)); + + // Create a new Behavior object that will perform the desired + // operation on the specified transform object and add it into the + // scene graph. + Transform3D yAxis = new Transform3D(); + Alpha rotation = new Alpha(-1, Alpha.INCREASING_ENABLE, + 0, 0, + 20000, 0, 0, + 0, 0, 0); + RotationInterpolator rotator = + new RotationInterpolator(rotation, + objTrans, yAxis, + 0.0f, (float) Math.PI*2.0f); + BoundingSphere bounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + rotator.setSchedulingBounds(bounds); + objTrans.addChild(rotator); + /* + * Create a sound node and add it to the scene graph + */ + BackgroundSound sound1 = new BackgroundSound(); + PointSound sound2 = new PointSound(); + PointSound sound3 = new PointSound(); + sound1.setCapability(PointSound.ALLOW_ENABLE_WRITE); + sound1.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE); + sound1.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE); + sound1.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_WRITE); + sound1.setCapability(PointSound.ALLOW_CONT_PLAY_WRITE); + sound1.setCapability(PointSound.ALLOW_RELEASE_WRITE); + sound1.setCapability(PointSound.ALLOW_DURATION_READ); + sound1.setCapability(PointSound.ALLOW_IS_PLAYING_READ); + sound1.setCapability(PointSound.ALLOW_LOOP_WRITE); + sound2.setCapability(PointSound.ALLOW_ENABLE_WRITE); + sound2.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE); + sound2.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE); + sound2.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_WRITE); + sound2.setCapability(PointSound.ALLOW_CONT_PLAY_WRITE); + sound2.setCapability(PointSound.ALLOW_RELEASE_WRITE); + sound2.setCapability(PointSound.ALLOW_DURATION_READ); + sound2.setCapability(PointSound.ALLOW_IS_PLAYING_READ); + sound2.setCapability(PointSound.ALLOW_POSITION_WRITE); + sound2.setCapability(PointSound.ALLOW_LOOP_WRITE); + sound3.setCapability(PointSound.ALLOW_ENABLE_WRITE); + sound3.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE); + sound3.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE); + sound3.setCapability(PointSound.ALLOW_SCHEDULING_BOUNDS_WRITE); + sound3.setCapability(PointSound.ALLOW_CONT_PLAY_WRITE); + sound3.setCapability(PointSound.ALLOW_RELEASE_WRITE); + sound3.setCapability(PointSound.ALLOW_DURATION_READ); + sound3.setCapability(PointSound.ALLOW_IS_PLAYING_READ); + sound3.setCapability(PointSound.ALLOW_POSITION_WRITE); + + BoundingSphere soundBounds = + new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + sound1.setSchedulingBounds(soundBounds); + sound2.setSchedulingBounds(soundBounds); + sound3.setSchedulingBounds(soundBounds); + objTrans.addChild(sound1); + objTrans.addChild(sound2); + objTrans.addChild(sound3); + + + /* + * Create a new Behavior object that will play the sound + */ + SimpleSoundsBehavior player = new SimpleSoundsBehavior( + sound1, sound2, sound3, + url[0], url[1], url[2], soundBounds); + player.setSchedulingBounds(soundBounds); + objTrans.addChild(player); + + // Let Java 3D perform optimizations on this scene graph. + objRoot.compile(); + + return objRoot; + } + + public SimpleSounds() { + } + + public void init() { + if (!filenamesSet) { + // path is null if started from appletviewer/browser + if (path == null) { + // the path for an applet + path = getCodeBase().toString(); + } + int j; + /* + * append given file name to given URL path + */ + for (j=0; j<filenamesGiven; j++) + filename[j] = new String(path + "/" + filename[j]); + /* + * fill in default file names if all three not given + */ + for (int i=j; i<3; i++) { + if (i == 0) + filename[0] = new String(path + "/techno_machine.au"); + if (i == 1) + filename[1] = new String(path + "/hello_universe.au"); + if (i == 2) + filename[2] = new String(path + "/roar.au"); + } + filenamesSet = true; + } + + setLayout(new BorderLayout()); + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); + + Canvas3D c = new Canvas3D(config); + add("Center", c); + + /* + * Change filenames into URLs + */ + for (int i=0; i<3; i++) { + try { + url[i] = new URL(filename[i]); + } + catch (Exception e) { + System.out.println(e.getMessage()); + return; + } + } + + /* + * Create a simple scene and attach it to the virtual universe + */ + u = new SimpleUniverse(c); + AudioDevice audioDev = u.getViewer().createAudioDevice(); + BranchGroup scene = createSceneGraph(); + + // This will move the ViewPlatform back a bit so the + // objects in the scene can be viewed. + u.getViewingPlatform().setNominalViewingTransform(); + + u.addBranchGraph(scene); + } + + public void destroy() { + u.cleanup(); + } + + /* + * The following allows SimpleSounds to be run as an application + * as well as an applet + */ + public static void main(String[] args) { + if (args.length > 0) { + if ( (args[0].startsWith("file"+File.pathSeparator)) || + (args[0].startsWith("http"+File.pathSeparator)) ) { + path = args[0]; + } + else { + path = "file:" + args[0]; + } + } + else { + path = "file:."; + } + + for (int i=0; i<3; i++) { + if (args.length > (i+1)) { + filename[i] = args[i+1]; + if (filename[i] != null) { + filenamesGiven++ ; + } + } + else + break; + } + new MainFrame(new SimpleSounds(), args, 256, 256); + } +} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/SimpleSoundsBehavior.java b/src/classes/org/jdesktop/j3d/examples/sound/SimpleSoundsBehavior.java new file mode 100644 index 0000000..862881f --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/SimpleSoundsBehavior.java @@ -0,0 +1,179 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2006 Sun Microsystems, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution 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. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any + * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND + * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY + * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL + * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF + * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR + * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, + * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND + * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR + * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed, licensed or + * intended for use in the design, construction, operation or + * maintenance of any nuclear facility. + * + * $Revision$ + * $Date$ + * $State$ + */ + +package org.jdesktop.j3d.examples.sound; + +import javax.media.j3d.*; +import javax.vecmath.*; +import java.net.URL; +import java.util.Enumeration; + +// User defined audio behavior class +public class SimpleSoundsBehavior extends Behavior { + WakeupOnElapsedTime wt; + WakeupOnBehaviorPost wp; + BackgroundSound sound1 = new BackgroundSound(); + PointSound sound2 = new PointSound(); + PointSound sound3 = new PointSound(); + static int WAKEUP_SOUND = 0; + int soundIndex = 0; + URL URLName1; + URL URLName2; + URL URLName3; + BoundingSphere bounds; + + // Override Behavior's initialize method to setup wakeup criteria + public void initialize() { + MediaContainer sample1 = new MediaContainer(); + MediaContainer sample2 = new MediaContainer(); + MediaContainer sample3 = new MediaContainer(); + sample1.setCapability(MediaContainer.ALLOW_URL_WRITE); + sample1.setCapability(MediaContainer.ALLOW_URL_READ); + sample1.setURLObject(URLName1); + //sample1.setCacheEnable(false); + sound1.setLoop(0); + sound1.setContinuousEnable(false); + sound1.setReleaseEnable(false); + sound1.setSoundData(sample1); + sound1.setInitialGain(0.7f); + sample2.setCapability(MediaContainer.ALLOW_URL_WRITE); + sample2.setCapability(MediaContainer.ALLOW_URL_READ); + sample2.setURLObject(URLName2); + sound2.setLoop(Sound.INFINITE_LOOPS); + sound2.setContinuousEnable(false); + sound2.setReleaseEnable(false); + sound2.setSoundData(sample2); + sound2.setInitialGain(2.0f); + Point3f sound2Pos = new Point3f(-30.0f, 0.0f, 0.0f); + sound2.setPosition(sound2Pos); + sample3.setCapability(MediaContainer.ALLOW_URL_WRITE); + sample3.setCapability(MediaContainer.ALLOW_URL_READ); + sample3.setURLObject(URLName3); + sound3.setContinuousEnable(false); + sound3.setReleaseEnable(false); + sound3.setSoundData(sample3); + sound3.setInitialGain(4.0f); + Point3f sound3Pos = new Point3f(30.0f, 0.0f, 0.0f); + sound3.setPosition(sound3Pos); + + wt = new WakeupOnElapsedTime(2000); + WakeupOnElapsedTime wp = new WakeupOnElapsedTime(5000); + wakeupOn(wp); + } + + // Override Behavior's stimulus method to handle the event + public void processStimulus(Enumeration criteria) { + + switch (soundIndex) + { + // Active + case 0: + // System.out.println("****Enable First Sound"); + sound1.setEnable(true); + wakeupOn(wt); + break; + case 1: + // System.out.println("********Enable Second Sound"); + sound2.setEnable(true); + wakeupOn(wt); + break; + case 2: + case 4: + case 6: + case 8: + case 10: + // System.out.println("************Enable Third Sound"); + sound3.setEnable(true); + wakeupOn(wt); + break; + case 3: + case 5: + case 7: + case 9: + // System.out.println("************Disable Third Sound"); + sound3.setEnable(false); + wakeupOn(wt); + break; + + case 11: + // System.out.println("********Disable Second Sound"); + sound2.setEnable(false) ; + wakeupOn(wt); + break; + case 12: + // System.out.println("****Disable First Sound"); + sound1.setEnable(false) ; + System.out.println("SimpleSounds: test complete"); + wt = new WakeupOnElapsedTime(400000); + wakeupOn(wt); + break; + + default: + break; + } + soundIndex++; + } + + // + // Constructor for rotation behavior. + // Parameters: sound node + // sample file name + // sound node's bounds + // + public SimpleSoundsBehavior(BackgroundSound sound1, + PointSound sound2, + PointSound sound3, + URL urlName1, + URL urlName2, + URL urlName3, + BoundingSphere soundBounds) { + this.sound1 = sound1; + this.sound2 = sound2; + this.sound3 = sound3; + this.URLName1 = urlName1; + this.URLName2 = urlName2; + this.URLName3 = urlName3; + this.bounds = (BoundingSphere)soundBounds.clone(); + } +} |