Class SpeexEncoder


  • public class SpeexEncoder
    extends java.lang.Object
    Main Speex Encoder class. This class encodes the given PCM 16bit samples into Speex packets.
    Version:
    $Revision: 1.6 $
    Author:
    Marc Gimpel, Wimba S.A. (mgimpel@horizonwimba.com)
    • Constructor Summary

      Constructors 
      Constructor Description
      SpeexEncoder()
      Constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getChannels()
      Returns the number of channels.
      Encoder getEncoder()
      Returns the Encoder being used (Narrowband, Wideband or Ultrawideband).
      int getFrameSize()
      Returns the size of a frame.
      int getProcessedData​(byte[] data, int offset)
      Pull the decoded data out into a byte array at the given offset and returns the number of bytes of encoded data just read.
      int getProcessedDataByteSize()
      Returns the number of bytes of encoded data ready to be read.
      int getSampleRate()
      Returns the sample rate.
      boolean init​(int mode, int quality, int sampleRate, int channels)
      Initialisation
      static void mapPcm16bitLittleEndian2Float​(byte[] pcm16bitBytes, int offsetInput, float[] samples, int offsetOutput, int length)
      Converts a 16 bit linear PCM stream (in the form of a byte array) into a floating point PCM stream (in the form of an float array).
      boolean processData​(byte[] data, int offset, int len)
      This is where the actual encoding takes place
      boolean processData​(float[] data, int numSamples)
      Encode an array of floats.
      boolean processData​(short[] data, int offset, int numShorts)
      Encode an array of shorts.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • VERSION

        public static final java.lang.String VERSION
        Version of the Speex Encoder
        See Also:
        Constant Field Values
      • bits

        private Bits bits
      • rawData

        private float[] rawData
      • sampleRate

        private int sampleRate
      • channels

        private int channels
      • frameSize

        private int frameSize
    • Constructor Detail

      • SpeexEncoder

        public SpeexEncoder()
        Constructor
    • Method Detail

      • init

        public boolean init​(int mode,
                            int quality,
                            int sampleRate,
                            int channels)
        Initialisation
        Parameters:
        mode - the mode of the encoder (0=NB, 1=WB, 2=UWB).
        quality - the quality setting of the encoder (between 0 and 10).
        sampleRate - the number of samples per second.
        channels - the number of audio channels (1=mono, 2=stereo, ...).
        Returns:
        true if initialisation successful.
      • getEncoder

        public Encoder getEncoder()
        Returns the Encoder being used (Narrowband, Wideband or Ultrawideband).
        Returns:
        the Encoder being used (Narrowband, Wideband or Ultrawideband).
      • getSampleRate

        public int getSampleRate()
        Returns the sample rate.
        Returns:
        the sample rate.
      • getChannels

        public int getChannels()
        Returns the number of channels.
        Returns:
        the number of channels.
      • getFrameSize

        public int getFrameSize()
        Returns the size of a frame.
        Returns:
        the size of a frame.
      • getProcessedData

        public int getProcessedData​(byte[] data,
                                    int offset)
        Pull the decoded data out into a byte array at the given offset and returns the number of bytes of encoded data just read.
        Parameters:
        data -
        offset -
        Returns:
        the number of bytes of encoded data just read.
      • getProcessedDataByteSize

        public int getProcessedDataByteSize()
        Returns the number of bytes of encoded data ready to be read.
        Returns:
        the number of bytes of encoded data ready to be read.
      • processData

        public boolean processData​(byte[] data,
                                   int offset,
                                   int len)
        This is where the actual encoding takes place
        Parameters:
        data -
        offset -
        len -
        Returns:
        true if successful.
      • processData

        public boolean processData​(short[] data,
                                   int offset,
                                   int numShorts)
        Encode an array of shorts.
        Parameters:
        data -
        offset -
        numShorts -
        Returns:
        true if successful.
      • processData

        public boolean processData​(float[] data,
                                   int numSamples)
        Encode an array of floats.
        Parameters:
        data -
        numSamples -
        Returns:
        true if successful.
      • mapPcm16bitLittleEndian2Float

        public static void mapPcm16bitLittleEndian2Float​(byte[] pcm16bitBytes,
                                                         int offsetInput,
                                                         float[] samples,
                                                         int offsetOutput,
                                                         int length)
        Converts a 16 bit linear PCM stream (in the form of a byte array) into a floating point PCM stream (in the form of an float array). Here are some important details about the encoding:
        • Java uses big endian for shorts and ints, and Windows uses little Endian. Therefore, shorts and ints must be read as sequences of bytes and combined with shifting operations.
        Parameters:
        pcm16bitBytes - - byte array of linear 16-bit PCM formated audio.
        offsetInput -
        samples - - float array to receive the 16-bit linear audio samples.
        offsetOutput -
        length -