Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5001959

Short tick sound after finished playing with SourceDataLine

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta2
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: fb126949 Date: 02/24/2004


      Reported from a user on javasound-interest:

      When I play sounds I often get a very short tick
      shortly after writing the sound data to the
      SourceDataLine. I wrote this short program below for
      another purpose but it demonstrates it clearly. I
      would be curious to know if others hear the tick as
      well or if it is just my computer/soundcard. Higher
      sample rates make the tick less pronounced. Larger
      buffers cause the tick to come later.


      import javax.sound.sampled.*;

      public class test {
       public static void main(String[] args) {
        int seconds = 2;
        int sampleRate = 8000;
        double frequency = 1000.0;
        double RAD = 2.0 * Math.PI;
        try {
         AudioFormat af =
           new AudioFormat((float)sampleRate,8,1,true,true);
         DataLine.Info info =
           new DataLine.Info(SourceDataLine.class,af);
         SourceDataLine source =
           (SourceDataLine)AudioSystem.getLine(info);
         source.open(af);
         source.start();
         byte[] buf = new byte[sampleRate * seconds];
         for (int i=0; i<buf.length; i++) {
          buf[i] =
           (byte)(Math.sin(RAD*frequency/sampleRate*i)*127.0);
      // System.out.println(buf[i]);
         }
         source.write(buf,0,buf.length);
         source.drain();
         source.stop();
         source.close();
        } catch (Exception e) {
         System.out.println(e);
        }
        System.exit(0);
       }
      }


      ======================================================================

      More info from submitter:
      The file I've been using is the 1-welcome.wav file that came with JavaSound 1.2 or 1.3. It is attached. The problem is related to the Clip. If I try to play the same file by writing bytes to a SourceDataLine it works fine.

        Attachments

          Activity

            People

            Assignee:
            fbomerssunw Florian Bomers (Inactive)
            Reporter:
            fbomerssunw Florian Bomers (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: