Note that there are some explanatory texts on larger screens.

plurals
  1. POJava AudioSystem .wav file discrepancy in behaviour
    primarykey
    data
    text
    <p>I have a number of .wav files I play from Java. In this stripped down example, "drip" is audible but "swish" is not even though they run via the same code. There does not seem to be anything unusual about "swish": it plays from the Gnome desktop. I have a similar app, not quite as stripped down that plays "swish" but not "drip" so again it does not seem to be a problem tied to the nature of the data. </p> <p>Any ideas what is happening here? This bug was noticed after code that was known to be working was "redeployed" on a rebuilt system: reinstalled Ubuntu 10.10 and Eclipse Indigo. This bug happens with both Sun JDK 6 and OpenJDK 6. <strong>Edit</strong> The "rebuilt" system is actually different hardware as well: Intel E6500 (2 cores, 2.93 GHz) I have only installed Ubuntu, Eclipse, OpenJDK, Sun JDK. The previous system was an AMD 630 (4 cores, 2.8 GHz) with Ubuntu, Eclipse, OpenJDK (I think).</p> <p><strong>Edit</strong> After some experimenting, it seems the first clip loaded will be the one that works. The TestSounder constructor loads them so that is where the order can be reversed. Perhaps the use of the static method <code>AudioSystem.getLine</code> has something to do with it since that is obviously the non-object oriented operation here.</p> <pre><code>import java.io.IOException; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.DataLine; import javax.sound.sampled.Clip; import javax.sound.sampled.UnsupportedAudioFileException; import javax.sound.sampled.LineUnavailableException; public class TestSounder { String resourcePathFromBin = "/resources/"; Clip dripClip; Clip swishClip; public TestSounder() { dripClip = setupClip("drip.wav"); swishClip = setupClip("swish.wav"); } public void close() { dripClip.close(); swishClip.close(); } private Clip setupClip(String fileName) { Clip clip = null; try { AudioInputStream ais = AudioSystem.getAudioInputStream(this.getClass().getResourceAsStream(resourcePathFromBin + fileName)); AudioFormat af = ais.getFormat(); DataLine.Info lineInfo = new DataLine.Info(Clip.class, af); clip = (Clip)AudioSystem.getLine(lineInfo); clip.open(ais); } catch (UnsupportedAudioFileException e) { assert false: "bug"; } catch (IOException e) { assert false: "bug"; } catch (LineUnavailableException e) { assert false: "bug"; } return clip; } public void go(UtilityK.Sounds s) { Clip clip = null; if (s == UtilityK.Sounds.drip) clip = dripClip; if (s == UtilityK.Sounds.swish) clip = swishClip; clip.stop(); clip.setFramePosition(0); clip.start(); //while (clip.isRunning()) // TestSounder.delay(); } public static void main(String[] args) { TestSounder obj = new TestSounder(); obj.go(UtilityK.Sounds.swish); TestSounder.delay(); obj.go(UtilityK.Sounds.drip); TestSounder.delay(); obj.go(UtilityK.Sounds.swish); TestSounder.delay(); obj.go(UtilityK.Sounds.drip); TestSounder.delay(); obj.close(); } private static void delay() { Thread.sleep(5000); } } public interface UtilityK { enum Sounds { drip, swish }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload