# HG changeset patch # User Omair Majid # Date 1222450053 14400 # Node ID f29cbcfbc354d3b4e5a052021ff7c253ae0c28c1 # Parent e0d34e48bc297603a60cb31106ab42a10e10be79 2008-09-26 Omair Majid * src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Moved framesSinceOpen to parent class PulseAudioDataLine. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Added framesSinceOpen. (addStreamListeners): framesSinceOpen is now passed as the position to all LineEvents being thrown. (start): Likewise. (stop): Likewise. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Renamed currentFramePosition to framesSinceOpen which moved to the parent class. (PulseAudioSourceDataLine): Renamed currentFramePosition to framesSinceOpen. (getFramePosition): Likewise. (getLongFramePosition): Likewise. (getMicrosecondPosition): Likewise. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Renamed currentFramePosition to framesSinceOpen which moved to parent class. (open): Renamed currentFramePosition to framesSinceOpen. (read): Likewise. (getFramePosition): Likewise. (getLongFramePosition): Likewise. (getMicrosecondPosition): Likewise. (start): Pass framesSinceOpen as the frame position at which the start event occured. (stop): framesSinceOpen is now passed as the position to LineEvent being raised. diff -r e0d34e48bc29 -r f29cbcfbc354 src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Fri Sep 26 12:54:37 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Fri Sep 26 13:27:33 2008 -0400 @@ -67,9 +67,6 @@ // the ending frame of the loop private int endFrame = 0; - // the total number of frames played since this line was opened - private int framesSinceOpen = 0; - public static final String DEFAULT_CLIP_NAME = "Clip"; private Object clipLock = new Object(); diff -r e0d34e48bc29 -r f29cbcfbc354 src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Sep 26 12:54:37 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Sep 26 13:27:33 2008 -0400 @@ -70,6 +70,8 @@ protected boolean sendEvents = true; protected int bufferSize = 0; + // the total number of frames played since this line was opened + protected long framesSinceOpen = 0; protected EventLoop eventLoop = null; protected Semaphore semaphore = new Semaphore(0); @@ -136,8 +138,7 @@ if (sendEvents) { fireLineEvent(new LineEvent( PulseAudioDataLine.this, - LineEvent.Type.OPEN, - AudioSystem.NOT_SPECIFIED)); + LineEvent.Type.OPEN, framesSinceOpen)); } semaphore.release(); @@ -146,8 +147,7 @@ if (sendEvents) { fireLineEvent((new LineEvent( PulseAudioDataLine.this, - LineEvent.Type.CLOSE, - AudioSystem.NOT_SPECIFIED))); + LineEvent.Type.CLOSE, framesSinceOpen))); } semaphore.release(); @@ -165,7 +165,7 @@ if (!corked) { fireLineEvent(new LineEvent(PulseAudioDataLine.this, - LineEvent.Type.STOP, AudioSystem.NOT_SPECIFIED)); + LineEvent.Type.STOP, framesSinceOpen)); } } @@ -179,7 +179,7 @@ dataWritten = true; if (!corked) { fireLineEvent(new LineEvent(PulseAudioDataLine.this, - LineEvent.Type.START, AudioSystem.NOT_SPECIFIED)); + LineEvent.Type.START, framesSinceOpen)); } } @@ -326,7 +326,7 @@ /* * if (dataWritten) { fireLineEvent(new * LineEvent(PulseAudioDataLine.this, LineEvent.Type.START, - * AudioSystem.NOT_SPECIFIED)); } + * framesSinceOpen)); } */ } @@ -352,7 +352,7 @@ isStarted = false; if (dataWritten) { fireLineEvent(new LineEvent(PulseAudioDataLine.this, - LineEvent.Type.STOP, AudioSystem.NOT_SPECIFIED)); + LineEvent.Type.STOP, framesSinceOpen)); } isStarted = false; diff -r e0d34e48bc29 -r f29cbcfbc354 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Fri Sep 26 12:54:37 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Fri Sep 26 13:27:33 2008 -0400 @@ -52,8 +52,6 @@ private boolean muted; private float volume; - private long currentFramePosition = 0; - public PulseAudioSourceDataLine(EventLoop eventLoop, AudioFormat[] formats, AudioFormat defaultFormat) { @@ -194,7 +192,7 @@ position += availableSize; remainingLength -= availableSize; - currentFramePosition += availableSize / frameSize; + framesSinceOpen += availableSize / frameSize; } } @@ -219,17 +217,17 @@ }; public int getFramePosition() { - return (int) currentFramePosition; + return (int) framesSinceOpen; } public long getLongFramePosition() { - return currentFramePosition; + return framesSinceOpen; } public long getMicrosecondPosition() { float frameRate = currentFormat.getFrameRate(); - float time = currentFramePosition / frameRate; // seconds + float time = framesSinceOpen / frameRate; // seconds long microseconds = (long) (time * 1000); return microseconds; } diff -r e0d34e48bc29 -r f29cbcfbc354 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Fri Sep 26 12:54:37 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Fri Sep 26 13:27:33 2008 -0400 @@ -38,7 +38,6 @@ package org.classpath.icedtea.pulseaudio; import javax.sound.sampled.AudioFormat; -import javax.sound.sampled.AudioSystem; import javax.sound.sampled.LineEvent; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.TargetDataLine; @@ -46,8 +45,6 @@ public class PulseAudioTargetDataLine extends PulseAudioDataLine implements TargetDataLine { - private long currentFramePosition = 0; - public PulseAudioTargetDataLine(EventLoop eventLoop, AudioFormat[] formats, AudioFormat defaultFormat) { supportedFormats = formats; @@ -79,7 +76,7 @@ super.open(format, bufferSize); - currentFramePosition = 0; + framesSinceOpen = 0; PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); parentMixer.addTargetLine(this); @@ -136,8 +133,7 @@ sizeRead += bytesRead; position += bytesRead; remainingLength -= bytesRead; - currentFramePosition += bytesRead - / currentFormat.getFrameSize(); + framesSinceOpen += bytesRead / currentFormat.getFrameSize(); } } @@ -178,12 +174,12 @@ } Operation operation; - synchronized (eventLoop.threadLock) { - operation = stream.flush(); - } - operation.waitForCompletion(); - operation.releaseReference(); - + synchronized (eventLoop.threadLock) { + operation = stream.flush(); + } + operation.waitForCompletion(); + operation.releaseReference(); + } public int available() { @@ -197,15 +193,15 @@ } public int getFramePosition() { - return (int) currentFramePosition; + return (int) framesSinceOpen; } public long getLongFramePosition() { - return currentFramePosition; + return framesSinceOpen; } public long getMicrosecondPosition() { - return (long) (currentFramePosition / currentFormat.getFrameRate()); + return (long) (framesSinceOpen / currentFormat.getFrameRate()); } /* @@ -218,16 +214,14 @@ public void start() { super.start(); - fireLineEvent(new LineEvent(this, LineEvent.Type.START, - AudioSystem.NOT_SPECIFIED)); + fireLineEvent(new LineEvent(this, LineEvent.Type.START, framesSinceOpen)); } @Override public void stop() { super.stop(); - fireLineEvent(new LineEvent(this, LineEvent.Type.STOP, - AudioSystem.NOT_SPECIFIED)); + fireLineEvent(new LineEvent(this, LineEvent.Type.STOP, framesSinceOpen)); } -} \ No newline at end of file +}