Pump up the size of our line buffer to get longer sounds to play less

skiptacularly and try going back to using line.drain since our sleep until we
figure the sound will be done method wasn't working so well with the larger
buffer.  Hopefully drain has been fixed in the 4 years since it was commented
out.



git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@590 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Charlie Groves
2008-08-01 01:23:04 +00:00
parent e6e5e82c83
commit 1255109f57
@@ -31,7 +31,6 @@ import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioFormat;
@@ -213,11 +212,11 @@ public class SoundManager
buf.append("clipVol=").append(_clipVol); buf.append("clipVol=").append(_clipVol);
buf.append(", disabled=["); buf.append(", disabled=[");
int ii = 0; int ii = 0;
for (Iterator<SoundType> iter = _disabledTypes.iterator(); iter.hasNext(); ) { for (SoundType soundType : _disabledTypes) {
if (ii++ > 0) { if (ii++ > 0) {
buf.append(", "); buf.append(", ");
} }
buf.append(iter.next()); buf.append(soundType);
} }
return buf.append("]").toString(); return buf.append("]").toString();
} }
@@ -565,7 +564,6 @@ public class SoundManager
line.start(); line.start();
_soundSeemsToWork = true; _soundSeemsToWork = true;
long startTime = System.currentTimeMillis();
byte[] buffer = new byte[LINEBUF_SIZE]; byte[] buffer = new byte[LINEBUF_SIZE];
int totalRead = 0; int totalRead = 0;
@@ -610,32 +608,7 @@ public class SoundManager
} }
} while (key.cmd == LOOP && key.running); } while (key.cmd == LOOP && key.running);
// sleep the drain time. We never trust line.drain() because line.drain();
// it is buggy and locks up on natively multithreaded systems
// (linux, winXP with HT).
float sampleRate = format.getSampleRate();
if (sampleRate == AudioSystem.NOT_SPECIFIED) {
sampleRate = 11025; // most of our sounds are
}
int sampleSize = format.getSampleSizeInBits();
if (sampleSize == AudioSystem.NOT_SPECIFIED) {
sampleSize = 16;
}
int drainTime = (int) Math.ceil((totalRead * 8 * 1000) / (sampleRate * sampleSize));
// subtract out time we've already spent doing things.
drainTime -= System.currentTimeMillis() - startTime;
drainTime = Math.max(0, drainTime);
// add in a fudge factor of half a second
drainTime += 500;
try {
Thread.sleep(drainTime);
} catch (InterruptedException ie) { }
} catch (IOException ioe) { } catch (IOException ioe) {
log.warning("Error loading sound file [key=" + key + ", e=" + ioe + "]."); log.warning("Error loading sound file [key=" + key + ", e=" + ioe + "].");
@@ -1072,7 +1045,7 @@ public class SoundManager
protected static final long MAX_SOUND_DELAY = 400L; protected static final long MAX_SOUND_DELAY = 400L;
/** The size of the line's buffer. */ /** The size of the line's buffer. */
protected static final int LINEBUF_SIZE = 16 * 1024; protected static final int LINEBUF_SIZE = 64 * 1024;
/** The maximum time a spooler will wait for a stream before deciding to shut down. */ /** The maximum time a spooler will wait for a stream before deciding to shut down. */
protected static final long MAX_WAIT_TIME = 30000L; protected static final long MAX_WAIT_TIME = 30000L;