001: /*
002: * $RCSfile: DistanceAttenuation.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.4 $
041: * $Date: 2007/02/09 17:20:11 $
042: * $State: Exp $
043: */
044:
045: /*
046: * Sound Distance Attenuation utilities
047: *
048: * Various methods to create PointSound and ConeSound distance attenuation
049: * arrays.
050: */
051:
052: package com.sun.j3d.utils.audio;
053:
054: import java.io.*;
055: import javax.vecmath.*;
056: import java.lang.String;
057: import javax.media.j3d.*;
058: import com.sun.j3d.internal.J3dUtilsI18N;
059:
060: public class DistanceAttenuation {
061: // private fields
062:
063: // public fields
064: /**
065: * Equation types
066: */
067: static final int DOUBLE_DISTANCE_HALF_GAIN = 1;
068:
069: // methods
070: /**
071: * Fill a Distance Attenuation array
072: *
073: * recommend that the distance attenuation Point2f array is defined to
074: * be allocated to be 10 for DOUBLE_DISTANCE_HALF_GAIN - since 1/(2^10)
075: * exceeds 1/1000 scale that is agreed to be affective zero gain
076: *
077: * First method assumes that:
078: * type is half gain for every double of distance
079: * inner radius is 0.0 but region between 0th and 1st elements is constant
080: * since gains for these two elements are the same
081: * min gain approches zero.
082: */
083: public void fillDistanceAttenuation(float unitDistance,
084: float unitGain, Point2f[] distanceAttenuation) {
085: if (distanceAttenuation == null)
086: throw new SoundException(J3dUtilsI18N
087: .getString("DistanceAttenuation0"));
088:
089: int length = distanceAttenuation.length;
090: distanceAttenuation[0].x = 0.0f;
091: distanceAttenuation[0].y = unitGain;
092: float nextDistance = unitDistance;
093: float nextGain = unitGain;
094:
095: for (int i = 1; i < length; i++) {
096: distanceAttenuation[i].x = nextDistance;
097: distanceAttenuation[i].y = nextGain;
098: nextDistance *= 2.0f;
099: nextGain *= 0.5f;
100: }
101: }
102:
103: public void fillDistanceAttenuation(float innerRadius,
104: float maxConstantGain, float unitDistance, float unitGain,
105: int curveType, Point2f[] distanceAttenuation) {
106: if (distanceAttenuation == null)
107: throw new SoundException(J3dUtilsI18N
108: .getString("DistanceAttenuation0"));
109:
110: int length = distanceAttenuation.length;
111: distanceAttenuation[0].x = innerRadius;
112: distanceAttenuation[0].y = maxConstantGain;
113: // Danger if mzxConstanceGain is less than greater than unitGain
114: // then your modeling attenuation that's physically improbable!
115: float nextDistance = unitDistance;
116: float nextGain = unitGain;
117:
118: for (int i = 1; i < length; i++) {
119: distanceAttenuation[i].x = innerRadius + nextDistance;
120: distanceAttenuation[i].y = nextGain;
121: nextDistance *= 2.0f;
122: nextGain *= 0.5f;
123: }
124: }
125:
126: public void fillDistanceAttenuation(float innerRadius,
127: float maxConstantGain, float unitDistance, float unitGain,
128: float outerRadius, float minConstantGain, int curveType,
129: Point2f[] distanceAttenuation) {
130: }
131: }
|