[1.5.0]sampled stuff isn't working anymore

[quote]Found a bugreport on AudioClip… http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5070730
[/quote]
Ah, there it is:[quote]
Thus this is java sound’s problem, not applet’s one.
xxxxx@xxxxx 2004-09-17

This might be either java sound or io problem, reassigning to javasound for further
investigation.
xxxxx@xxxxx 2004-09-17
[/quote]
So I guess we should all vote on this bug? It’s just four votes so far. :frowning:

Ye, well I’m wondering if it’s the right one to vote for. The whole sound stuff is b0rked in my case (except manually triggered midi events).

[quote]Ye, well I’m wondering if it’s the right one to vote for. The whole sound stuff is b0rked in my case (except manually triggered midi events).
[/quote]
Ok. Then somebody please file a “borq sound” bug and annotate it here so we all can vote for it.

Bombadil,

I was checking the problem with JavaSound driver of Xith3D and found that the problems happen only with direct audio drivers. I tried to fall back to Software Mixer, and everything is working fine again. If this workaround is OK for you, you can use the following code to get software mixer:

    public Mixer getMixer() {
        Mixer.Info[] mixers = AudioSystem.getMixerInfo();
        for (int i = 0; i < mixers.length; i++) {
            if ("Java Sound Audio Engine".equals(mixers[i].getName())) {
                return AudioSystem.getMixer(mixers[i]);
            }
        }
        return null;
    }

...
        Mixer mix = getMixer();
        // Use selected (compatible) Mixer, or fall back to default system Mixer if no compatible one found
        if (mix != null)
            clip = (Clip) mix.getLine(...);
        else
            clip = (Clip) AudioSystem.getLine(...);
        clip.open(sb.af,sb.data,0,sb.size);
    }

Yuri

[quote]I was checking the problem with JavaSound driver of Xith3D and found that the problems happen only with direct audio drivers. I tried to fall back to Software Mixer, and everything is working fine again. If this workaround is OK for you, you can use the following code to get software mixer
[/quote]
Thanks Yuri, this works perfect. Welcome back on the forum. :slight_smile:
So, does Xith now also use this workaround, ie Java software mixer for sound?

Does the software mixer mean a big performance decrease in contrast to other mixers, or is it marginal?

That workaround isn’t working for me :-/

However, I just found out that I can play rather long wavs pretty fine. Eg like so:
http://www.jsresources.org/examples/SimpleAudioPlayer.java.html

But short ones doesn’t work at all and rather short ones randomly work :frowning:

Hi,

[quote]So, does Xith now also use this workaround, ie Java software mixer for sound?
[/quote]
Yes.

[quote]Does the software mixer mean a big performance decrease in contrast to other mixers, or is it marginal?
[/quote]
Not really. It was default implementation in Java 1.4.2.

Yuri

Alright. I just voted for 5070730 after some research.

just got hit by same bug - reverting to software mixer works - go figure.

but when I shutdown the sound engine, I get some strange sounds - like something run backwards.

I shutdown the sound engine by enumerating all clips and calling close on them. If I don’t do that, it shutdowns quicker and I don’t get any distorted sound effects.

and only java 1.4 & 1.5 does this - 1.3 doesn’t.

+[quote]That workaround isn’t working for me :-/
[/quote]
Strange. So… since the software mixer has been the standard way to play Javasound prior to Java 1.5 (according to Yuri’s article), how have you ever been able to hear Javasound before 1.5 ? :slight_smile:

Would you mind testing this small class; for me it works fine with Java 1.5 thanks to Yuri. You just need to call the constructor with some Sample.wav string for example, and then call “starte()” on the object.


import java.io.IOException;
import java.io.InputStream;
import javax.sound.sampled.*;

public class Klang
{
  private static Mixer mMixer;

  private byte[]        mSampledaten;
  private AudioFormat   mAudioformat;
  private DataLine.Info mDatlinInfo;

