TwoLAME 0.4.0 MPEG Audio Layer 2 encoder

Macros | Typedefs | Enumerations | Functions
twolame.h File Reference

Go to the source code of this file.

## Macros
#define | TWOLAME_SAMPLES_PER_FRAME (1152)

## Typedefs
typedef struct twolame_options_struct | twolame_options

## Enumerations
enum | TWOLAME_MPEG_mode { TWOLAME_AUTO_MODE = -1, TWOLAME_STEREO = 0, TWOLAME_JOINT_STEREO, TWOLAME_DUAL_CHANNEL, TWOLAME_MONO }
enum | TWOLAME_MPEG_version { , TWOLAME_MPEG2 = 0, TWOLAME_MPEG1 = 1 }
enum | TWOLAME_Padding { TWOLAME_PAD_NO = 0, TWOLAME_PAD_ALL }
enum | TWOLAME_Emphasis { TWOLAME_EMPHASIS_N = 0, TWOLAME_EMPHASIS_5 = 1, TWOLAME_EMPHASIS_C = 3 }

## Functions
TL_API const char * | get_twolame_version (void)
TL_API const char * | get_twolame_url (void)
TL_API void | twolame_print_config (twolame_options *glopts)
TL_API twolame_options * | twolame_init (void)
TL_API int | twolame_init_params (twolame_options *glopts)
TL_API int | twolame_encode_buffer (twolame_options *glopts, const short int leftpcm[], const short int rightpcm[], int num_samples, unsigned char *mp2buffer, int mp2buffer_size)
TL_API int | twolame_encode_buffer_interleaved (twolame_options *glopts, const short int pcm[], int num_samples, unsigned char *mp2buffer, int mp2buffer_size)
TL_API int | twolame_encode_buffer_float32 (twolame_options *glopts, const float leftpcm[], const float rightpcm[], int num_samples, unsigned char *mp2buffer, int mp2buffer_size)
int | twolame_encode_buffer_float32_interleaved (twolame_options *glopts, const float pcm[], int num_samples, unsigned char *mp2buffer, int mp2buffer_size)
TL_API int | twolame_encode_flush (twolame_options *glopts, unsigned char *mp2buffer, int mp2buffer_size)
TL_API void | twolame_close (twolame_options **glopts)
TL_API int | twolame_set_verbosity (twolame_options *glopts, int verbosity)
TL_API int | twolame_get_verbosity (twolame_options *glopts)
TL_API int | twolame_set_mode (twolame_options *glopts, TWOLAME_MPEG_mode mode)
TL_API TWOLAME_MPEG_mode | twolame_get_mode (twolame_options *glopts)
TL_API const char * | twolame_get_mode_name (twolame_options *glopts)
TL_API int | twolame_set_version (twolame_options *glopts, TWOLAME_MPEG_version version)
TL_API TWOLAME_MPEG_version | twolame_get_version (twolame_options *glopts)
TL_API const char * | twolame_get_version_name (twolame_options *glopts)
TL_API int | twolame_set_freeformat (twolame_options *glopts, int freef)
TL_API int | twolame_get_framelength (twolame_options *glopts)
TL_API int | twolame_set_psymodel (twolame_options *glopts, int psymodel)
TL_API int | twolame_get_psymodel (twolame_options *glopts)
TL_API int | twolame_set_num_channels (twolame_options *glopts, int num_channels)
TL_API int | twolame_get_num_channels (twolame_options *glopts)
TL_API int | twolame_set_scale (twolame_options *glopts, float scale)
TL_API float | twolame_get_scale (twolame_options *glopts)
TL_API int | twolame_set_scale_left (twolame_options *glopts, float scale)
TL_API float | twolame_get_scale_left (twolame_options *glopts)
TL_API int | twolame_set_scale_right (twolame_options *glopts, float scale)
TL_API float | twolame_get_scale_right (twolame_options *glopts)
TL_API int | twolame_set_in_samplerate (twolame_options *glopts, int samplerate)
TL_API int | twolame_get_in_samplerate (twolame_options *glopts)
TL_API int | twolame_set_out_samplerate (twolame_options *glopts, int samplerate)
TL_API int | twolame_get_out_samplerate (twolame_options *glopts)
TL_API int | twolame_set_bitrate (twolame_options *glopts, int bitrate)
TL_API int | twolame_get_bitrate (twolame_options *glopts)
TL_API int | twolame_set_brate (twolame_options *glopts, int bitrate)
TL_API int | twolame_get_brate (twolame_options *glopts)
TL_API int | twolame_set_padding (twolame_options *glopts, TWOLAME_Padding padding)
TL_API TWOLAME_Padding | twolame_get_padding (twolame_options *glopts)
TL_API int | twolame_set_energy_levels (twolame_options *glopts, int energylevels)
TL_API int | twolame_get_energy_levels (twolame_options *glopts)
TL_API int | twolame_set_num_ancillary_bits (twolame_options *glopts, int num)
TL_API int | twolame_get_num_ancillary_bits (twolame_options *glopts)
TL_API int | twolame_set_emphasis (twolame_options *glopts, TWOLAME_Emphasis emphasis)
TL_API TWOLAME_Emphasis | twolame_get_emphasis (twolame_options *glopts)
TL_API int | twolame_set_error_protection (twolame_options *glopts, int err_protection)
TL_API int | twolame_get_error_protection (twolame_options *glopts)
TL_API int | twolame_set_copyright (twolame_options *glopts, int copyright)
TL_API int | twolame_get_copyright (twolame_options *glopts)
TL_API int | twolame_set_original (twolame_options *glopts, int original)
TL_API int | twolame_get_original (twolame_options *glopts)
TL_API int | twolame_set_extension (twolame_options *glopts, int extension)
TL_API int | twolame_get_extension (twolame_options *glopts)
TL_API int | twolame_set_VBR (twolame_options *glopts, int vbr)
TL_API int | twolame_get_VBR (twolame_options *glopts)
TL_API int | twolame_set_VBR_level (twolame_options *glopts, float level)
TL_API float | twolame_get_VBR_level (twolame_options *glopts)
TL_API int | twolame_set_ATH_level (twolame_options *glopts, float level)
TL_API float | twolame_get_ATH_level (twolame_options *glopts)
TL_API int | twolame_set_VBR_max_bitrate_kbps (twolame_options *glopts, int bitrate)
TL_API int | twolame_get_VBR_max_bitrate_kbps (twolame_options *glopts)
TL_API int | twolame_set_quick_mode (twolame_options *glopts, int quickmode)
TL_API int | twolame_get_quick_mode (twolame_options *glopts)
TL_API int | twolame_set_quick_count (twolame_options *glopts, int quickcount)
TL_API int | twolame_get_quick_count (twolame_options *glopts)
TL_API int | twolame_set_DAB (twolame_options *glopts, int dab)
TL_API int | twolame_get_DAB (twolame_options *glopts)
TL_API int | twolame_set_DAB_xpad_length (twolame_options *glopts, int length)
TL_API int | twolame_get_DAB_xpad_length (twolame_options *glopts)
TL_API int | twolame_set_DAB_crc_length (twolame_options *glopts, int length)
TL_API int | twolame_set_DAB_scf_crc_length (twolame_options *glopts)
TL_API int | twolame_get_DAB_crc_length (twolame_options *glopts)
TL_API int | twolame_set_DAB_scf_crc (twolame_options *glopts, unsigned char *mp2buffer, int mp2buffer_size)

## Macro Definition Documentation

## ◆ TWOLAME_SAMPLES_PER_FRAME

#define TWOLAME_SAMPLES_PER_FRAME (1152)

Number of samples per frame of Layer 2 MPEG Audio

## Typedef Documentation

## ◆ twolame_options

typedef struct twolame_options_struct twolame_options

Opaque data type for the twolame encoder options.

## Enumeration Type Documentation

## ◆ TWOLAME_MPEG_mode

enum TWOLAME_MPEG_mode

MPEG modes

Enumerator
TWOLAME_AUTO_MODE | Choose Mode Automatically
TWOLAME_STEREO | Stereo
TWOLAME_JOINT_STEREO | Joint Stereo
TWOLAME_DUAL_CHANNEL | Dual Channel
TWOLAME_MONO | Mono

## ◆ TWOLAME_MPEG_version

enum TWOLAME_MPEG_version

MPEG Version.

MPEG2 is for Lower Sampling Frequencies - LSF < 32000.

Enumerator
TWOLAME_MPEG2 | MPEG-2 - for sample rates less than 32k
TWOLAME_MPEG1 | MPEG-1

## ◆ TWOLAME_Padding

enum TWOLAME_Padding

Padding types.

Enumerator
TWOLAME_PAD_NO | No Padding
TWOLAME_PAD_ALL | Pad all frames

## ◆ TWOLAME_Emphasis

enum TWOLAME_Emphasis

Emphasis types.

Enumerator
TWOLAME_EMPHASIS_N | No Emphasis
TWOLAME_EMPHASIS_5 | 50/15 ms
TWOLAME_EMPHASIS_C | CCIT J.17

## Function Documentation

## ◆ get_twolame_version()

TL_API const char* get_twolame_version | ( | void |  | ) |

Get the version number of the TwoLAME library. eg "0.3.1".

Returns
  The version number as a C string

## ◆ get_twolame_url()

TL_API const char* get_twolame_url | ( | void |  | ) |

Get the URL of the TwoLAME homepage. eg "http://www.twolame.org/".

Returns
  The url as a C string

## ◆ twolame_print_config()

TL_API void twolame_print_config | ( | twolame_options * | glopts | ) |

Print the library version and encoder parameter settings to STDERR.

Will display differnent ammounts of information depending on the verbosity setting. If verbosity is set to 0 then no message will be displayed.

Parameters

  glopts | Options pointer created by twolame_init()

## ◆ twolame_init()

TL_API twolame_options* twolame_init | ( | void |  | ) |

Initialise the twolame encoder.

Sets defaults for all parameters. Will return NULL if malloc() failed, otherwise returns a pointer which you then need to pass to all future API calls.

Returns
  a pointer to your new options data structure

## ◆ twolame_init_params()

TL_API int twolame_init_params | ( | twolame_options * | glopts | ) |

Prepare to start encoding.

You must call twolame_init_params() before you start encoding. It will check call your parameters to make sure they are valid, as well as allocating buffers and initising internally used variables.

Parameters

  glopts | Options pointer created by twolame_init()

Returns
  0 if all patameters are valid, non-zero if something is invalid

## ◆ twolame_encode_buffer()

TL_API int twolame_encode_buffer | ( | twolame_options * | glopts,
|  | const short int | leftpcm[],
|  | const short int | rightpcm[],
|  | int | num_samples,
|  | unsigned char * | mp2buffer,
|  | int | mp2buffer_size
| ) |  |

Encode some 16-bit PCM audio to MP2.

Takes 16-bit PCM audio samples from seperate left and right buffers and places encoded audio into mp2buffer.

Parameters

  glopts | twolame options pointer
  leftpcm | Left channel audio samples
  rightpcm | Right channel audio samples
  num_samples | Number of samples per channel
  mp2buffer | Buffer to place encoded audio into
  mp2buffer_size | Size of the output buffer

Returns
  The number of bytes put in output buffer or a negative value on error

## ◆ twolame_encode_buffer_interleaved()

TL_API int twolame_encode_buffer_interleaved | ( | twolame_options * | glopts,
|  | const short int | pcm[],
|  | int | num_samples,
|  | unsigned char * | mp2buffer,
|  | int | mp2buffer_size
| ) |  |

Encode some 16-bit PCM audio to MP2.

Takes interleaved 16-bit PCM audio samples from a single buffer and places encoded audio into mp2buffer.

Parameters

  glopts | twolame options pointer
  pcm | Audio samples for left AND right channels
  num_samples | Number of samples per channel
  mp2buffer | Buffer to place encoded audio into
  mp2buffer_size | Size of the output buffer

Returns
  The number of bytes put in output buffer or a negative value on error

## ◆ twolame_encode_buffer_float32()

TL_API int twolame_encode_buffer_float32 | ( | twolame_options * | glopts,
|  | const float | leftpcm[],
|  | const float | rightpcm[],
|  | int | num_samples,
|  | unsigned char * | mp2buffer,
|  | int | mp2buffer_size
| ) |  |

Encode some 32-bit PCM audio to MP2.

Takes 32-bit floating point PCM audio samples from seperate left and right buffers and places encoded audio into mp2buffer.

Note: the 32-bit samples are currently scaled down to 16-bit samples internally.

Parameters

  glopts | twolame options pointer
  leftpcm | Left channel audio samples
  rightpcm | Right channel audio samples
  num_samples | Number of samples per channel
  mp2buffer | Buffer to place encoded audio into
  mp2buffer_size | Size of the output buffer

Returns
  The number of bytes put in output buffer or a negative value on error

## ◆ twolame_encode_buffer_float32_interleaved()

int twolame_encode_buffer_float32_interleaved | ( | twolame_options * | glopts,
|  | const float | pcm[],
|  | int | num_samples,
|  | unsigned char * | mp2buffer,
|  | int | mp2buffer_size
| ) |  |

Encode some 32-bit PCM audio to MP2.

Takes 32-bit floating point PCM audio samples from a single buffer and places encoded audio into mp2buffer.

Parameters

  glopts | twolame options pointer
  pcm | Audio samples for left AND right channels
  num_samples | Number of samples per channel
  mp2buffer | Buffer to place encoded audio into
  mp2buffer_size | Size of the output buffer

Returns
  The number of bytes put in output buffer or a negative value on error

## ◆ twolame_encode_flush()

TL_API int twolame_encode_flush | ( | twolame_options * | glopts,
|  | unsigned char * | mp2buffer,
|  | int | mp2buffer_size
| ) |  |

Encode any remains buffered PCM audio to MP2.

Encodes any remaining audio samples in the libtwolame internal sample buffer. This function will return at most a single frame of MPEG Audio, and at least 0 frames.

Parameters

  glopts | twolame options pointer
  mp2buffer | Buffer to place encoded audio into
  mp2buffer_size | Size of the output buffer

Returns
  The number of bytes put in output buffer or a negative value on error

## ◆ twolame_close()

TL_API void twolame_close | ( | twolame_options ** | glopts | ) |

Shut down the twolame encoder.

Shuts down the twolame encoder and frees all memory that it previously allocated. You should call this once you have finished all your encoding. This function will set your glopts pointer to NULL for you.

Parameters

  glopts | pointer to twolame options pointer

## ◆ twolame_set_verbosity()

TL_API int twolame_set_verbosity | ( | twolame_options * | glopts,
|  | int | verbosity
| ) |  |

Set the verbosity of the encoder.

Sets how verbose the encoder is with the debug and informational messages it displays. The higher the number, the more messages it will display. Set to 0 for no status messages to STDERR ( error messages will still be displayed ).

Default: 1

Parameters

  glopts | pointer to twolame options pointer
  verbosity | integer between 0 and 10

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_verbosity()

TL_API int twolame_get_verbosity | ( | twolame_options * | glopts | ) |

Get the verbosity of the encoder.

Parameters

  glopts | pointer to twolame options pointer

Returns
  integer indicating the verbosity of the encoder (0-10)

## ◆ twolame_set_mode()

TL_API int twolame_set_mode | ( | twolame_options * | glopts,
|  | TWOLAME_MPEG_mode | mode
| ) |  |

Set the MPEG Audio Mode (Mono, Stereo, etc) for the output stream.

Default: TWOLAME_AUTO_MODE

Parameters

  glopts | pointer to twolame options pointer
  mode | the mode to set to

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_mode()

TL_API TWOLAME_MPEG_mode twolame_get_mode | ( | twolame_options * | glopts | ) |

Get the MPEG Audio mode of the output stream.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the MPEG audio mode

## ◆ twolame_get_mode_name()

TL_API const char* twolame_get_mode_name | ( | twolame_options * | glopts | ) |

Get a string name for the current MPEG Audio mode.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the name of the MPEG audio mode as a string

## ◆ twolame_set_version()

TL_API int twolame_set_version | ( | twolame_options * | glopts,
|  | TWOLAME_MPEG_version | version
| ) |  |

Set the MPEG version of the MPEG audio stream.

Default: TWOLAME_MPEG1

Parameters

  glopts | pointer to twolame options pointer
  version | the version to set to

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_version()

TL_API TWOLAME_MPEG_version twolame_get_version | ( | twolame_options * | glopts | ) |

Get the MPEG version of the output stream.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the MPEG version

## ◆ twolame_get_version_name()

TL_API const char* twolame_get_version_name | ( | twolame_options * | glopts | ) |

Get a string name for the current MPEG version.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the name of the MPEG version as a string

## ◆ twolame_set_freeformat()

