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

AudioInputStream.reset doesn't skip the header

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.3.0
    • client-libs



      Name: krT82822 Date: 02/07/2000


      java version "1.3.0rc1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
      Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)

      When one opens a file with AudioSystem and starts to read the data, he just gets
      the waveform data, which is expected.
      However, if he call reset() on the AudioInputStream before starting to read, he
      will first get the header of the file. Since one is reading an
      _Audio_InputStream, it's not normal to be able to read non audio data.


      Here an example:
      import java.io.*;
      import javax.sound.sampled.*;

      public class Test {
        public static void main(String[] args) {
          try {
            File file = new File("test.wav");
            AudioInputStream audioIS = AudioSystem.getAudioInputStream(file);

            byte[] b = new byte[audioIS.getFormat().getFrameSize()];
            for (int j = 40; j >= 0; j--) {
              audioIS.read(b);
              for (int i = 0; i < b.length; i++)
                System.out.print(b[i] + " ");
            }
            System.out.println();

            audioIS.reset();

            for (int j = 40; j >= 0; j--) {
              audioIS.read(b);
              for (int i = 0; i < b.length; i++)
                System.out.print(b[i] + " ");
            }
            System.out.println();
          }
          catch (IOException e) {
            e.printStackTrace();
          }
          catch (UnsupportedAudioFileException e) {
            e.printStackTrace();
          }
        }
      }

      Here is the result:
      -16 1 10 2 -15 1 -18 1 -16 1 -21 1 -29 1 -45 1 -4 1 -27 1 -8 1 -18 1 53 2 -15 1
      -48 -1 -89 -1 -58 -1 -103 -1 -91 -1 -105 -1 -70 -1 -45 -1 -32 -1 -67 -1 -92 -1 -
      83 -1 -90 -1 -114 -1 -103 -1 -105 -1 -124 -1 -75 -1 -101 -1 -91 -1 -84 -1 -85 -1
       -26 -1 -70 -1 -85 -1 -75 -1 -87 -1
      82 73 70 70 -124 109 0 0 87 65 86 69 102 109 116 32 16 0 0 0 1 0 1 0 -128 62 0 0
       0 125 0 0 2 0 16 0 100 97 116 97 96 109 0 0 -16 1 10 2 -15 1 -18 1 -16 1 -21 1
      -29 1 -45 1 -4 1 -27 1 -8 1 -18 1 53 2 -15 1 -48 -1 -89 -1 -58 -1 -103 -1 -91 -1

      the first four lines are before calling reset, it's the waveform.
      the next three lines are after a reset. The waveform data starts in the middle
      of the second line.
      (Review ID: 100923)
      ======================================================================

            fbomerssunw Florian Bomers (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: