Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Java convert uLaw encoded audio file to PCM ecoded

Java convert uLaw encoded audio file to PCM ecoded

Scheduled Pinned Locked Moved Java
javahelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Moonis Ahmed
    wrote on last edited by
    #1

    Hi, I want to convert a ULAW encoded .wav file into a PCM encoded one. The ULAW encoded .wav file is of 8 bit, mono with 8Khz sample rate. How can I achieve this. I have written a code below but it gives error that the conversion is not supported. I am using javax.sound.sampled class. below is the code.

    try{

    File temp = new File("C:/temp.wav");
    File fileout = new File("C:/1java.wav");
    AudioInputStream sourceaudio = AudioSystem.getAudioInputStream(temp);
    AudioFormat targetformat = new AudioFormat(new AudioFormat.Encoding("PCM\_UNSIGNED"),8000,16,0,8,8000,true);
    AudioFileFormat.Type targettype = AudioFileFormat.Type.WAVE;
    AudioInputStream targetaudiostream = AudioSystem.getAudioInputStream(targetformat,sourceaudio);
    AudioSystem.write(targetaudiostream, targettype, fileout);
    }
    catch(Exception e){
        out.println("Error in audio format conversion");
        e.printStackTrace();
        }
    
    4 1 Reply Last reply
    0
    • M Moonis Ahmed

      Hi, I want to convert a ULAW encoded .wav file into a PCM encoded one. The ULAW encoded .wav file is of 8 bit, mono with 8Khz sample rate. How can I achieve this. I have written a code below but it gives error that the conversion is not supported. I am using javax.sound.sampled class. below is the code.

      try{

      File temp = new File("C:/temp.wav");
      File fileout = new File("C:/1java.wav");
      AudioInputStream sourceaudio = AudioSystem.getAudioInputStream(temp);
      AudioFormat targetformat = new AudioFormat(new AudioFormat.Encoding("PCM\_UNSIGNED"),8000,16,0,8,8000,true);
      AudioFileFormat.Type targettype = AudioFileFormat.Type.WAVE;
      AudioInputStream targetaudiostream = AudioSystem.getAudioInputStream(targetformat,sourceaudio);
      AudioSystem.write(targetaudiostream, targettype, fileout);
      }
      catch(Exception e){
          out.println("Error in audio format conversion");
          e.printStackTrace();
          }
      
      4 Offline
      4 Offline
      4277480
      wrote on last edited by
      #2

      I personally did not try this but I found this link that will solve your problem http://www.mms-computing.co.uk/uk/co/mmscomputing/sound/ Do tell if you figure it out

      M 1 Reply Last reply
      0
      • 4 4277480

        I personally did not try this but I found this link that will solve your problem http://www.mms-computing.co.uk/uk/co/mmscomputing/sound/ Do tell if you figure it out

        M Offline
        M Offline
        Moonis Ahmed
        wrote on last edited by
        #3

        Hi, I was able to solve it using the inherent java audio class javax.sound.sampled. I convert an input audio file encoded in uLaw to PCM and then write the PCM file into an Audiostream. Code is given below.

        try{
        File filein = new File("C:/sourcefile.wav");
        File fileout = new File("C:/PCMfile.wav");
        AudioInputStream sourceaudio = AudioSystem.getAudioInputStream(filein);
        AudioFormat format = sourceaudio.getFormat();
        if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
        format = new AudioFormat(
        AudioFormat.Encoding.PCM_SIGNED,
        format.getSampleRate(),
        format.getSampleSizeInBits() * 2,
        format.getChannels(),
        format.getFrameSize() * 2,
        format.getFrameRate(),
        true);
        }
        AudioFileFormat.Type targettype = AudioFileFormat.Type.WAVE;
        AudioInputStream targetaudiostream = AudioSystem.getAudioInputStream(format, sourceaudio);
        AudioSystem.write(targetaudiostream, targettype, fileout);
        System.out.println("PCM encoded file generated successfully.");
        sourceaudio.close();
        targetaudiostream.close();
        } catch (Exception e) {
        out.println("Error in audio format conversion");
        e.printStackTrace();
        }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups