title: mp3 to wav conversion in java
body: <p>My code to convert mp3 to wav is:</p>
  
  <pre><code>package audio1;
  
  import java.io.File;
  import javax.sound.sampled.AudioFileFormat;
  import javax.sound.sampled.AudioFormat;
  import javax.sound.sampled.AudioInputStream;
  import javax.sound.sampled.AudioSystem;
  
  public class NewClass {
      public static void main(String [] args){
          try{
              AudioFileFormat inputFileFormat = AudioSystem.getAudioFileFormat(new File("c:\\1.mp3"));
              AudioInputStream ais = AudioSystem.getAudioInputStream(new File("c:\\1.mp3"));
  
              AudioFormat audioFormat = ais.getFormat();
  
              System.out.println("File Format Type: "+inputFileFormat.getType());
              System.out.println("File Format String: "+inputFileFormat.toString());
              System.out.println("File lenght: "+inputFileFormat.getByteLength());
              System.out.println("Frame length: "+inputFileFormat.getFrameLength());
              System.out.println("Channels: "+audioFormat.getChannels());
              System.out.println("Encoding: "+audioFormat.getEncoding());
              System.out.println("Frame Rate: "+audioFormat.getFrameRate());
              System.out.println("Frame Size: "+audioFormat.getFrameSize());
              System.out.println("Sample Rate: "+audioFormat.getSampleRate());
              System.out.println("Sample size (bits): "+audioFormat.getSampleSizeInBits());
              System.out.println("Big endian: "+audioFormat.isBigEndian());
              System.out.println("Audio Format String: "+audioFormat.toString());
  
              AudioInputStream encodedASI = AudioSystem.getAudioInputStream(AudioFormat.Encoding.PCM_SIGNED, ais);
  
              try{
                  int i = AudioSystem.write(encodedASI, AudioFileFormat.Type.WAVE, new File("c:\\converted.wav"));
                  System.out.println("Bytes Written: "+i);
              }catch(Exception e){
                  e.printStackTrace();
              }
          }catch(Exception e){
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>But I am getting following output:</p>
  
  <pre><code>File Format Type: MP3
  File Format String: MP3 (.mp3) file, byte length: 9631340, data format: MPEG1L3 48000.0 Hz, unknown bits per sample, stereo, unknown frame size, 41.666668 frames/second, , frame length: 10030
  File lenght: 9631340
  Frame length: 10030
  Channels: 2
  Encoding: MPEG1L3
  Frame Rate: 41.666668
  Frame Size: -1
  Sample Rate: 48000.0
  Sample size (bits): -1
  Big endian: true
  Audio Format String: MPEG1L3 48000.0 Hz, unknown bits per sample, stereo, unknown frame size, 41.666668 frames/second, 
  java.lang.ArrayIndexOutOfBoundsException: 1
          at org.tritonus.sampled.convert.javalayer.MpegFormatConversionProvider$DecodedMpegAudioInputStream$DMAISObuffer.append(MpegFormatConversionProvider.java:386)
          at javazoom.jl.decoder.Obuffer.appendSamples(Unknown Source)
          at javazoom.jl.decoder.SynthesisFilter.compute_pcm_samples(Unknown Source)
          at javazoom.jl.decoder.SynthesisFilter.calculate_pcm_samples(Unknown Source)
          at javazoom.jl.decoder.LayerIIIDecoder.decode(Unknown Source)
          at javazoom.jl.decoder.LayerIIIDecoder.decodeFrame(Unknown Source)
          at javazoom.jl.decoder.Decoder.decodeFrame(Unknown Source)
          at org.tritonus.sampled.convert.javalayer.MpegFormatConversionProvider$DecodedMpegAudioInputStream.execute(MpegFormatConversionProvider.java:307)
          at org.tritonus.share.TCircularBuffer.read(TCircularBuffer.java:138)
          at org.tritonus.share.sampled.convert.TAsynchronousFilteredAudioInputStream.read(TAsynchronousFilteredAudioInputStream.java:194)
          at javax.sound.sampled.AudioInputStream.read(AudioInputStream.java:292)
          at com.sun.media.sound.PCMtoPCMCodec$PCMtoPCMCodecStream.read(PCMtoPCMCodec.java:506)
          at com.sun.media.sound.SunFileWriter$NoCloseInputStream.read(SunFileWriter.java:199)
          at java.io.SequenceInputStream.read(SequenceInputStream.java:208)
          at java.io.SequenceInputStream.read(SequenceInputStream.java:211)
          at java.io.InputStream.read(InputStream.java:101)
          at com.sun.media.sound.WaveFileWriter.writeWaveFile(WaveFileWriter.java:247)
          at com.sun.media.sound.WaveFileWriter.write(WaveFileWriter.java:145)
          at javax.sound.sampled.AudioSystem.write(AudioSystem.java:1354)
          at audio1.NewClass.main(NewClass.java:33)
  </code></pre>
  
  <p>Can anyone help me what I am doing wrong?</p>