comparison game/SoundManager.java @ 93:e1d657e6c25b

Work on audio code.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Mar 2011 18:21:45 +0200
parents 1c7a97d80120
children dd896bc7352b
comparison
equal deleted inserted replaced
92:d5f51370617b 93:e1d657e6c25b
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 queue = new LinkedList();
45 for (int i = 0; i < numThreads; i++)
46 new PooledThread().start();
47
48 playbackFormat = format; 44 playbackFormat = format;
49 localLine = new ThreadLocal(); 45 localLine = new ThreadLocal();
50 localBuffer = new ThreadLocal(); 46 localBuffer = new ThreadLocal();
51 pausedLock = new Object(); 47 pausedLock = new Object();
48
49 queue = new LinkedList();
50 for (int i = 0; i < numThreads; i++)
51 new PooledThread().start();
52 52
53 synchronized (this) 53 synchronized (this)
54 { 54 {
55 notifyAll(); 55 notifyAll();
56 } 56 }
221 } 221 }
222 222
223 223
224 public InputStream play(InputStream is) 224 public InputStream play(InputStream is)
225 { 225 {
226 System.out.print("SMGR.play("+is+")\n"); 226 System.out.print("SMGR.play(is="+is+")\n");
227 if (is != null) 227 if (is != null)
228 { 228 {
229 runTask(new SoundPlayer(is)); 229 runTask(new SoundPlayer(is));
230 } 230 }
231 return is; 231 return is;
240 wait(); 240 wait();
241 } 241 }
242 catch (InterruptedException ex) { } 242 catch (InterruptedException ex) { }
243 } 243 }
244 244
245 System.out.print("SMGR.threadStarted()\n");
246 245
247 // use a short, 100ms (1/10th sec) buffer for filters that 246 // use a short, 100ms (1/10th sec) buffer for filters that
248 // change in real-time 247 // change in real-time
249 int bufferSize = playbackFormat.getFrameSize() * Math.round(playbackFormat.getSampleRate() / 10); 248 int bufferSize = playbackFormat.getFrameSize() * Math.round(playbackFormat.getSampleRate() / 10);
250 249
251 // create, open, and start the line 250 // create, open, and start the line
252 SourceDataLine line; 251 SourceDataLine line;
253 DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat); 252 DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat);
253
254 System.out.print("SMGR.threadStarted(): "+lineInfo.toString()+"\n");
254 255
255 try { 256 try {
256 line = (SourceDataLine) AudioSystem.getLine(lineInfo); 257 line = (SourceDataLine) AudioSystem.getLine(lineInfo);
257 line.open(playbackFormat, bufferSize); 258 line.open(playbackFormat, bufferSize);
258 } 259 }