Mercurial > hg > pulseaudio
changeset 148:f29cbcfbc354
2008-09-26 Omair Majid <omajid@redhat.com>
* 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.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 26 Sep 2008 13:27:33 -0400 |
parents | e0d34e48bc29 |
children | b4390e330ff7 f508adb1c908 |
files | src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java |
diffstat | 4 files changed, 26 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- 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();
--- 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;
--- 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; }
--- 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 +}