001: /*
002: * $RCSfile: AudioReverberate.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: import java.net.URL;
048: import javax.media.j3d.*;
049: import javax.vecmath.*;
050: import java.util.Enumeration;
051:
052: /*
053: * Pick the JavaSound reverb type that matches the input parameters
054: * as best as possible.
055: *
056: * Hae Reverb Types Size Persistance Delay
057: * ================ ----------- ------------ -----------
058: * 1 None (dry)
059: * 2 "Closet" very small very short <.5 fast smooth
060: * 3 "Garage" med. large medium 1.0 medium
061: * 4 "Acoustic Lab" med. small short .5 med. fast
062: * 5 "Cavern" large long >2.0 very slow
063: * 6 "Dungeon" medium med. long 1.5 med. slow
064: *
065: *
066: * Order is NOT controllable, nor does it have a natural parallel.
067: * For this reason Order and Reflection are tied together as to
068: * affect 'Decay Speed'. This speed paired with the size of the
069: * space implied by the Delay parameter determine the JavaSound
070: * Reverb type that is set:
071: *
072: * | Short: Long:
073: * Speed | Coeff <= 0.9 Coeff > 0.9
074: * Size | Order <= 8 Order > 8
075: * ---------------------------------------------------------------
076: * small (<100ms) | 2 "Closet" 4 "Acoustic Lab"
077: * medium (<500ms) | 3 "Garage" 6 "Dungeon"
078: * large (>500ms) | 6 "Dungeon" 5 "Cavern"
079: */
080: // User defined audio behavior class
081: public class AudioReverberate extends Behavior {
082: WakeupOnElapsedTime wt;
083: WakeupOnBehaviorPost wp;
084: PointSound psound = new PointSound();
085: AuralAttributes sScape = null;
086: static int WAKEUP_SOUND = 0;
087: long dur;
088: long time;
089: boolean firstTime = true;
090: URL url = null;
091: int lCount = 0;
092: int loopCount = 0;
093:
094: // Override Behavior's initialize method to setup wakeup criteria
095: public void initialize() {
096: MediaContainer sample = new MediaContainer();
097: sample.setCacheEnable(true);
098: sample.setURLObject(url);
099: psound.setSoundData(sample);
100: Point3f soundPos = new Point3f(-23.0f, 0.0f, 0.0f);
101: psound.setPosition(soundPos);
102: psound.setLoop(3);
103: firstTime = true;
104: System.out.println("Reverb Name Size Reflect Order Delay ");
105: System.out.println("----------- ---- ------- ----- ----- ");
106: WakeupOnElapsedTime wp = new WakeupOnElapsedTime(5000);
107: wakeupOn(wp);
108: }
109:
110: // Override Behavior's stimulus method to handle the event
111: public void processStimulus(Enumeration criteria) {
112: // time = System.currentTimeMillis();
113: if (firstTime) {
114: wt = new WakeupOnElapsedTime(10000);
115: firstTime = false;
116: } else
117: psound.setEnable(false);
118:
119: if (++lCount > 6)
120: lCount = 1;
121:
122: if (lCount == 1) {
123: sScape.setReverbDelay(10.0f);
124: sScape.setReflectionCoefficient(0.5f);
125: sScape.setReverbOrder(5);
126: System.out
127: .println("Closet sm 0.5 5 10.0 ");
128: } else if (lCount == 2) {
129: sScape.setReverbDelay(10.0f);
130: sScape.setReflectionCoefficient(0.999f);
131: sScape.setReverbOrder(9);
132: System.out
133: .println("Acoustic Lab sm 0.999 9 10.0 ");
134: } else if (lCount == 3) {
135: sScape.setReverbDelay(200.0f);
136: sScape.setReflectionCoefficient(0.4f);
137: sScape.setReverbOrder(3);
138: System.out
139: .println("Garage med 0.4 3 200.0 ");
140: } else if (lCount == 4) {
141: sScape.setReverbDelay(200.0f);
142: sScape.setReflectionCoefficient(0.99f);
143: sScape.setReverbOrder(10);
144: System.out
145: .println("Dungeon med 0.99 10 200.0 ");
146: } else if (lCount == 5) {
147: sScape.setReverbDelay(600.0f);
148: sScape.setReflectionCoefficient(0.33f);
149: sScape.setReverbOrder(7);
150: System.out
151: .println("Dungeon lrg 0.33 7 600.0 ");
152: } else if (lCount == 6) {
153: sScape.setReverbDelay(600.0f);
154: sScape.setReflectionCoefficient(1.0f);
155: sScape.setReverbOrder(20);
156: System.out
157: .println("Cavern lrg 1.0 20 600.0 ");
158: }
159: psound.setEnable(true);
160: wakeupOn(wt);
161: }
162:
163: //
164: // Constructor for rotation behavior. Parameter: front and back Sound nodes
165: //
166: public AudioReverberate(PointSound psound, URL url,
167: AuralAttributes sscape) {
168: this.psound = psound;
169: this.url = url;
170: this.sScape = sscape;
171: }
172: }
|