  static
  {
    Mixer.Info[] mixers = AudioSystem.getMixerInfo();
    for (int i = 0; i < mixers.length; i++) {
      if ("Java Sound Audio Engine".equals(mixers[i].getName())) {
        mMixer = AudioSystem.getMixer(mixers[i]);
      }
    }
  }

  /**
   * @param  Wav-Dateiname.
   */
  Klang(final String dateiname)
  {
    try
    {
      InputStream istrom = new BufferedInputStream(FileInputStream(dateiname));

      AudioInputStream tonstrom = AudioSystem.getAudioInputStream(istrom);
      mAudioformat = tonstrom.getFormat();

      int bytelänge = (int) (mAudioformat.getFrameSize() * tonstrom.getFrameLength());
      mSampledaten  = new byte[bytelänge];
      tonstrom.read(mSampledaten, 0, bytelänge);

      mDatlinInfo = new DataLine.Info(Clip.class, mAudioformat);
      if (! AudioSystem.isLineSupported(mDatlinInfo)) {
        System.err.println("Audio-Linie nicht unterstützt!");
      }
    }
    catch (UnsupportedAudioFileException ex) {
      System.err.println("Audio-Dateiformat nicht unterstützt: " + ex);
    }
    catch (IOException ex) {
      System.err.println(ex);
    }
  }

  /**
   * @return  Ob erfolgreich gestartet.
   */
  public boolean starte()
  {
    Clip klip;
    try {
      if (mMixer != null) {
        klip = (Clip) mMixer.getLine(mDatlinInfo);
      }
      else {
        klip = (Clip) AudioSystem.getLine(mDatlinInfo);
      }
      klip.open(mAudioformat, mSampledaten, 0, mSampledaten.length);
    }
    catch (LineUnavailableException ex)  {
      System.err.println("Klang konnte nicht gestartet werden: " + ex);
      return false;
    }

    klip.start();
    return true;
  }
}

Cheers Bombadil. Yea… it works… doh…

I had… private Mixer mix;… ok… and then later I had… Mixer mix=… ::slight_smile:

My stupidity is unmatched! My sillyness knows no equal! :stuck_out_tongue:

Ahyea… great. ;D

[quote]Cheers Bombadil. Yea… it works… doh…
[/quote]
Well, this is nice. So finally we’ve got a solid way to sound with Java 1.5: via the old mixer, hehe.

[quote]I had… private Mixer mix;… ok… and then later I had… Mixer mix=… ::slight_smile:
[/quote]
Oh yes, I know this kind of error. A pity my favourite IDE JBuilder still doesn’t mark it with a warning - although it knows “Audit” warnings for so many things (several of them pretty useless).

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5070730
(quotet before)

Status: “Closed, fixed”

Nice.

Ye, I was about to post the same :slight_smile:

Meh… so what I’m supposed to do with that workaround? Remove it when a newer 1.5 appeared? Leave it there… forever?

Have I hit the same bug?

I’ve written a seekable InputStream for my modplayer, and verified that it spits bytes out (so I should hear /something/, even if it is just noise :).

The following code is silent:


            AudioFormat format = new AudioFormat( rate, 16, 2, true, false );
            AudioInputStream ais = new AudioInputStream( new IBXMInputStream( i ), format, i.getSongLength() );
            Clip c = AudioSystem.getClip();
            c.open( ais );
            c.start();

[quote]Have I hit the same bug?
[/quote]
No I haven’t. A bug in my read method caused it to return 0 every time. I’m surprised I can get anything I write to work these days :-[

Clips seem to work every time for me, although streaming mods through the clip interface is slow and takes up enormous amounts of memory. It’s obviously not designed for that.

[quote]Have I hit the same bug?

I’ve written a seekable InputStream for my modplayer, and verified that it spits bytes out (so I should hear /something/, even if it is just noise :).

The following code is silent:


            AudioFormat format = new AudioFormat( rate, 16, 2, true, false );
            AudioInputStream ais = new AudioInputStream( new IBXMInputStream( i ), format, i.getSongLength() );
            Clip c = AudioSystem.getClip();
            c.open( ais );
            c.start();

[/quote]