summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/WavSoundPlayer.java
blob: a7297095cfbb3177a8a90938ab1fd4fecd4e4ba7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
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
 */