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

AudioSystem/WaveFileWriter can't write PCM_FLOAT, but writes it anyway

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 8u25
    • client-libs
    • b105
    • x86
    • os_x

    Description

      FULL PRODUCT VERSION :
      java -version
      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin mankell 13.4.0 Darwin Kernel Version 13.4.0: Sun Aug 17 19:50:11 PDT 2014; root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      AudioSystem is capable of reading floating point wave files. According to AudioFormat they have an encoding of PCM_FLOAT.

      Via AudioSystem it is also possible to write those files, however, the result is garbage.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Write a PCM_FLOAT encoded file using AudioSystem.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The file should be encoded as PCM_FLOAT or AudioSystem should cry foul and not write it.
      ACTUAL -
      AudioSystem writes a file that it claims to be PCM_SIGNED, but that contains the float samples. In other words: claimed format in the header and actual sample format don't match.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.sound.sampled.AudioFileFormat;
      import javax.sound.sampled.AudioFormat;
      import javax.sound.sampled.AudioInputStream;
      import javax.sound.sampled.AudioSystem;
      import java.io.File;

      import static javax.sound.sampled.AudioFileFormat.Type.WAVE;
      import static javax.sound.sampled.AudioFormat.Encoding.PCM_FLOAT;

      public class TestReadWrite32BitFloat {

          public static void main(String[] args) throws Exception {
              final File file = new File("test32BitFloat.wav"); // this must be PCM_FLOAT encoded
              // you can create one, e.g. with "sox test.wav -b 32 -e floating-point test32BitFloat.wav"
              final File out = new File("out32BitFloat.wav");
              AudioInputStream in = AudioSystem.getAudioInputStream(file);
              AudioSystem.write(in, WAVE, out);
              // now play the file, listen and cry...
              AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(out);
              AudioFormat.Encoding encoding = fileFormat.getFormat().getEncoding();
              if (!encoding.equals(PCM_FLOAT)) {
                  throw new Exception("Wrong encoding: " + encoding);
              }
          }

      }

      ---------- END SOURCE ----------

      Attachments

        Activity

          People

            serb Sergey Bylokhov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: