From iivan at redhat.com Thu Aug 21 13:49:01 2008 From: iivan at redhat.com (Ioana Ivan) Date: Thu, 21 Aug 2008 16:49:01 -0400 Subject: java sound implementation using pulseaudio - ports Message-ID: <48ADD4BD.1040202@redhat.com> Hi, We've been trying to write an implementation of javax.sound.sampled.Mixer(and the associated classes: SourceDataLine, TargetDataLine, Clip, and Port) that uses pulseaudio as a backend. So far, SourceDataLine, TargetDataLine and Clip are working (somewhat, there are still issues that need to be fixed), but we're not sure how to approach Port. From the java API: "Ports are simple lines for input or output of audio to or from audio devices. Common examples of ports that act as source lines (mixer inputs) include the microphone, line input, and CD-ROM drive. Ports that act as target lines (mixer outputs) include the speaker, headphone, and line output. You can access port using a Port.Info object." Ports should have an open() and close() method, and ideally they should also support volume and mute controls. There currently is an implementation of Port in openjdk that uses alsa to enumerate the devices that could connect to the sound system, and implement the required methods. We were wondering whether there's anything in the pulseaudio API that could be used to do something similar, and, if not, how problematic using the old version of Port(that uses alsa directly) with our mixer that uses pulseaudio is. Thank you, Ioana Ivan From gmane at colin.guthr.ie Thu Aug 21 16:06:01 2008 From: gmane at colin.guthr.ie (Colin Guthrie) Date: Fri, 22 Aug 2008 00:06:01 +0100 Subject: java sound implementation using pulseaudio - ports In-Reply-To: <48ADD4BD.1040202@redhat.com> References: <48ADD4BD.1040202@redhat.com> Message-ID: Ioana Ivan wrote: > Hi, > > We've been trying to write an implementation of > javax.sound.sampled.Mixer(and the associated classes: SourceDataLine, > TargetDataLine, Clip, and Port) that uses pulseaudio as a backend. So > far, SourceDataLine, TargetDataLine and Clip are working (somewhat, > there are still issues that need to be fixed), but we're not sure how to > approach Port. > > From the java API: > "Ports are simple lines for input or output of audio to or from audio > devices. Common examples of ports that act as source lines (mixer > inputs) include the microphone, line input, and CD-ROM drive. Ports that > act as target lines (mixer outputs) include the speaker, headphone, and > line output. You can access port using a Port.Info object." > > Ports should have an open() and close() method, and ideally they should > also support volume and mute controls. There currently is an > implementation of Port in openjdk that uses alsa to enumerate the > devices that could connect to the sound system, and implement the > required methods. > > We were wondering whether there's anything in the pulseaudio API that > could be used to do something similar, and, if not, how problematic > using the old version of Port(that uses alsa directly) with our mixer > that uses pulseaudio is. I spoke to you on the mailing list but this is a little clearer I think. Basically you just want to expose the volume of the various Sinks and Sources here. I would just get a list of all the Sinks and provide playback Ports that allow volume control and muting etc. and do a similar exposure for the Sources. I'd use the introspection stuff to do this (tho' not overly sure). http://0pointer.de/lennart/projects/pulseaudio/doxygen/introspect_8h.html You can probably use the source of pavucontrol to work out what to do here. You can of course export a volume on a "per stream" basis, but I'd imagine this doesn't map too well to the Java API seeing as streams will come and go quickly but sinks/sources will be slightly more long term (tho can still come and go (e.g. when a usb audio device is plugged in or a network sink is detected etc.) I think whatever is in the "Output devices" and "Input devices" tab in pavucontrol (from git) is probably what you want... HTHs Col -- Colin Guthrie gmane(at)colin.guthr.ie http://colin.guthr.ie/ Day Job: Tribalogic Limited [http://www.tribalogic.net/] Open Source: Mandriva Linux Contributor [http://www.mandriva.com/] PulseAudio Hacker [http://www.pulseaudio.org/] Trac Hacker [http://trac.edgewall.org/] From Joe.Darcy at Sun.COM Thu Aug 21 21:14:27 2008 From: Joe.Darcy at Sun.COM (Joseph D. Darcy) Date: Thu, 21 Aug 2008 21:14:27 -0700 Subject: Further updating Gervill for OpenJDK 6 build 12 Message-ID: <48AE3D23.4000508@sun.com> Hello. I noticed the Gervill CVS tree has been updated since I last integrated Gervill into OpenJDK 6 [1]. Here is a patch of the current differences: --- old/src/share/classes/com/sun/media/sound/SoftMixingMixer.java Thu Aug 21 21:06:18 2008 +++ new/src/share/classes/com/sun/media/sound/SoftMixingMixer.java Thu Aug 21 21:06:18 2008 @@ -62,7 +62,7 @@ protected static final String INFO_DESCRIPTION = "Software Sound Mixer"; - protected static final String INFO_VERSION = "0.9"; + protected static final String INFO_VERSION = "1.0"; protected final static Mixer.Info info = new Info(); --- old/src/share/classes/com/sun/media/sound/ModelInstrument.java Thu Aug 21 21:06:20 2008 +++ new/src/share/classes/com/sun/media/sound/ModelInstrument.java Thu Aug 21 21:06:20 2008 @@ -88,10 +88,10 @@ // This information is generated from ModelPerformer.getName() // returned from getPerformers(). public String[] getKeys() { - String[] keys = new String[127]; + String[] keys = new String[128]; for (ModelPerformer performer : getPerformers()) { for (int k = performer.getKeyFrom(); k <= performer.getKeyTo(); k++) { - if (keys[k] == null) { + if (k >= 0 && k < 128 && keys[k] == null) { String name = performer.getName(); if (name == null) name = "untitled"; --- old/src/share/classes/com/sun/media/sound/ModelByteBuffer.java Thu Aug 21 21:06:21 2008 +++ new/src/share/classes/com/sun/media/sound/ModelByteBuffer.java Thu Aug 21 21:06:21 2008 @@ -45,7 +45,7 @@ private long fileoffset; private byte[] buffer; private long offset; - private long len; + private final long len; private class RandomFileInputStream extends InputStream { @@ -107,11 +107,12 @@ } public int read(byte[] b) throws IOException { + int len = b.length; if (len > left) len = (int)left; if (left == 0) return -1; - int len = raf.read(b); + len = raf.read(b, 0, len); if (len == -1) return -1; left -= len; @@ -119,12 +120,12 @@ } public int read() throws IOException { - if (len == 0) + if (left == 0) return -1; int b = raf.read(); if (b == -1) return -1; - len--; + left--; return b; } @@ -137,15 +138,15 @@ long beginIndex, long endIndex, boolean independent) { this.root = parent.root; this.offset = 0; - this.len = parent.len; + long parent_len = parent.len; if (beginIndex < 0) beginIndex = 0; - if (beginIndex > len) - beginIndex = len; + if (beginIndex > parent_len) + beginIndex = parent_len; if (endIndex < 0) endIndex = 0; - if (endIndex > len) - endIndex = len; + if (endIndex > parent_len) + endIndex = parent_len; if (beginIndex > endIndex) beginIndex = endIndex; offset = beginIndex; I plan to apply this patch before OpenJDK 6 b12 is published, which should be within a week or two. (Neither the test directory nor the src.floatwav files seem to have been updated since the last integration.) Cheers, -Joe [1] http://mail.openjdk.java.net/pipermail/sound-dev/2008-July/000064.html