From 7e9009fea6bcab18ccaa7db6a14423e2814f1884 Mon Sep 17 00:00:00 2001 From: jada Date: Fri, 9 Feb 2007 18:10:27 +0000 Subject: Ported some earlier version of Sound examples, in the j3d-incubator project, contributed by David Grace (dave@dutchie.net). --- .../examples/sound/BackgroundSoundBehavior.java | 79 ++++++ .../j3d/examples/sound/BackgroundSoundTest.form | 37 +++ .../j3d/examples/sound/BackgroundSoundTest.java | 271 +++++++++++++++++++ .../j3d/examples/sound/PointSoundBehavior.java | 82 ++++++ .../j3d/examples/sound/PointSoundTest.form | 37 +++ .../j3d/examples/sound/PointSoundTest.java | 298 +++++++++++++++++++++ src/resources/audio/magic_bells.wav | Bin 0 -> 295252 bytes 7 files changed, 804 insertions(+) create mode 100644 src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundBehavior.java create mode 100644 src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundTest.form create mode 100644 src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundTest.java create mode 100644 src/classes/org/jdesktop/j3d/examples/sound/PointSoundBehavior.java create mode 100644 src/classes/org/jdesktop/j3d/examples/sound/PointSoundTest.form create mode 100644 src/classes/org/jdesktop/j3d/examples/sound/PointSoundTest.java create mode 100644 src/resources/audio/magic_bells.wav diff --git a/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundBehavior.java b/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundBehavior.java new file mode 100644 index 0000000..9f421fe --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundBehavior.java @@ -0,0 +1,79 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2007 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.net.URL; +import java.util.Enumeration; +import javax.media.j3d.*; +import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; + +public class BackgroundSoundBehavior extends Behavior { + + private WakeupCondition condition = new WakeupOnElapsedFrames(0); + + /** Creates a new instance of BackgroundSoundBehavior */ + public BackgroundSoundBehavior(BackgroundSound bgs, URL url) { + + Bounds b = new BoundingSphere(new Point3d(), 20); + bgs.setSoundData(new MediaContainer(url)); + bgs.setEnable(true); + bgs.setPause(false); + bgs.setLoop(-1); + bgs.setContinuousEnable(true); + bgs.setSchedulingBounds(b); + + } + + public void initialize() { + + wakeupOn(condition); + } + + public void processStimulus(Enumeration enumeration) { + wakeupOn(condition); + } + +} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundTest.form b/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundTest.form new file mode 100644 index 0000000..9a2f209 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundTest.form @@ -0,0 +1,37 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundTest.java b/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundTest.java new file mode 100644 index 0000000..a21759c --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/BackgroundSoundTest.java @@ -0,0 +1,271 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2007 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 com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior; +import com.sun.j3d.utils.geometry.Sphere; +import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; +import java.net.URL; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JFrame; +import javax.media.j3d.*; +import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; + +/** + * This is a test for a BackgroundSound. + * This program is ported from an earlier version of BackgroundSoundTest, in the j3d-incubator project, + * contributed by David Grace (dave@dutchie.net). + * + */ +public class BackgroundSoundTest extends javax.swing.JFrame { + + private URL url = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; + + //The activation radius for the ViewPlatform + private float activationRadius = 1; + + private Shape3D getDefaultGrid(int noOfLines, double size, double height){ + + Shape3D shape = new Shape3D(); + double lineLength = noOfLines * size / 2; + LineArray la = new LineArray(noOfLines * 4, LineArray.COORDINATES); + int count = 0; + for (int i=0; i//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("BackgroundSoundTest"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(800, 600)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new BackgroundSoundTest().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/PointSoundBehavior.java b/src/classes/org/jdesktop/j3d/examples/sound/PointSoundBehavior.java new file mode 100644 index 0000000..beea15c --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/PointSoundBehavior.java @@ -0,0 +1,82 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2007 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.net.URL; +import java.util.Enumeration; +import javax.media.j3d.*; +import javax.vecmath.*; +import org.jdesktop.j3d.examples.Resources; + +public class PointSoundBehavior extends Behavior { + + private WakeupCondition condition = new WakeupOnElapsedFrames(0); + + /** Creates a new instance of PointSoundBehavior */ + public PointSoundBehavior(PointSound ps, URL url, Point3f pos) { + + Bounds b = new BoundingSphere(new Point3d(), 40); + ps.setSoundData(new MediaContainer(url)); + ps.setPosition(pos); + float distanceAtZero = 30; + ps.setDistanceGain(new float []{0, distanceAtZero}, new float []{1, 0}); + ps.setEnable(true); + ps.setPause(false); + ps.setContinuousEnable(true); + ps.setSchedulingBounds(b); + ps.setLoop(-1); + + } + + public void initialize() { + + wakeupOn(condition); + } + + public void processStimulus(Enumeration enumeration) { + wakeupOn(condition); + } + +} diff --git a/src/classes/org/jdesktop/j3d/examples/sound/PointSoundTest.form b/src/classes/org/jdesktop/j3d/examples/sound/PointSoundTest.form new file mode 100644 index 0000000..41f5f7d --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/PointSoundTest.form @@ -0,0 +1,37 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/classes/org/jdesktop/j3d/examples/sound/PointSoundTest.java b/src/classes/org/jdesktop/j3d/examples/sound/PointSoundTest.java new file mode 100644 index 0000000..fd62169 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/sound/PointSoundTest.java @@ -0,0 +1,298 @@ +/* + * $RCSfile$ + * + * Copyright (c) 2007 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 com.sun.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior; +import com.sun.j3d.utils.geometry.Sphere; +import com.sun.j3d.utils.universe.*; +import com.sun.j3d.utils.geometry.ColorCube; +import java.net.URL; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JFrame; +import javax.media.j3d.*; +import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import org.jdesktop.j3d.examples.Resources; + +/** + * This is a test for a PointSound. + * This program is ported from an earlier version of PointSoundTest, in the j3d-incubator project, + * contributed by David Grace (dave@dutchie.net). + * + */ +public class PointSoundTest extends javax.swing.JFrame { + + private URL url = null; + private SimpleUniverse univ = null; + private BranchGroup scene = null; + + //The activation radius for the ViewPlatform + private float activationRadius = 1; + + private Shape3D getDefaultGrid(int noOfLines, double size, double height){ + + Shape3D shape = new Shape3D(); + double lineLength = noOfLines * size / 2; + LineArray la = new LineArray(noOfLines * 4, LineArray.COORDINATES); + int count = 0; + for (int i=0; i//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("PointSound Test"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(800, 600)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + new PointSoundTest().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + +} diff --git a/src/resources/audio/magic_bells.wav b/src/resources/audio/magic_bells.wav new file mode 100644 index 0000000..f89a7fd Binary files /dev/null and b/src/resources/audio/magic_bells.wav differ -- cgit v1.2.3