PCM to uLaw encoding

All your problems with Audio, Video and Images.

PCM to uLaw encoding

Postby herbertmunch » Thu Nov 03, 2011 11:29 am

Hi all!

I'm trying to encode raw pcm data as uLaw to save on the bandwidth required to transmit speech data.

I have come across a class called UlawEncoderInputStream on http://www.devdaily.com/java/jwarehouse/android/core/java/android/speech/srec/UlawEncoderInputStream.java.shtml but there is no documentation :shock: !

The constructor takes an input stream and a max pcm value (whatever that is).

Code: Select all
     * Create an InputStream which takes 16 bit pcm data and produces ulaw data.
     * @param in InputStream containing 16 bit pcm data.
     * @param max pcm value corresponding to maximum ulaw value.
    public UlawEncoderInputStream(InputStream in, int max) {

After looking through the code, I suspect that i should calculate this "max" value using a supplied function: maxAbsPcm. Problem is, i dont really understand what I'm meant to pass into it! I am recording my raw pcm to a file on the sdcard so I dont have one continuous memory resident array of data to pass to this.

Code: Select all
     * Compute the maximum of the absolute value of the pcm samples.
     * The return value can be used to set ulaw encoder scaling.
     * @param pcmBuf array containing 16 bit pcm data.
     * @param offset offset of start of 16 bit pcm data.
     * @param length number of pcm samples (not number of input bytes)
     * @return maximum abs of pcm data values
    public static int maxAbsPcm(byte[] pcmBuf, int offset, int length) {

Another problem I have using this code is I am unsure what values to write out for the header for uLaw data. How do i determine how much less byte data there is after encoding with uLaw?

I have listened to one of the (potentially) uLaw encoded files that I created in VLC media player (the only player i have that will attempt to read the file) and its sounds nasty, broken and clicky but can still make out the voice.

I am writing my wave header using code similar to a class I found called WaveHeader which can be found http://gitorious.org/android-eeepc/base/blobs/48276ab989a4d775961ce30a43635a317052672a/core/java/android/speech/srec/WaveHeader.java".

If anyone has any thoughts on this matter I would be most grateful to hear them! :D

Many thanks
Once Poster
Once Poster
Posts: 1
Joined: Thu Nov 03, 2011 11:21 am


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 5 guests