diff options
Diffstat (limited to 'NET/worlds/scape/WavSoundPlayer.java')
| -rw-r--r-- | NET/worlds/scape/WavSoundPlayer.java | 402 |
1 files changed, 402 insertions, 0 deletions
diff --git a/NET/worlds/scape/WavSoundPlayer.java b/NET/worlds/scape/WavSoundPlayer.java new file mode 100644 index 0000000..a729709 --- /dev/null +++ b/NET/worlds/scape/WavSoundPlayer.java @@ -0,0 +1,402 @@ +/* */ package NET.worlds.scape; +/* */ +/* */ import NET.worlds.core.IniFile; +/* */ import NET.worlds.network.URL; +/* */ import java.util.Vector; +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public class WavSoundPlayer +/* */ extends SoundPlayer +/* */ implements Runnable +/* */ { +/* */ float ang; +/* */ float dist; +/* */ float vol; +/* */ +/* */ public WavSoundPlayer(Sound owner) +/* */ { +/* 34 */ super(owner); +/* */ } +/* */ +/* */ static +/* */ { +/* 39 */ nativeInit(); +/* */ } +/* */ +/* */ public boolean open(float volume, float stopDist, boolean atten, boolean pan) +/* */ { +/* 44 */ return true; +/* */ } +/* */ +/* */ public void close() { +/* 48 */ stop(); +/* */ } +/* */ +/* */ public boolean position(Point3Temp cam, Point3Temp obj, Point3Temp out, Point3Temp up) +/* */ { +/* 53 */ Point3Temp toObj = Point3Temp.make(obj).minus(cam); +/* 54 */ Point3Temp right = Point3Temp.make(out).cross(up); +/* 55 */ float y = toObj.dot(out); +/* 56 */ float x = toObj.dot(right); +/* 57 */ this.ang = ((float)(Math.atan2(y, x) / 3.141592653589793D)); +/* 58 */ this.dist = toObj.length(); +/* */ +/* */ +/* 61 */ return setVolume(this.vol); +/* */ } +/* */ +/* */ public boolean setVolume(float v) { +/* 65 */ this.vol = v; +/* */ +/* 67 */ float leftFrac = 0.5F; +/* 68 */ if ((this.owner != null) && (this.owner.getPanning())) +/* */ { +/* */ +/* 71 */ leftFrac = Math.abs(this.ang); +/* */ +/* */ +/* 74 */ if (this.ang < 0.0F) { +/* 75 */ v = this.vol * (float)(0.5D + Math.abs(0.5D + this.ang)); +/* */ } +/* */ } +/* 78 */ if ((this.owner != null) && (this.owner.getAttenuate())) { +/* 79 */ float stopDist = this.owner.getStopDistance(); +/* 80 */ if (this.dist > stopDist) { +/* 81 */ volume(0.0F, 0.0F); +/* 82 */ return false; +/* */ } +/* */ +/* 85 */ v *= (stopDist - this.dist) / stopDist; +/* */ } +/* */ +/* 88 */ volume(v * leftFrac, v * (1.0F - leftFrac)); +/* 89 */ return true; +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public int getState() +/* */ { +/* 98 */ return soundStack.contains(this) ? 0 : 1; +/* */ } +/* */ +/* */ +/* 102 */ private String playingSoundFile = ""; +/* */ +/* */ +/* */ private URL url; +/* */ +/* */ +/* */ +/* */ public void start(URL u) +/* */ { +/* 111 */ this.url = u; +/* 112 */ start(1); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* 118 */ private static Vector<WavSoundPlayer> soundStack = new Vector(); +/* */ +/* */ private static Thread activeThread; +/* */ +/* */ int repeatsLeft; +/* */ +/* */ private static int playingThreads; +/* */ private static int systemPaused; +/* */ +/* */ private static WavSoundPlayer getActive() +/* */ { +/* 129 */ if (!soundStack.isEmpty()) +/* 130 */ return (WavSoundPlayer)soundStack.lastElement(); +/* 131 */ return null; +/* */ } +/* */ +/* */ public static boolean isActive() { +/* 135 */ return !soundStack.isEmpty(); +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void play(int repeatCount, boolean reuseLoop) +/* */ { +/* 146 */ this.playingSoundFile = this.url.unalias(); +/* */ +/* 148 */ soundStack.removeElement(this); +/* 149 */ soundStack.addElement(this); +/* */ +/* 151 */ this.repeatsLeft = repeatCount; +/* 152 */ if (this.repeatsLeft < 0) +/* */ { +/* 154 */ if ((!reuseLoop) && (systemPaused == 0)) +/* 155 */ nativePlay(true); +/* 156 */ activeThread = null; +/* */ } else { +/* 158 */ activeThread = new Thread(this); +/* 159 */ activeThread.start(); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ public void start(int repeatCount) +/* */ { +/* 167 */ synchronized (soundStack) { +/* 168 */ WavSoundPlayer active = getActive(); +/* */ +/* 170 */ assert ((this.repeatsLeft == 0) && (active != this)); +/* 171 */ if (this.owner != null) { +/* 172 */ this.url = this.owner.getURL(); +/* */ } +/* */ +/* */ +/* 176 */ boolean activeWasLoop = activeThread == null; +/* 177 */ boolean reuseLoop = (active != null) && +/* 178 */ (activeWasLoop) && +/* 179 */ (repeatCount < 0) && +/* 180 */ (active.playingSoundFile.equals(this.url.unalias())); +/* */ +/* 182 */ if (active != null) { +/* 183 */ active.stop(reuseLoop); +/* */ +/* */ +/* 186 */ if (activeWasLoop) { +/* 187 */ soundStack.addElement(active); +/* */ } +/* */ } +/* 190 */ play(repeatCount, reuseLoop); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public void run() +/* */ { +/* 211 */ synchronized (soundStack) { +/* 212 */ if (systemPaused > 0) { +/* 213 */ this.repeatsLeft = 0; +/* 214 */ return; +/* */ } +/* 216 */ playingThreads += 1; +/* */ } +/* */ +/* */ +/* 220 */ while (this.repeatsLeft > 0) { +/* 221 */ synchronized (soundStack) { +/* 222 */ if (activeThread != Thread.currentThread()) { +/* */ break; +/* */ } +/* 225 */ if (this.repeatsLeft > 0) { +/* 226 */ this.repeatsLeft -= 1; +/* */ } +/* */ } +/* */ +/* */ +/* 231 */ nativePlay(false); +/* */ } +/* */ +/* 234 */ synchronized (soundStack) { +/* 235 */ if (activeThread == Thread.currentThread()) { +/* 236 */ assert (getActive() == this); +/* 237 */ soundStack.removeElement(this); +/* 238 */ activeThread = null; +/* */ +/* */ +/* 241 */ WavSoundPlayer active = getActive(); +/* 242 */ if (active != null) +/* 243 */ active.play(-1, false); +/* */ } +/* 245 */ playingThreads -= 1; +/* 246 */ soundStack.notifyAll(); +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ private void stop(boolean leaveLoopRunning) +/* */ { +/* 262 */ if (getActive() == this) { +/* 263 */ boolean isLoop = activeThread == null; +/* 264 */ assert (((this.repeatsLeft < 0) && (isLoop)) || (!leaveLoopRunning)); +/* */ +/* */ +/* 267 */ this.repeatsLeft = 0; +/* */ +/* */ +/* 270 */ if ((!leaveLoopRunning) && (isLoop) && (systemPaused == 0)) { +/* 271 */ nativeStop(); +/* */ } +/* 273 */ activeThread = null; +/* */ } +/* */ +/* 276 */ soundStack.removeElement(this); +/* */ } +/* */ +/* */ +/* */ +/* */ public void stop() +/* */ { +/* 283 */ synchronized (soundStack) { +/* 284 */ if (getActive() == this) { +/* 285 */ stop(false); +/* */ +/* */ +/* 288 */ WavSoundPlayer active = getActive(); +/* 289 */ if (active != null) +/* 290 */ active.play(-1, false); +/* */ } else { +/* 292 */ soundStack.removeElement(this); +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static void pauseSystemExceptASF() +/* */ { +/* 312 */ synchronized (soundStack) { +/* 313 */ WavSoundPlayer active = getActive(); +/* 314 */ boolean isLoop = activeThread == null; +/* */ +/* 316 */ if (active != null) { +/* 317 */ if (isLoop) { +/* 318 */ active.nativeStop(); +/* */ } else { +/* 320 */ active.stop(false); +/* */ } +/* */ } +/* 323 */ systemPaused += 1; +/* */ +/* 325 */ if (active != null) { +/* 326 */ active.play(-1, false); +/* */ } +/* */ +/* 329 */ while (playingThreads > 0) { +/* */ try { +/* 331 */ soundStack.wait(); +/* */ } +/* */ catch (InterruptedException localInterruptedException) {} +/* */ } +/* */ } +/* */ } +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ +/* */ public static void resumeSystemExceptASF() +/* */ { +/* 347 */ synchronized (soundStack) +/* */ { +/* */ +/* */ +/* */ +/* 352 */ if (systemPaused > 0) +/* */ { +/* 354 */ systemPaused = 0; +/* */ +/* 356 */ WavSoundPlayer active = getActive(); +/* 357 */ if ((active != null) && (activeThread == null)) { +/* 358 */ active.play(-1, false); +/* */ } +/* */ } +/* */ } +/* */ } +/* */ +/* 364 */ static boolean ignoreVolumeChanges = IniFile.gamma().getIniInt("ignoreVolumeChanges", 1) != 0; +/* */ +/* 366 */ private static WavSoundTerminator terminator = new WavSoundTerminator(); +/* */ private static float lastLeftVol; +/* */ private static float lastRightVol; +/* */ +/* */ public void volume(float left, float right) { +/* 371 */ if (ignoreVolumeChanges) { +/* 372 */ return; +/* */ } +/* 374 */ synchronized (soundStack) { +/* 375 */ if ((getActive() == this) && ( +/* 376 */ (lastLeftVol != left) || (lastRightVol != right))) +/* */ { +/* 378 */ lastLeftVol = left; +/* 379 */ lastRightVol = right; +/* 380 */ nativeVolume(left, right); +/* */ } +/* */ } +/* */ } +/* */ +/* */ public static native void nativeInit(); +/* */ +/* */ public static void pauseSystem() {} +/* */ +/* */ public static void resumeSystem() {} +/* */ +/* */ private native void nativePlay(boolean paramBoolean); +/* */ +/* */ private native void nativeVolume(float paramFloat1, float paramFloat2); +/* */ +/* */ private native void nativeStop(); +/* */ } + + +/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\WavSoundPlayer.class + * Java compiler version: 6 (50.0) + * JD-Core Version: 0.7.1 + */
\ No newline at end of file |