changeset in /hg/pulseaudio: 2008-08-13 Omair Majid <omajid at redh...
Omair Majid
omajid at redhat.com
Wed Aug 13 07:13:03 PDT 2008
changeset c054a0681a49 in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=c054a0681a49
description:
2008-08-13 Omair Majid <omajid at redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java:
implemented getFramePosition(), getLevel(), getLongFramePosition() and
getMicrosecondPosition
* unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java:
added a test for getMicrosecondPosition() (the test isnt perfect; cant
confirm microsecond length with any other wav player)
diffstat:
2 files changed, 45 insertions(+), 10 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java | 21 +++---
unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java | 34 +++++++++-
diffs (111 lines):
diff -r 9a72b909f18a -r c054a0681a49 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Tue Aug 12 16:55:28 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Wed Aug 13 10:12:49 2008 -0400
@@ -80,6 +80,8 @@ public class PulseAudioSourceDataLine im
private PulseAudioStreamVolumeControl volumeControl;
private boolean muted;
private float volume;
+
+ private long currentFramePosition = 0;
/*
* When moving from 32bit platform to 64 bit platform, these variables
@@ -451,13 +453,14 @@ public class PulseAudioSourceDataLine im
sizeWritten += availableSize;
position += availableSize;
remainingLength -= availableSize;
+
}
}
// all the data should have been played by now
assert (sizeWritten == length);
-
+ currentFramePosition += (sizeWritten/getFormat().getFrameSize());
/*
* FIXME when the stream is flushed() etc, instead of returning length
* this should unblock and return the the size of data written so far
@@ -566,23 +569,23 @@ public class PulseAudioSourceDataLine im
}
public int getFramePosition() {
- // TODO Auto-generated method stub
- return 0;
+ return (int)currentFramePosition;
}
public float getLevel() {
- // TODO Auto-generated method stub
- return 0;
+ return AudioSystem.NOT_SPECIFIED;
}
public long getLongFramePosition() {
- // TODO Auto-generated method stub
- return 0;
+ return currentFramePosition;
}
public long getMicrosecondPosition() {
- // TODO Auto-generated method stub
- return 0;
+
+ float frameRate = currentFormat.getFrameRate();
+ float time = currentFramePosition/frameRate; // seconds
+ long microseconds = (long)(time * 1000);
+ return microseconds;
}
public boolean isActive() {
diff -r 9a72b909f18a -r c054a0681a49 unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java Tue Aug 12 16:55:28 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java Wed Aug 13 10:12:49 2008 -0400
@@ -82,7 +82,7 @@ public class PulseSourceDataLineTest {
public void testPlay() throws LineUnavailableException,
UnsupportedAudioFileException, IOException {
System.out.println("This test plays a file");
-
+
File soundFile = new File("testsounds/startup.wav");
AudioInputStream audioInputStream = AudioSystem
.getAudioInputStream(soundFile);
@@ -312,6 +312,38 @@ public class PulseSourceDataLineTest {
}
+ @Test
+ public void testFramePosition() throws UnsupportedAudioFileException,
+ IOException, LineUnavailableException {
+ File soundFile = new File("testsounds/logout.wav");
+ AudioInputStream audioInputStream = AudioSystem
+ .getAudioInputStream(soundFile);
+ AudioFormat audioFormat = audioInputStream.getFormat();
+
+ SourceDataLine line;
+ line = (PulseAudioSourceDataLine) mixer.getLine(new DataLine.Info(
+ SourceDataLine.class, audioFormat));
+ Assert.assertNotNull(line);
+
+ line.open(audioFormat);
+ line.start();
+
+ byte[] abData = new byte[1000];
+ int bytesRead = 0;
+
+ while (bytesRead >= 0) {
+ bytesRead = audioInputStream.read(abData, 0, abData.length);
+ if (bytesRead > 0) {
+ line.write(abData, 0, bytesRead);
+ }
+ }
+
+ line.flush();
+ System.out.println("time position: " + line.getMicrosecondPosition());
+ Assert.assertEquals(6199, line.getMicrosecondPosition());
+ line.close();
+ }
+
@After
public void tearDown() throws Exception {
More information about the distro-pkg-dev
mailing list