Re: <Sound Dev> Opening multiple output lines

View: New views
2 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: <Sound Dev> Opening multiple output lines

by Karl Helgason-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I added software sound mixing to the gervill Project which writes to default directaudio backend.
And thus allows true sharing of audio device (within the Java application).

cheers,
Karl Helgason
________________________________________
Frá: sound-dev-bounces@... [sound-dev-bounces@...] Fyrir hönd Mark Wielaard [mark@...]
Sent: 9. maí 2008 00:48
Viðtakandi: Thomas Fitzsimmons
Afrit: sound-dev@...; distro-pkg-dev@...
Efni: Re: <Sound Dev> Opening multiple output lines

Hi,

On Sun, 2008-05-04 at 19:19 +0200, Mark Wielaard wrote:

> I had the same problem with a similar setup and with applications that
> forget to close a line they don't use anymore (unfortunately this seems
> very common). With the current directaudio backend I don't see how multiple
> lines for the same hardware device could work though. So I am using a
> trick to look for "sloppy" applications. If the last line opened in the
> directaudio device was for the same hardware format then we silence that
> one first so we can hand out a new one. This seems to work surprisingly
> well. And it doesn't seem to interfere with applications that handle the
> hardware formats they need explicitly.
>
> With gcjwebplugin and this patch we can happily play the vNES games :)
>
> Of course a real solution would be to import or write a better mixer
> that does share lines properly.

I updated the patch a little to make it all a bit more robust. It splits
the locks, so there is no longer one gaint static one (I shouldn't have
reused the lockNative one and made that static in the original patch).

And it makes sure that all methods that require the nativeLock check the
doIO inside their synchronized block and the lock around nStop() isn't
released before the flag is set. ALSA can actually hang when called on a
pcm you already stopped or closed. This race was already in the code,
since a DataSourceLine could be asynchronously stopped or closed at any
time. My patch just exposed it more easily, because DirectAudioDevice is
the mixer that is now always used by defailt.

2008-05-08  Mark Wielaard  <mark@...>

        * patches/icedtea-directaudio-close-trick.patch: Use new static
        lockLast for nOpen/nClose guarding.  Make lockNative non-static
        again.  Do all checks before native calls of doIO inside
        lockNative guard. Set doIO to false after nClose before dropping
        lockNative guard.

I do think we should write a new MixerProvider based on a modern
soundserver, like pulseaudio. The current DirectAudioDeviceProvider code
cannot easily be extended to provide true software sound mixing. And the
way it opens direct hardware alsa devices means it locks out other
applications.

Cheers,

Mark

Patch against original code (updated patch file in icedtea6).

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.524 / Virus Database: 269.23.10/1421 - Release Date: 7.5.2008 17:23


_______________________________________________
audio-engine-dev mailing list
audio-engine-dev@...
http://mail.openjdk.java.net/mailman/listinfo/audio-engine-dev

Re: <Sound Dev> Opening multiple output lines

by Mark Wielaard :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Karl,

On Fri, 2008-05-09 at 19:58 +0000, Karl Helgason wrote:
> I added software sound mixing to the gervill Project which writes to default directaudio backend.
> And thus allows true sharing of audio device (within the Java application).

This is great! Sorry for the late response. I integrated it into
icedtea. But I haven't set it as default yet because I didn't have time
to fully test it. I do want to have it integrated so others can play
with it though.

Also thanks for your AudioFloatFormatConverter.getTargetFormats() fix, I
removed my own attempt of fixing that. And for integrating the dls/sf2
soundbank opening issues.

Also since we now have jtreg integrated I imported all the tests so they
will now all be run by default on a make check (or make jtregcheck).
That found two issues.

One with a test. TestRender1 accesses its test files through
getResourceAsStream(), but the jtreg tag specification recommends
opening files through the system property test.src so that the test can
be run inside another work directory. See
http://www.openjdk.org/jtreg/tag-spec.txt
Patch to change this attached.

The other issue is with the change that made SoftAudioProcessor
(limiter, reverb, chorus, agc) more general. Since you cannot provide a
Synthesizer directly to one of these classes you need a way to pass it
the control rate. Unfortunately SoftSynthesizer.getControlRate() is
currently protected and there is as far as I can see no other way to get
the control rate. So I believe the method should be made public. A
change to do this and adapt the tests to use this is attached.

With these changes all tests pass.

Cheers,

Mark

[TestRender1-test.src.patch]

Index: test/com/sun/media/sound/SoftSynthesizer/TestRender1.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftSynthesizer/TestRender1.java,v
retrieving revision 1.1
diff -u -r1.1 TestRender1.java
--- test/com/sun/media/sound/SoftSynthesizer/TestRender1.java 2 Jan 2008 12:24:16 -0000 1.1
+++ test/com/sun/media/sound/SoftSynthesizer/TestRender1.java 25 May 2008 19:07:10 -0000
@@ -29,6 +29,8 @@
 import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
@@ -134,13 +136,15 @@
 
  public static void main(String[] args) throws Exception {
 
- InputStream sb = new BufferedInputStream(TestRender1.class
- .getResourceAsStream("/ding.sf2"));
+ File fb = new File(System.getProperty("test.src", "."),
+   "ding.sf2");
+ InputStream sb = new FileInputStream(fb);
  soundbank = MidiSystem.getSoundbank(sb);
  sb.close();
 
- InputStream si = new BufferedInputStream(TestRender1.class
- .getResourceAsStream("/expresso.mid"));
+ File fi = new File(System.getProperty("test.src", "."),
+   "expresso.mid");
+ InputStream si = new FileInputStream(fi);
  sequence = MidiSystem.getSequence(si);
  si.close();
 


[controlrate.patch]

Index: src/com/sun/media/sound/SoftSynthesizer.java
===================================================================
RCS file: /cvs/gervill/src/com/sun/media/sound/SoftSynthesizer.java,v
retrieving revision 1.31
diff -u -r1.31 SoftSynthesizer.java
--- src/com/sun/media/sound/SoftSynthesizer.java 5 Mar 2008 03:35:22 -0000 1.31
+++ src/com/sun/media/sound/SoftSynthesizer.java 25 May 2008 19:12:24 -0000
@@ -331,7 +331,10 @@
  return deviceid;
  }
 
- protected float getControlRate() {
+ /**
+ * Returns the number of control changes per second.
+ */
+ public float getControlRate() {
  return controlrate;
  }
 
Index: test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix.java,v
retrieving revision 1.1
diff -u -r1.1 ProcessAudio_replace_mix.java
--- test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix.java 11 Dec 2007 02:49:18 -0000 1.1
+++ test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix.java 25 May 2008 19:12:24 -0000
@@ -71,7 +71,8 @@
  }
 
  SoftLimiter limiter = new SoftLimiter();
- limiter.init(synth);
+ limiter.init(synth.getFormat().getSampleRate(),
+     synth.getControlRate());
  limiter.setMixMode(true);
  limiter.setInput(0, in1);
  limiter.setInput(1, in2);
Index: test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_mono.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_mono.java,v
retrieving revision 1.1
diff -u -r1.1 ProcessAudio_replace_mix_mono.java
--- test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_mono.java 11 Dec 2007 02:49:19 -0000 1.1
+++ test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_mono.java 25 May 2008 19:12:24 -0000
@@ -63,7 +63,8 @@
  }
 
  SoftLimiter limiter = new SoftLimiter();
- limiter.init(synth);
+ limiter.init(synth.getFormat().getSampleRate(),
+     synth.getControlRate());
  limiter.setMixMode(true);
  limiter.setInput(0, in1);
  limiter.setOutput(0, out1);
Index: test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_mono_overdrive.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_mono_overdrive.java,v
retrieving revision 1.1
diff -u -r1.1 ProcessAudio_replace_mix_mono_overdrive.java
--- test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_mono_overdrive.java 11 Dec 2007 02:49:17 -0000 1.1
+++ test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_mono_overdrive.java 25 May 2008 19:12:24 -0000
@@ -64,7 +64,8 @@
  }
 
  SoftLimiter limiter = new SoftLimiter();
- limiter.init(synth);
+ limiter.init(synth.getFormat().getSampleRate(),
+     synth.getControlRate());
  limiter.setMixMode(true);
  limiter.setInput(0, in1);
  limiter.setOutput(0, out1);
Index: test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_overdrive.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_overdrive.java,v
retrieving revision 1.1
diff -u -r1.1 ProcessAudio_replace_mix_overdrive.java
--- test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_overdrive.java 11 Dec 2007 02:50:21 -0000 1.1
+++ test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_mix_overdrive.java 25 May 2008 19:12:24 -0000
@@ -71,7 +71,8 @@
  }
 
  SoftLimiter limiter = new SoftLimiter();
- limiter.init(synth);
+ limiter.init(synth.getFormat().getSampleRate(),
+     synth.getControlRate());
  limiter.setMixMode(true);
  limiter.setInput(0, in1);
  limiter.setInput(1, in2);
Index: test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_normal.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_normal.java,v
retrieving revision 1.1
diff -u -r1.1 ProcessAudio_replace_normal.java
--- test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_normal.java 11 Dec 2007 02:50:22 -0000 1.1
+++ test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_normal.java 25 May 2008 19:12:24 -0000
@@ -71,7 +71,8 @@
  }
 
  SoftLimiter limiter = new SoftLimiter();
- limiter.init(synth);
+ limiter.init(synth.getFormat().getSampleRate(),
+     synth.getControlRate());
  limiter.setMixMode(false);
  limiter.setInput(0, in1);
  limiter.setInput(1, in2);
Index: test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_normal_mono.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_normal_mono.java,v
retrieving revision 1.1
diff -u -r1.1 ProcessAudio_replace_normal_mono.java
--- test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_normal_mono.java 11 Dec 2007 02:50:23 -0000 1.1
+++ test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_normal_mono.java 25 May 2008 19:12:24 -0000
@@ -63,7 +63,8 @@
  }
 
  SoftLimiter limiter = new SoftLimiter();
- limiter.init(synth);
+ limiter.init(synth.getFormat().getSampleRate(),
+     synth.getControlRate());
  limiter.setMixMode(false);
  limiter.setInput(0, in1);
  limiter.setOutput(0, out1);
Index: test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_overdrive.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_overdrive.java,v
retrieving revision 1.1
diff -u -r1.1 ProcessAudio_replace_overdrive.java
--- test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_overdrive.java 11 Dec 2007 02:49:50 -0000 1.1
+++ test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_overdrive.java 25 May 2008 19:12:24 -0000
@@ -71,7 +71,8 @@
  }
 
  SoftLimiter limiter = new SoftLimiter();
- limiter.init(synth);
+ limiter.init(synth.getFormat().getSampleRate(),
+     synth.getControlRate());
  limiter.setMixMode(false);
  limiter.setInput(0, in1);
  limiter.setInput(1, in2);
Index: test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_overdrive_mono.java
===================================================================
RCS file: /cvs/gervill/test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_overdrive_mono.java,v
retrieving revision 1.1
diff -u -r1.1 ProcessAudio_replace_overdrive_mono.java
--- test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_overdrive_mono.java 11 Dec 2007 02:50:23 -0000 1.1
+++ test/com/sun/media/sound/SoftLimiter/ProcessAudio_replace_overdrive_mono.java 25 May 2008 19:12:24 -0000
@@ -63,7 +63,8 @@
  }
 
  SoftLimiter limiter = new SoftLimiter();
- limiter.init(synth);
+ limiter.init(synth.getFormat().getSampleRate(),
+     synth.getControlRate());
  limiter.setMixMode(false);
  limiter.setInput(0, in1);
  limiter.setOutput(0, out1);
 


_______________________________________________
audio-engine-dev mailing list
audio-engine-dev@...
http://mail.openjdk.java.net/mailman/listinfo/audio-engine-dev