001: /*
002: * $RCSfile: ReverberateSound.java,v $
003: *
004: * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * - Redistribution of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * - Redistribution in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * Neither the name of Sun Microsystems, Inc. or the names of
019: * contributors may be used to endorse or promote products derived
020: * from this software without specific prior written permission.
021: *
022: * This software is provided "AS IS," without a warranty of any
023: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
024: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
025: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
026: * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL
027: * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF
028: * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
029: * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR
030: * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
031: * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
032: * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
033: * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
034: * POSSIBILITY OF SUCH DAMAGES.
035: *
036: * You acknowledge that this software is not designed, licensed or
037: * intended for use in the design, construction, operation or
038: * maintenance of any nuclear facility.
039: *
040: * $Revision: 1.3 $
041: * $Date: 2007/02/09 17:21:51 $
042: * $State: Exp $
043: */
044:
045: package org.jdesktop.j3d.examples.sound;
046:
047: /*
048: * ReverberateSound
049: *
050: * Same as MoveSound except this calls UniverseBuilderJS to use the
051: * JavaSoundMixer AudioDevice rather than the HolosketchMixer device.
052: *
053: * NOTE: To run this anywhere but the Solaris Eng Menlo Park network
054: * the URL path must be set to the java3d/javaone directory.
055: */
056:
057: import java.applet.Applet;
058: import java.awt.*;
059: import com.sun.j3d.utils.applet.MainFrame;
060: import com.sun.j3d.utils.geometry.ColorCube;
061: import com.sun.j3d.utils.universe.*;
062: import java.net.URL;
063: import javax.media.j3d.*;
064: import javax.swing.JOptionPane;
065: import javax.vecmath.*;
066: import org.jdesktop.j3d.examples.Resources;
067:
068: public class ReverberateSound extends Applet {
069:
070: // File name of sound sample
071: private static URL url = null;
072: private SimpleUniverse u = null;
073:
074: public BranchGroup createSceneGraph() {
075: // Create the root of the subgraph
076: BranchGroup objRoot = new BranchGroup();
077:
078: // Create the transform group node and initialize it to the identity.
079: // Enable the TRANSFORM_WRITE capability so that our behavior code
080: // can modify it at runtime. Add it to the root of the subgraph.
081: TransformGroup objTrans = new TransformGroup();
082: objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
083: objRoot.addChild(objTrans);
084:
085: // Create a simple shape leaf node and add it into the scene graph.
086: objTrans.addChild(new ColorCube(0.4));
087:
088: // Create a new Behavior object that will perform the desired
089: // operation on the specified transform object and add it into the
090: // scene graph.
091: Transform3D yAxis = new Transform3D();
092: Alpha rotation = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0,
093: 20000, 0, 0, 0, 0, 0);
094: RotationInterpolator rotator = new RotationInterpolator(
095: rotation, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
096: BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,
097: 0.0, 0.0), 100.0);
098: rotator.setSchedulingBounds(bounds);
099: objTrans.addChild(rotator);
100:
101: //
102: // Create an AuralAttribute with reverb params set
103: //
104: Soundscape soundScape2 = new Soundscape();
105: AuralAttributes attributes2 = new AuralAttributes();
106: attributes2.setReverbOrder(6);
107: attributes2
108: .setCapability(AuralAttributes.ALLOW_REVERB_ORDER_WRITE);
109: attributes2
110: .setCapability(AuralAttributes.ALLOW_REVERB_DELAY_WRITE);
111: attributes2
112: .setCapability(AuralAttributes.ALLOW_REFLECTION_COEFFICIENT_WRITE);
113: soundScape2.setApplicationBounds(bounds);
114: soundScape2.setAuralAttributes(attributes2);
115: objRoot.addChild(soundScape2);
116:
117: //
118: // Create a sound node and add it to the scene graph
119: //
120: PointSound sound = new PointSound();
121: sound.setCapability(PointSound.ALLOW_ENABLE_WRITE);
122: sound.setCapability(PointSound.ALLOW_INITIAL_GAIN_WRITE);
123: sound.setCapability(PointSound.ALLOW_SOUND_DATA_WRITE);
124: sound.setCapability(PointSound.ALLOW_DURATION_READ);
125: sound.setCapability(PointSound.ALLOW_POSITION_WRITE);
126: sound.setCapability(PointSound.ALLOW_LOOP_WRITE);
127: sound.setSchedulingBounds(bounds);
128:
129: objTrans.addChild(sound);
130: //
131: // Create a new Behavior object that will play the sound
132: //
133: AudioReverberate player = new AudioReverberate(sound, url,
134: attributes2);
135: player.setSchedulingBounds(bounds);
136: objTrans.addChild(player);
137:
138: return objRoot;
139: }
140:
141: public ReverberateSound() {
142: }
143:
144: public void init() {
145: url = Resources
146: .getResource("resources/audio/hello_universe.au");
147: if (url == null) {
148: System.err
149: .println("resources/audio/hello_universe.au not found");
150: System.exit(1);
151: }
152:
153: setLayout(new BorderLayout());
154: GraphicsConfiguration config = SimpleUniverse
155: .getPreferredConfiguration();
156:
157: Canvas3D c = new Canvas3D(config);
158: add("Center", c);
159:
160: /*
161: * Create a simple scene and attach it to the virtual universe
162: */
163: u = new SimpleUniverse(c);
164: AudioDevice audioDev = u.getViewer().createAudioDevice();
165: BranchGroup scene = createSceneGraph();
166:
167: // This will move the ViewPlatform back a bit so the
168: // objects in the scene can be viewed.
169: u.getViewingPlatform().setNominalViewingTransform();
170:
171: u.addBranchGraph(scene);
172:
173: JOptionPane.showMessageDialog(this ,
174: ("This program is still a work in progress.\n"
175: + "Please check back in Java 3D 1.5.\n"),
176: "Incomplete Work", JOptionPane.INFORMATION_MESSAGE);
177: }
178:
179: public void destroy() {
180: u.cleanup();
181: }
182:
183: //
184: // The following allows ReverberateSound to be run as an application
185: // as well as an applet
186: //
187: public static void main(String[] args) {
188: new MainFrame(new ReverberateSound(), 256, 256);
189: }
190: }
|