TL_API int twolame_set_freeformat | ( | twolame_options * | glopts,
|  | int | freef
| ) |  |

Set the freeformat strem mode.

Parameters

  glopts | pointer to twolame options pointer
  freef | freeformat mode ( TRUE / FALSE )

Returns
  0

## ◆ twolame_get_framelength()

TL_API int twolame_get_framelength | ( | twolame_options * | glopts | ) |

Get the number of bytes per MPEG audio frame, for current settings.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the number of bytes per frame

## ◆ twolame_set_psymodel()

TL_API int twolame_set_psymodel | ( | twolame_options * | glopts,
|  | int | psymodel
| ) |  |

Set the Psychoacoustic Model used to encode the audio.

Default: 3

Parameters

  glopts | pointer to twolame options pointer
  psymodel | the psychoacoustic model number

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_psymodel()

TL_API int twolame_get_psymodel | ( | twolame_options * | glopts | ) |

Get the Psychoacoustic Model used to encode the audio.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the psychoacoustic model number

## ◆ twolame_set_num_channels()

TL_API int twolame_set_num_channels | ( | twolame_options * | glopts,
|  | int | num_channels
| ) |  |

Set the number of channels in the input stream.

If this is different the number of channels in the output stream (set by mode) then the encoder will automatically downmix/upmix the audio.

Default: 2

Parameters

  glopts | pointer to twolame options pointer
  num_channels | the number of input channels

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_num_channels()

TL_API int twolame_get_num_channels | ( | twolame_options * | glopts | ) |

Get the number of channels in the input stream.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the number of channels

## ◆ twolame_set_scale()

TL_API int twolame_set_scale | ( | twolame_options * | glopts,
|  | float | scale
| ) |  |

Set the scaling level for audio before encoding.

Set to 0 to disable.

Default: 0

Parameters

  glopts | pointer to twolame options pointer
  scale | the amount to scale by

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_scale()

TL_API float twolame_get_scale | ( | twolame_options * | glopts | ) |

Get the scaling level for audio before encoding.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the amount to scale audio sample by

## ◆ twolame_set_scale_left()

TL_API int twolame_set_scale_left | ( | twolame_options * | glopts,
|  | float | scale
| ) |  |

Set the scaling level for left channel audio before encoding.

Set to 0 to disable.

Default: 0

Parameters

  glopts | pointer to twolame options pointer
  scale | the amount to scale by

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_scale_left()

TL_API float twolame_get_scale_left | ( | twolame_options * | glopts | ) |

Get the scaling level for audio left channel before encoding.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the amount to scale left channel audio samples by

## ◆ twolame_set_scale_right()

TL_API int twolame_set_scale_right | ( | twolame_options * | glopts,
|  | float | scale
| ) |  |

Set the scaling level for right channel audio before encoding.

Set to 0 to disable.

Default: 0

Parameters

  glopts | pointer to twolame options pointer
  scale | the amount to scale by

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_scale_right()

TL_API float twolame_get_scale_right | ( | twolame_options * | glopts | ) |

Get the scaling level for audio right channel before encoding.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the amount to scale right channel audio samples by

## ◆ twolame_set_in_samplerate()

TL_API int twolame_set_in_samplerate | ( | twolame_options * | glopts,
|  | int | samplerate
| ) |  |

Set the samplerate of the PCM audio input.

Default: 44100

Parameters

  glopts | pointer to twolame options pointer
  samplerate | the samplerate in Hz

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_in_samplerate()

TL_API int twolame_get_in_samplerate | ( | twolame_options * | glopts | ) |

Get the samplerate of the PCM audio input.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the input samplerate

## ◆ twolame_set_out_samplerate()

TL_API int twolame_set_out_samplerate | ( | twolame_options * | glopts,
|  | int | samplerate
| ) |  |

Set the samplerate of the MPEG audio output.

Default: 44100

Parameters

  glopts | pointer to twolame options pointer
  samplerate | the samplerate in Hz

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_out_samplerate()

TL_API int twolame_get_out_samplerate | ( | twolame_options * | glopts | ) |

Get the samplerate of the MPEG audio output.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the output samplerate

## ◆ twolame_set_bitrate()

TL_API int twolame_set_bitrate | ( | twolame_options * | glopts,
|  | int | bitrate
| ) |  |

