FileDocCategorySizeDatePackage
JmpxAudio.javaAPI DocJMF 2.1.1e2552Mon May 12 12:21:26 BST 2003com.sun.media.codec.video.jmpx

JmpxAudio

public class JmpxAudio extends JavaSoundOutput

Fields Summary
private long
count
private long
JSHackIncr
private long
JSHackCount
private long
JSHackSample
private long
JSHackSampleCount
private Object
pauseSync
static final long
MAX_TOLERENCE
static final long
OFFSET
private int
sampleCountLow
long
lastPos
long
originPos
long
totalCount
Constructors Summary
public JmpxAudio()

    
      
    
Methods Summary
private static intbufferSize(javax.media.format.AudioFormat f)

	int bufferSize = 0;
	bufferSize = 256*1024;
	return ++bufferSize; // make it an odd number
    
public voidflush()

 	super.flush();
    
public intgetSampleCountHigh()

    
    /*
     * We are doing this since the JNI doesn't seem to like getSamplesPlayed().
     * which returns a long instead of an int for some reason...
     */
       
	long pos = dataLine.getFramePosition();
	// Check for wrap around
	if (pos < lastPos) {
	    totalCount += lastPos - originPos;
	    originPos = pos;
	}
	
	lastPos = pos;
	
	long s = totalCount + pos - originPos - count + JSHackSampleCount;
	if (s == JSHackSample) {
	    if (JSHackCount++ > MAX_TOLERENCE) {
		JSHackSampleCount += JSHackIncr;
		JSHackCount = 0;
	    }
	} else {
	    JSHackCount = 0;
	    JSHackSample = s;
	}
	sampleCountLow = (int) (s & 0xFFFFFFFFL);
	return (int) ((s >> 32) & 0xFFFFFFFFL);
    
public intgetSampleCountLow()

	return sampleCountLow;
    
public booleaninitialize(javax.media.format.AudioFormat format)

	JSHackIncr = (long)(format.getSampleRate() / 60);
	return super.initialize(format, bufferSize(format));
    
public voidpause()

	synchronized (pauseSync) {
	    super.pause();
	}
    
public voidresetSamples()

	if (dataLine != null) {
	    count = dataLine.getFramePosition();
	    lastPos = count;
	    originPos = count;
	    totalCount = count;
	}
	JSHackSampleCount = 0;
    
public voidresume()

	synchronized (pauseSync) {
	    super.resume();
	}
    
public intwrite(byte[] data, int off, int len)

	synchronized (pauseSync) {
	    if (paused) {
System.err.println("writing when paused: " + len);
		return len;
	    }
	    return super.write(data, off, len);
	}