Mercurial > hg > ristipolku
comparison game/SoundManager.java @ 63:1c7a97d80120
Some work on the sound code ...
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 25 Feb 2011 07:26:58 +0200 |
parents | ceaf645ed930 |
children | e1d657e6c25b |
comparison
equal
deleted
inserted
replaced
62:caf67c7e0814 | 63:1c7a97d80120 |
---|---|
60 public static int getMaxSimultaneousSounds(AudioFormat playbackFormat) | 60 public static int getMaxSimultaneousSounds(AudioFormat playbackFormat) |
61 { | 61 { |
62 DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat); | 62 DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat); |
63 | 63 |
64 Mixer.Info[] info = AudioSystem.getMixerInfo(); | 64 Mixer.Info[] info = AudioSystem.getMixerInfo(); |
65 System.out.print("getMaxSimultaneousSounds() mixer information:\n"); | 65 System.out.print("SMGR.getMaxSimultaneousSounds() mixer information:\n"); |
66 Mixer.Info select = null; | 66 Mixer.Info select = null; |
67 for (Mixer.Info i : info) | 67 for (Mixer.Info i : info) |
68 { | 68 { |
69 System.out.print("#"+i.getName()+"\n"); | 69 System.out.print(" - '"+i.getName()+"'\n"); |
70 if (i.getName().equals("Java Sound Audio Engine")) | 70 if (i.getName().equals("Java Sound Audio Engine")) |
71 select = i; | 71 select = i; |
72 } | 72 } |
73 | 73 |
74 Mixer mixer = AudioSystem.getMixer(select); | 74 Mixer mixer = AudioSystem.getMixer(select); |
75 | 75 |
76 Mixer.Info i = mixer.getMixerInfo(); | 76 Mixer.Info i = mixer.getMixerInfo(); |
77 System.out.print("selected: "+i.getName()+"\n"); | 77 System.out.print(" * selected='"+i.getName()+"'\n"); |
78 | 78 |
79 int maxLines = mixer.getMaxLines(lineInfo); | 79 int maxLines = mixer.getMaxLines(lineInfo); |
80 if (maxLines == AudioSystem.NOT_SPECIFIED) | 80 if (maxLines == AudioSystem.NOT_SPECIFIED) |
81 maxLines = 16; | 81 maxLines = 8; |
82 | 82 |
83 System.out.print("SMGR.getMaxSimultaneousSounds() maxLines="+maxLines+"\n"); | 83 System.out.print(" * maxLines="+maxLines+"\n"); |
84 | 84 |
85 return maxLines; | 85 return maxLines; |
86 } | 86 } |
87 | 87 |
88 | 88 |
94 | 94 |
95 System.out.print("SMGR.cleanUp(): closing mixer\n"); | 95 System.out.print("SMGR.cleanUp(): closing mixer\n"); |
96 | 96 |
97 // close the mixer (stops any running sounds) | 97 // close the mixer (stops any running sounds) |
98 Mixer mixer = AudioSystem.getMixer(null); | 98 Mixer mixer = AudioSystem.getMixer(null); |
99 System.out.print("SMGR.cleanUp(): foo\n"); | |
100 if (mixer.isOpen()) | 99 if (mixer.isOpen()) |
101 mixer.close(); | 100 mixer.close(); |
102 | 101 |
103 System.out.print("SMGR.cleanUp(): leaving\n"); | 102 System.out.print("SMGR.cleanUp(): leaving\n"); |
104 } | 103 } |
222 } | 221 } |
223 | 222 |
224 | 223 |
225 public InputStream play(InputStream is) | 224 public InputStream play(InputStream is) |
226 { | 225 { |
227 System.out.print("SMGR.play()\n"); | 226 System.out.print("SMGR.play("+is+")\n"); |
228 if (is != null) | 227 if (is != null) |
228 { | |
229 runTask(new SoundPlayer(is)); | 229 runTask(new SoundPlayer(is)); |
230 | 230 } |
231 return is; | 231 return is; |
232 } | 232 } |
233 | 233 |
234 | 234 |
235 protected void threadStarted() | 235 protected void threadStarted() |
244 | 244 |
245 System.out.print("SMGR.threadStarted()\n"); | 245 System.out.print("SMGR.threadStarted()\n"); |
246 | 246 |
247 // use a short, 100ms (1/10th sec) buffer for filters that | 247 // use a short, 100ms (1/10th sec) buffer for filters that |
248 // change in real-time | 248 // change in real-time |
249 int bufferSize = playbackFormat.getFrameSize() * | 249 int bufferSize = playbackFormat.getFrameSize() * Math.round(playbackFormat.getSampleRate() / 10); |
250 Math.round(playbackFormat.getSampleRate() / 10); | |
251 | 250 |
252 // create, open, and start the line | 251 // create, open, and start the line |
253 SourceDataLine line; | 252 SourceDataLine line; |
254 DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat); | 253 DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat); |
255 | 254 |
257 line = (SourceDataLine) AudioSystem.getLine(lineInfo); | 256 line = (SourceDataLine) AudioSystem.getLine(lineInfo); |
258 line.open(playbackFormat, bufferSize); | 257 line.open(playbackFormat, bufferSize); |
259 } | 258 } |
260 catch (LineUnavailableException ex) | 259 catch (LineUnavailableException ex) |
261 { | 260 { |
261 System.out.print("SMGR.threadStarted() line unavailable!\n"); | |
262 // the line is unavailable - signal to end this thread | 262 // the line is unavailable - signal to end this thread |
263 Thread.currentThread().interrupt(); | 263 Thread.currentThread().interrupt(); |
264 return; | 264 return; |
265 } | 265 } |
266 | 266 |
267 /* | 267 // Change volume |
268 Control[] ctrls = line.getControls(); | |
269 for (Control c : ctrls) | |
270 { | |
271 System.out.print("#" + c.toString() +"\n"); | |
272 } | |
273 */ | |
274 Control.Type ct = FloatControl.Type.MASTER_GAIN; | 268 Control.Type ct = FloatControl.Type.MASTER_GAIN; |
275 if (line.isControlSupported(ct)) | 269 if (line.isControlSupported(ct)) |
276 { | 270 { |
277 FloatControl c = (FloatControl) line.getControl(ct); | 271 FloatControl c = (FloatControl) line.getControl(ct); |
278 c.setValue(-20f); | 272 c.setValue(-20f); |