Set the bitrate of the MPEG audio output stream.

Default: 192

Parameters

  glopts | pointer to twolame options pointer
  bitrate | the bitrate in kbps

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_bitrate()

TL_API int twolame_get_bitrate | ( | twolame_options * | glopts | ) |

Get the bitrate of the MPEG audio output.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the output bitrate in kbps

## ◆ twolame_set_brate()

TL_API int twolame_set_brate | ( | twolame_options * | glopts,
|  | int | bitrate
| ) |  |

Set the bitrate of the MPEG audio output stream (LAME style).

Same as twolame_set_bitrate()

## ◆ twolame_get_brate()

TL_API int twolame_get_brate | ( | twolame_options * | glopts | ) |

Get the bitrate of the MPEG audio output stream (LAME style).

Same as twolame_get_bitrate()

## ◆ twolame_set_padding()

TL_API int twolame_set_padding | ( | twolame_options * | glopts,
|  | TWOLAME_Padding | padding
| ) |  |

Set frame padding for the MPEG audio output stream.

i.e. adjust frame sizes to achieve overall target bitrate

Default: TWOLAME_PAD_NO

Parameters

  glopts | pointer to twolame options pointer
  padding | the padding type

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_padding()

TL_API TWOLAME_Padding twolame_get_padding | ( | twolame_options * | glopts | ) |

Get the padding type of the MPEG audio output.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the output bitrate in kbps

## ◆ twolame_set_energy_levels()

TL_API int twolame_set_energy_levels | ( | twolame_options * | glopts,
|  | int | energylevels
| ) |  |

Enable/Disable Energy Level Extension.

Enable writing the peak PCM level (energy level) at the end of each MPEG audio frame (in the ancillary bits). This function will automatically call twolame_set_num_ancillary_bits() to set the required number of ancillary bits for this feature.

The energy level extension is commonly used in the broadcast industry for visualising the audio in editing applications without decoding.

Default: FALSE

Parameters

  glopts | pointer to twolame options pointer
  energylevels | energy level extension state (TRUE/FALSE)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_energy_levels()

TL_API int twolame_get_energy_levels | ( | twolame_options * | glopts | ) |

Get the Energy Level Extension state.

Parameters

  glopts | pointer to twolame options pointer

Returns
  state of the Energy Level Extension (TRUE/FALSE)

## ◆ twolame_set_num_ancillary_bits()

TL_API int twolame_set_num_ancillary_bits | ( | twolame_options * | glopts,
|  | int | num
| ) |  |

Set number of Ancillary Bits at end of frame.

Default: 0

Parameters

  glopts | pointer to twolame options pointer
  num | number of bits to reserve

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_num_ancillary_bits()

TL_API int twolame_get_num_ancillary_bits | ( | twolame_options * | glopts | ) |

Get the number of Ancillary Bits at end of frame.

Parameters

  glopts | pointer to twolame options pointer

Returns
  number of Ancillary Bits at end of frame

## ◆ twolame_set_emphasis()

TL_API int twolame_set_emphasis | ( | twolame_options * | glopts,
|  | TWOLAME_Emphasis | emphasis
| ) |  |

Set the type of pre-emphasis to be applied to the decoded audio.

Default: TWOLAME_EMPHASIS_N

Parameters

  glopts | pointer to twolame options pointer
  emphasis | the type of pre-emphasis

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_emphasis()

TL_API TWOLAME_Emphasis twolame_get_emphasis | ( | twolame_options * | glopts | ) |

Get the type of pre-emphasis to be applied to the decoded audio.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the type of pre-emphasis

## ◆ twolame_set_error_protection()

TL_API int twolame_set_error_protection | ( | twolame_options * | glopts,
|  | int | err_protection
| ) |  |

Enable/Disable CRC Error Protection.

Default: FALSE

Parameters

  glopts | pointer to twolame options pointer
  err_protection | error protection state (TRUE/FALSE)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_error_protection()

TL_API int twolame_get_error_protection | ( | twolame_options * | glopts | ) |

Get the CRC Error Protection state.

Parameters

  glopts | pointer to twolame options pointer

Returns
  state of Error Protection (TRUE/FALSE)

## ◆ twolame_set_copyright()

TL_API int twolame_set_copyright | ( | twolame_options * | glopts,
|  | int | copyright
| ) |  |

Set the MPEG Audio Copyright flag.

Indicates that MPEG stream is copyrighted.

Default: FALSE

Parameters

  glopts | pointer to twolame options pointer
  copyright | copyright flag state (TRUE/FALSE)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_copyright()

TL_API int twolame_get_copyright | ( | twolame_options * | glopts | ) |

Get the copright flag state

Parameters

  glopts | pointer to twolame options pointer

Returns
  state of the copyright flag (TRUE/FALSE)

## ◆ twolame_set_original()

TL_API int twolame_set_original | ( | twolame_options * | glopts,
|  | int | original
| ) |  |

Set the MPEG Audio Original flag.

Default: FALSE

Parameters

  glopts | pointer to twolame options pointer
  original | original flag state (TRUE/FALSE)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_original()

TL_API int twolame_get_original | ( | twolame_options * | glopts | ) |

Get the MPEG Audio Original flag state.

Parameters

  glopts | pointer to twolame options pointer

Returns
  state of the original flag (TRUE/FALSE)

## ◆ twolame_set_extension()

TL_API int twolame_set_extension | ( | twolame_options * | glopts,
|  | int | extension
| ) |  |

Set the MPEG Audio Private Extension flag.

Default: FALSE

Parameters

  glopts | pointer to twolame options pointer
  extension | extension flag state (TRUE/FALSE)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_extension()

TL_API int twolame_get_extension | ( | twolame_options * | glopts | ) |

Get the MPEG Audio Private Extension flag state.

Parameters

  glopts | pointer to twolame options pointer

Returns
  state of the extension flag (TRUE/FALSE)

## ◆ twolame_set_VBR()

TL_API int twolame_set_VBR | ( | twolame_options * | glopts,
|  | int | vbr
| ) |  |

Enable/Disable VBR (Variable Bit Rate) mode.

Default: FALSE

Parameters

  glopts | pointer to twolame options pointer
  vbr | VBR state (TRUE/FALSE)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_VBR()

TL_API int twolame_get_VBR | ( | twolame_options * | glopts | ) |

Get the VBR state.

Parameters

  glopts | pointer to twolame options pointer

Returns
  state of VBR (TRUE/FALSE)

## ◆ twolame_set_VBR_level()

TL_API int twolame_set_VBR_level | ( | twolame_options * | glopts,
|  | float | level
| ) |  |

Set the level/quality of the VBR audio.

The level value can is a measurement of quality - the higher the level the higher the average bitrate of the resultant file.

Default: 5.0

Parameters

  glopts | pointer to twolame options pointer
  level | quality level (-10 to 10)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_VBR_level()

TL_API float twolame_get_VBR_level | ( | twolame_options * | glopts | ) |

Get the level/quality of the VBR audio.

Parameters

  glopts | pointer to twolame options pointer

Returns
  quality value for VBR

## ◆ twolame_set_ATH_level()

TL_API int twolame_set_ATH_level | ( | twolame_options * | glopts,
|  | float | level
| ) |  |

Set the adjustment (in dB) applied to the ATH for Psycho models 3 and 4.

Default: 0.0

Parameters

  glopts | pointer to twolame options pointer
  level | adjustment level in db

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_ATH_level()

TL_API float twolame_get_ATH_level | ( | twolame_options * | glopts | ) |

Get the adjustment (in dB) applied to the ATH for Psycho models 3 and 4.

Parameters

  glopts | pointer to twolame options pointer

Returns
  adjustment level in db

## ◆ twolame_set_VBR_max_bitrate_kbps()

TL_API int twolame_set_VBR_max_bitrate_kbps | ( | twolame_options * | glopts,
|  | int | bitrate
| ) |  |

Set the upper bitrate for VBR

Default: 0 (off)

Parameters

  glopts | pointer to twolame options pointer
  bitrate | upper bitrate for VBR

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_VBR_max_bitrate_kbps()

TL_API int twolame_get_VBR_max_bitrate_kbps | ( | twolame_options * | glopts | ) |

Get the upper bitrate for VBR.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the upper bitrate for VBR

## ◆ twolame_set_quick_mode()

TL_API int twolame_set_quick_mode | ( | twolame_options * | glopts,
|  | int | quickmode
| ) |  |

Enable/Disable the quick mode for psycho model calculation.

Default: FALSE

Parameters

  glopts | pointer to twolame options pointer
  quickmode | the state of quick mode (TRUE/FALSE)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_quick_mode()

TL_API int twolame_get_quick_mode | ( | twolame_options * | glopts | ) |

Get the state of quick mode.

Parameters

  glopts | pointer to twolame options pointer

Returns
  the state of quick mode (TRUE/FALSE)

## ◆ twolame_set_quick_count()

TL_API int twolame_set_quick_count | ( | twolame_options * | glopts,
|  | int | quickcount
| ) |  |

Set how often the psy model is calculated.

Default: 10

Parameters

  glopts | pointer to twolame options pointer
  quickcount | number of frames between calculations

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_quick_count()

TL_API int twolame_get_quick_count | ( | twolame_options * | glopts | ) |

Get the how often the psy model is calculated.

Parameters

  glopts | pointer to twolame options pointer

Returns
  number of frames between calculations

## ◆ twolame_set_DAB()

TL_API int twolame_set_DAB | ( | twolame_options * | glopts,
|  | int | dab
| ) |  |

Enable/Disable the Eureka 147 DAB extensions for MP2.

Default: FALSE

Parameters

  glopts | pointer to twolame options pointer
  dab | state of DAB extensions (TRUE/FALSE)

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_DAB()

TL_API int twolame_get_DAB | ( | twolame_options * | glopts | ) |

Get the state of the DAB extensions

Parameters

  glopts | pointer to twolame options pointer

Returns
  the state of DAB (TRUE/FALSE)

## ◆ twolame_set_DAB_xpad_length()

TL_API int twolame_set_DAB_xpad_length | ( | twolame_options * | glopts,
|  | int | length
| ) |  |

Set the number of bytes to reserve for DAB XPAD data.

Default: 0

Parameters

  glopts | pointer to twolame options pointer
  length | number of bytes to reserve

Returns
  0 if successful, non-zero on failure

## ◆ twolame_get_DAB_xpad_length()

TL_API int twolame_get_DAB_xpad_length | ( | twolame_options * | glopts | ) |

Get the number of bytes reserved for DAB XPAD data.

Parameters

  glopts | pointer to twolame options pointer

Returns
  number of XPAD bytes

## ◆ twolame_set_DAB_crc_length()

TL_API int twolame_set_DAB_crc_length | ( | twolame_options * | glopts,
|  | int | length
| ) |  |

Set the CRC error protection length for DAB. Note: Alternative method is: twolame_set_DAB_scf_crc_length.

Default: 2

Parameters

  glopts | pointer to twolame options pointer
  length | length of DAB CRC

Returns
  0 if successful, non-zero on failure

## ◆ twolame_set_DAB_scf_crc_length()

TL_API int twolame_set_DAB_scf_crc_length | ( | twolame_options * | glopts | ) |

Method that calculates and sets the length of the ScF-CRC field. The method must be called after initialization of bitrate, mpeg version and mpeg mode. If these conditions are met, the method can be used instead of twolame_set_DAB_crc_length.

Parameters

  glopts | pointer to twolame options pointer

## ◆ twolame_get_DAB_crc_length()

TL_API int twolame_get_DAB_crc_length | ( | twolame_options * | glopts | ) |

Get the CRC error protection length for DAB.

Parameters

  glopts | pointer to twolame options pointer

Returns
  length of DAB CRC

## ◆ twolame_set_DAB_scf_crc()

TL_API int twolame_set_DAB_scf_crc | ( | twolame_options * | glopts,
|  | unsigned char * | mp2buffer,
|  | int | mp2buffer_size
| ) |  |

Set the DAB ScF-CRC error protection. The front-end is responsible for holding at least two mp2 frames in memory to invoke this method.

For DAB to work properly follow these steps: First: Reserve enough bits in ancillary data field (options->num_ancillary_bits). Second: Put the encoder into "single frame mode" i.e. only read 1152 samples per channel. Third: When you receive an mp2 frame back from the library, call this method to insert the options->dabCrc[i] values to the previous mp2 frame.

Parameters

  glopts | pointer to twolame options pointer for the (N) encoded frame
  mp2buffer | buffer to the (N-1) encoded frame
  mp2buffer_size | the length (in bytes) of mp2buffer

Returns
  0 if successful, non-zero on failure