org.tritonus.lowlevel.lame
Class Lame

java.lang.Object
  extended by org.tritonus.lowlevel.lame.Lame

public class Lame
extends java.lang.Object

Low level wrapper for the LAME native encoder.


Field Summary
static int BITRATE_AUTO
           
static int CHANNEL_MODE_AUTO
           
static int CHANNEL_MODE_DUAL_CHANNEL
           
static int CHANNEL_MODE_JOINT_STEREO
           
static int CHANNEL_MODE_MONO
           
static int CHANNEL_MODE_STEREO
           
static int MPEG_VERSION_1
           
static int MPEG_VERSION_2
           
static int MPEG_VERSION_2DOT5
           
static AudioFormat.Encoding MPEG1L3
           
static AudioFormat.Encoding MPEG2DOT5L3
           
static AudioFormat.Encoding MPEG2L3
           
static java.lang.String P_BITRATE
          property key to read/set the bitrate: an Integer value.
static java.lang.String P_CHMODE
          property key to read/set the channel mode: a String, one of "jointstereo", "dual", "mono", "auto" (default).
static java.lang.String P_ENCODING
          legacy: system property key to read the effective encoding of the encoded audio data, an instance of AudioFormat.Encoding
static java.lang.String P_QUALITY
          property key to read/set the quality: an Integer from 1 (highest) to 9 (lowest).
static java.lang.String P_SAMPLERATE
          legacy: system property key to read the effective sample rate of the encoded audio stream (an instance of Float)
static java.lang.String P_VBR
          property key to read/set the VBR mode: an instance of Boolean (default: false)
static int QUALITY_HIGH
           
static int QUALITY_HIGHEST
           
static int QUALITY_LOW
           
static int QUALITY_LOWEST
           
static int QUALITY_MIDDLE
           
 
Constructor Summary
Lame(AudioFormat sourceFormat)
          Initializes the encoder with the given source/PCM format.
Lame(AudioFormat sourceFormat, AudioFormat targetFormat)
          Initializes the encoder with the given source/PCM format.
Lame(AudioFormat sourceFormat, int bitRate, int channelMode, int quality, boolean VBR)
          Initializes the encoder, overriding any parameters set in the audio format's properties or in the system properties.
 
Method Summary
 void close()
           
 int encodeBuffer(byte[] pcm, int offset, int length, byte[] encoded)
          Encode a block of data.
 int encodeFinish(byte[] encoded)
           
 int getEffectiveBitRate()
           
 int getEffectiveChannelMode()
           
 AudioFormat.Encoding getEffectiveEncoding()
           
 AudioFormat getEffectiveFormat()
          Return the audioformat representing the encoded mp3 stream.
 int getEffectiveQuality()
           
 int getEffectiveSampleRate()
           
 boolean getEffectiveVBR()
           
 java.lang.String getEncoderVersion()
           
static java.lang.String getLinkError()
           
 int getMP3BufferSize()
           
 int getPCMBufferSize()
          Returns the buffer needed pcm buffer size.
static boolean isLibAvailable()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MPEG1L3

public static final AudioFormat.Encoding MPEG1L3

MPEG2L3

public static final AudioFormat.Encoding MPEG2L3

MPEG2DOT5L3

public static final AudioFormat.Encoding MPEG2DOT5L3

P_ENCODING

public static final java.lang.String P_ENCODING
legacy: system property key to read the effective encoding of the encoded audio data, an instance of AudioFormat.Encoding

See Also:
Constant Field Values

P_SAMPLERATE

public static final java.lang.String P_SAMPLERATE
legacy: system property key to read the effective sample rate of the encoded audio stream (an instance of Float)

See Also:
Constant Field Values

P_VBR

public static final java.lang.String P_VBR
property key to read/set the VBR mode: an instance of Boolean (default: false)

See Also:
Constant Field Values

P_CHMODE

public static final java.lang.String P_CHMODE
property key to read/set the channel mode: a String, one of "jointstereo", "dual", "mono", "auto" (default).

See Also:
Constant Field Values

P_BITRATE

public static final java.lang.String P_BITRATE
property key to read/set the bitrate: an Integer value. Set to -1 for default bitrate.

See Also:
Constant Field Values

P_QUALITY

public static final java.lang.String P_QUALITY
property key to read/set the quality: an Integer from 1 (highest) to 9 (lowest).

See Also:
Constant Field Values

MPEG_VERSION_2

public static final int MPEG_VERSION_2
See Also:
Constant Field Values

