Mercurial > hg > ristipolku
comparison game/SoundManager.java @ 134:4c0dec72e2f0
Whitespace cosmetic cleanup.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 Nov 2011 21:51:54 +0200 |
parents | 3551b61b3c0b |
children | d6d92845d6a2 |
comparison
equal
deleted
inserted
replaced
133:881deac2daf8 | 134:4c0dec72e2f0 |
---|---|
33 public SoundManager(AudioFormat format, int maxSounds) | 33 public SoundManager(AudioFormat format, int maxSounds) |
34 { | 34 { |
35 super("SoundManagerPool-" + (poolID++)); | 35 super("SoundManagerPool-" + (poolID++)); |
36 | 36 |
37 int numThreads = Math.min(maxSounds, getMaxSimultaneousSounds(playbackFormat)); | 37 int numThreads = Math.min(maxSounds, getMaxSimultaneousSounds(playbackFormat)); |
38 | 38 |
39 System.out.print("SMGR.SoundManager() initializing with " + numThreads +" max sounds\n"); | 39 System.out.print("SMGR.SoundManager() initializing with " + numThreads +" max sounds\n"); |
40 | 40 |
41 setDaemon(true); | 41 setDaemon(true); |
42 alive = true; | 42 alive = true; |
43 | 43 |
44 playbackFormat = format; | 44 playbackFormat = format; |
45 localLine = new ThreadLocal(); | 45 localLine = new ThreadLocal(); |
248 int bufferSize = playbackFormat.getFrameSize() * Math.round(playbackFormat.getSampleRate() / 10); | 248 int bufferSize = playbackFormat.getFrameSize() * Math.round(playbackFormat.getSampleRate() / 10); |
249 | 249 |
250 // create, open, and start the line | 250 // create, open, and start the line |
251 SourceDataLine line; | 251 SourceDataLine line; |
252 DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat); | 252 DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat); |
253 | 253 |
254 System.out.print("SMGR.threadStarted(): "+lineInfo.toString()+"\n"); | 254 System.out.print("SMGR.threadStarted(): "+lineInfo.toString()+"\n"); |
255 | 255 |
256 try { | 256 try { |
257 line = (SourceDataLine) AudioSystem.getLine(lineInfo); | 257 line = (SourceDataLine) AudioSystem.getLine(lineInfo); |
258 line.open(playbackFormat, bufferSize); | 258 line.open(playbackFormat, bufferSize); |
262 System.out.print("SMGR.threadStarted() line unavailable!\n"); | 262 System.out.print("SMGR.threadStarted() line unavailable!\n"); |
263 // the line is unavailable - signal to end this thread | 263 // the line is unavailable - signal to end this thread |
264 Thread.currentThread().interrupt(); | 264 Thread.currentThread().interrupt(); |
265 return; | 265 return; |
266 } | 266 } |
267 | 267 |
268 // Change volume | 268 // Change volume |
269 Control.Type ct = FloatControl.Type.MASTER_GAIN; | 269 Control.Type ct = FloatControl.Type.MASTER_GAIN; |
270 if (line.isControlSupported(ct)) | 270 if (line.isControlSupported(ct)) |
271 { | 271 { |
272 FloatControl c = (FloatControl) line.getControl(ct); | 272 FloatControl c = (FloatControl) line.getControl(ct); |
308 public void run() | 308 public void run() |
309 { | 309 { |
310 // get line and buffer from ThreadLocals | 310 // get line and buffer from ThreadLocals |
311 SourceDataLine line = (SourceDataLine) localLine.get(); | 311 SourceDataLine line = (SourceDataLine) localLine.get(); |
312 byte[] buffer = (byte[])localBuffer.get(); | 312 byte[] buffer = (byte[])localBuffer.get(); |
313 | 313 |
314 if (line == null || buffer == null) | 314 if (line == null || buffer == null) |
315 return; | 315 return; |
316 | 316 |
317 // copy data to the line | 317 // copy data to the line |
318 try { | 318 try { |
328 catch (InterruptedException ex) { | 328 catch (InterruptedException ex) { |
329 return; | 329 return; |
330 } | 330 } |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 // copy data | 334 // copy data |
335 int bufPos = 0; | 335 int bufPos = 0; |
336 while (bufPos < buffer.length && playing) | 336 while (bufPos < buffer.length && playing) |
337 { | 337 { |
338 int res = source.read(buffer, bufPos, buffer.length - bufPos); | 338 int res = source.read(buffer, bufPos, buffer.length - bufPos); |