MPEG_VERSION_1

public static final int MPEG_VERSION_1
See Also:
Constant Field Values

MPEG_VERSION_2DOT5

public static final int MPEG_VERSION_2DOT5
See Also:
Constant Field Values

QUALITY_LOWEST

public static final int QUALITY_LOWEST
See Also:
Constant Field Values

QUALITY_LOW

public static final int QUALITY_LOW
See Also:
Constant Field Values

QUALITY_MIDDLE

public static final int QUALITY_MIDDLE
See Also:
Constant Field Values

QUALITY_HIGH

public static final int QUALITY_HIGH
See Also:
Constant Field Values

QUALITY_HIGHEST

public static final int QUALITY_HIGHEST
See Also:
Constant Field Values

CHANNEL_MODE_STEREO

public static final int CHANNEL_MODE_STEREO
See Also:
Constant Field Values

CHANNEL_MODE_JOINT_STEREO

public static final int CHANNEL_MODE_JOINT_STEREO
See Also:
Constant Field Values

CHANNEL_MODE_DUAL_CHANNEL

public static final int CHANNEL_MODE_DUAL_CHANNEL
See Also:
Constant Field Values

CHANNEL_MODE_MONO

public static final int CHANNEL_MODE_MONO
See Also:
Constant Field Values

CHANNEL_MODE_AUTO

public static final int CHANNEL_MODE_AUTO
See Also:
Constant Field Values

BITRATE_AUTO

public static final int BITRATE_AUTO
See Also:
Constant Field Values
Constructor Detail

Lame

public Lame(AudioFormat sourceFormat)
Initializes the encoder with the given source/PCM format. The default mp3 encoding parameters are used, see DEFAULT_BITRATE, DEFAULT_CHANNEL_MODE, DEFAULT_QUALITY, and DEFAULT_VBR.

Throws:
java.lang.IllegalArgumentException - when parameters are not supported by LAME.

Lame

public Lame(AudioFormat sourceFormat,
            AudioFormat targetFormat)
Initializes the encoder with the given source/PCM format. The mp3 parameters are read from the targetFormat's properties. For any parameter that is not set, global system properties are queried for backwards tritonus compatibility. Last, parameters will use the default values DEFAULT_BITRATE, DEFAULT_CHANNEL_MODE, DEFAULT_QUALITY, and DEFAULT_VBR.

Throws:
java.lang.IllegalArgumentException - when parameters are not supported by LAME.

Lame

public Lame(AudioFormat sourceFormat,
            int bitRate,
            int channelMode,
            int quality,
            boolean VBR)
Initializes the encoder, overriding any parameters set in the audio format's properties or in the system properties.

Throws:
java.lang.IllegalArgumentException - when parameters are not supported by LAME.
Method Detail

getEncoderVersion

public java.lang.String getEncoderVersion()

getPCMBufferSize

public int getPCMBufferSize()
Returns the buffer needed pcm buffer size. The passed parameter is a wished buffer size. The implementation of the encoder may return a lower or higher buffer size. The encoder must be initalized (i.e. not closed) at this point. A return value of <0 denotes an error.


getMP3BufferSize

public int getMP3BufferSize()

encodeBuffer

public int encodeBuffer(byte[] pcm,
                        int offset,
                        int length,
                        byte[] encoded)
                 throws java.lang.ArrayIndexOutOfBoundsException
Encode a block of data. Throws IllegalArgumentException when parameters are wrong. When the encoded array is too small, an ArrayIndexOutOfBoundsException is thrown. length should be the value returned by getPCMBufferSize.

Returns:
the number of bytes written to encoded. May be 0.
Throws:
java.lang.ArrayIndexOutOfBoundsException

encodeFinish

public int encodeFinish(byte[] encoded)

close

public void close()

isLibAvailable

public static boolean isLibAvailable()

getLinkError

public static java.lang.String getLinkError()

getEffectiveFormat

public AudioFormat getEffectiveFormat()
Return the audioformat representing the encoded mp3 stream. The format object will have the following properties:


getEffectiveQuality

public int getEffectiveQuality()

getEffectiveBitRate

public int getEffectiveBitRate()

getEffectiveChannelMode

public int getEffectiveChannelMode()

getEffectiveVBR

public boolean getEffectiveVBR()

getEffectiveSampleRate

public int getEffectiveSampleRate()

getEffectiveEncoding

public AudioFormat.Encoding getEffectiveEncoding()