twolame 0.3.13
MPEGAudioLayer2encoder
|
Go to the source code of this file.
#define TWOLAME_SAMPLES_PER_FRAME (1152) |
Number of samples per frame of Layer 2 MPEG Audio
typedef struct twolame_options_struct twolame_options |
Opaque data type for the twolame encoder options.
enum TWOLAME_MPEG_mode |
enum TWOLAME_MPEG_version |
enum TWOLAME_Padding |
enum TWOLAME_Emphasis |
const char* get_twolame_version | ( | void | ) |
Get the version number of the TwoLAME library. eg "0.3.1".
const char* get_twolame_url | ( | void | ) |
Get the URL of the TwoLAME homepage. eg "http://www.twolame.org/".
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.
glopts | Options pointer created by twolame_init() |
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.
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.
glopts | Options pointer created by twolame_init() |
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.
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 |
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.
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 |
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.
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 |
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.
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 |
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.
glopts | twolame options pointer |
mp2buffer | Buffer to place encoded audio into |
mp2buffer_size | Size of the output buffer |
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.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
verbosity | integer between 0 and 10 |
int twolame_get_verbosity | ( | twolame_options * | glopts | ) |
Get the verbosity of the encoder.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
mode | the mode to set to |
TWOLAME_MPEG_mode twolame_get_mode | ( | twolame_options * | glopts | ) |
Get the MPEG Audio mode of the output stream.
glopts | pointer to twolame options pointer |
const char* twolame_get_mode_name | ( | twolame_options * | glopts | ) |
Get a string name for the current MPEG Audio mode.
glopts | pointer to twolame options pointer |
int twolame_set_version | ( | twolame_options * | glopts, |
TWOLAME_MPEG_version | version | ||
) |
Set the MPEG version of the MPEG audio stream.
Default: TWOLAME_MPEG1
glopts | pointer to twolame options pointer |
version | the version to set to |
TWOLAME_MPEG_version twolame_get_version | ( | twolame_options * | glopts | ) |
Get the MPEG version of the output stream.
glopts | pointer to twolame options pointer |
const char* twolame_get_version_name | ( | twolame_options * | glopts | ) |
Get a string name for the current MPEG version.
glopts | pointer to twolame options pointer |
int twolame_get_framelength | ( | twolame_options * | glopts | ) |
Get the number of bytes per MPEG audio frame, for current settings.
glopts | pointer to twolame options pointer |
int twolame_set_psymodel | ( | twolame_options * | glopts, |
int | psymodel | ||
) |
Set the Psychoacoustic Model used to encode the audio.
Default: 3
glopts | pointer to twolame options pointer |
psymodel | the psychoacoustic model number |
int twolame_get_psymodel | ( | twolame_options * | glopts | ) |
Get the Psychoacoustic Model used to encode the audio.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
num_channels | the number of input channels |
int twolame_get_num_channels | ( | twolame_options * | glopts | ) |
Get the number of channels in the input stream.
glopts | pointer to twolame options pointer |
int twolame_set_scale | ( | twolame_options * | glopts, |
float | scale | ||
) |
Set the scaling level for audio before encoding.
Set to 0 to disable.
Default: 0
glopts | pointer to twolame options pointer |
scale | the amount to scale by |
float twolame_get_scale | ( | twolame_options * | glopts | ) |
Get the scaling level for audio before encoding.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
scale | the amount to scale by |
float twolame_get_scale_left | ( | twolame_options * | glopts | ) |
Get the scaling level for audio left channel before encoding.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
scale | the amount to scale by |
float twolame_get_scale_right | ( | twolame_options * | glopts | ) |
Get the scaling level for audio right channel before encoding.
glopts | pointer to twolame options pointer |
int twolame_set_in_samplerate | ( | twolame_options * | glopts, |
int | samplerate | ||
) |
Set the samplerate of the PCM audio input.
Default: 44100
glopts | pointer to twolame options pointer |
samplerate | the samplerate in Hz |
int twolame_get_in_samplerate | ( | twolame_options * | glopts | ) |
Get the samplerate of the PCM audio input.
glopts | pointer to twolame options pointer |
int twolame_set_out_samplerate | ( | twolame_options * | glopts, |
int | samplerate | ||
) |
Set the samplerate of the MPEG audio output.
Default: 44100
glopts | pointer to twolame options pointer |
samplerate | the samplerate in Hz |
int twolame_get_out_samplerate | ( | twolame_options * | glopts | ) |
Get the samplerate of the MPEG audio output.
glopts | pointer to twolame options pointer |
int twolame_set_bitrate | ( | twolame_options * | glopts, |
int | bitrate | ||
) |
Set the bitrate of the MPEG audio output stream.
Default: 192
glopts | pointer to twolame options pointer |
bitrate | the bitrate in kbps |
int twolame_get_bitrate | ( | twolame_options * | glopts | ) |
Get the bitrate of the MPEG audio output.
glopts | pointer to twolame options pointer |
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()
int twolame_get_brate | ( | twolame_options * | glopts | ) |
Get the bitrate of the MPEG audio output stream (LAME style).
same as twolame_get_bitrate()
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
glopts | pointer to twolame options pointer |
padding | the padding type |
TWOLAME_Padding twolame_get_padding | ( | twolame_options * | glopts | ) |
Get the padding type of the MPEG audio output.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
energylevels | energy level extension state (TRUE/FALSE) |
int twolame_get_energy_levels | ( | twolame_options * | glopts | ) |
Get the Energy Level Extension state.
glopts | pointer to twolame options pointer |
int twolame_set_num_ancillary_bits | ( | twolame_options * | glopts, |
int | num | ||
) |
Set number of Ancillary Bits at end of frame.
Default: 0
glopts | pointer to twolame options pointer |
num | number of bits to reserve |
int twolame_get_num_ancillary_bits | ( | twolame_options * | glopts | ) |
Get the number of Ancillary Bits at end of frame.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
emphasis | the type of pre-emphasis |
TWOLAME_Emphasis twolame_get_emphasis | ( | twolame_options * | glopts | ) |
Get the type of pre-emphasis to be applied to the decoded audio.
glopts | pointer to twolame options pointer |
int twolame_set_error_protection | ( | twolame_options * | glopts, |
int | err_protection | ||
) |
Enable/Disable CRC Error Protection.
Default: FALSE
glopts | pointer to twolame options pointer |
err_protection | error protection state (TRUE/FALSE) |
int twolame_get_error_protection | ( | twolame_options * | glopts | ) |
Get the CRC Error Protection state.
glopts | pointer to twolame options pointer |
int twolame_set_copyright | ( | twolame_options * | glopts, |
int | copyright | ||
) |
Set the MPEG Audio Copyright flag.
Indicates that MPEG stream is copyrighted.
Default: FALSE
glopts | pointer to twolame options pointer |
copyright | copyright flag state (TRUE/FALSE) |
int twolame_get_copyright | ( | twolame_options * | glopts | ) |
Get the copright flag state
glopts | pointer to twolame options pointer |
int twolame_set_original | ( | twolame_options * | glopts, |
int | original | ||
) |
Set the MPEG Audio Original flag.
Default: FALSE
glopts | pointer to twolame options pointer |
original | original flag state (TRUE/FALSE) |
int twolame_get_original | ( | twolame_options * | glopts | ) |
Get the origianl flag state.
glopts | pointer to twolame options pointer |
int twolame_set_VBR | ( | twolame_options * | glopts, |
int | vbr | ||
) |
Enable/Disable VBR (Variable Bit Rate) mode.
Default: FALSE
glopts | pointer to twolame options pointer |
vbr | VBR state (TRUE/FALSE) |
int twolame_get_VBR | ( | twolame_options * | glopts | ) |
Get the VBR state.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
level | quality level (-10 to 10) |
float twolame_get_VBR_level | ( | twolame_options * | glopts | ) |
Get the level/quality of the VBR audio.
glopts | pointer to twolame options pointer |
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
glopts | pointer to twolame options pointer |
level | adjustment level in db |
float twolame_get_ATH_level | ( | twolame_options * | glopts | ) |
Get the adjustment (in dB) applied to the ATH for Psycho models 3 and 4.
glopts | pointer to twolame options pointer |
int twolame_set_VBR_max_bitrate_kbps | ( | twolame_options * | glopts, |
int | bitrate | ||
) |
Set the upper bitrate for VBR
Default: 0 (off)
glopts | pointer to twolame options pointer |
bitrate | upper bitrate for VBR |
int twolame_get_VBR_max_bitrate_kbps | ( | twolame_options * | glopts | ) |
Get the upper bitrate for VBR.
glopts | pointer to twolame options pointer |
int twolame_set_quick_mode | ( | twolame_options * | glopts, |
int | quickmode | ||
) |
Enable/Disable the quick mode for psycho model calculation.
Default: FALSE
glopts | pointer to twolame options pointer |
quickmode | the state of quick mode (TRUE/FALSE) |
int twolame_get_quick_mode | ( | twolame_options * | glopts | ) |
Get the state of quick mode.
glopts | pointer to twolame options pointer |
int twolame_set_quick_count | ( | twolame_options * | glopts, |
int | quickcount | ||
) |
Set how often the psy model is calculated.
Default: 10
glopts | pointer to twolame options pointer |
quickcount | number of frames between calculations |
int twolame_get_quick_count | ( | twolame_options * | glopts | ) |
Get the how often the psy model is calculated.
glopts | pointer to twolame options pointer |
int twolame_set_DAB | ( | twolame_options * | glopts, |
int | dab | ||
) |
Enable/Disable the Eureka 147 DAB extensions for MP2.
Default: FALSE
glopts | pointer to twolame options pointer |
dab | state of DAB extensions (TRUE/FALSE) |
int twolame_get_DAB | ( | twolame_options * | glopts | ) |
Get the state of the DAB extensions
glopts | pointer to twolame options pointer |
int twolame_set_DAB_xpad_length | ( | twolame_options * | glopts, |
int | length | ||
) |
Set the number of bytes to reserve for DAB XPAD data.
Default: 0
glopts | pointer to twolame options pointer |
length | number of bytes to reserve |
int twolame_get_DAB_xpad_length | ( | twolame_options * | glopts | ) |
Get the number of bytes reserved for DAB XPAD data.
glopts | pointer to twolame options pointer |
int twolame_set_DAB_crc_length | ( | twolame_options * | glopts, |
int | length | ||
) |
Set the CRC error protection length for DAB.
Default: 2
glopts | pointer to twolame options pointer |
length | length of DAB CRC |
int twolame_get_DAB_crc_length | ( | twolame_options * | glopts | ) |
Get the CRC error protection length for DAB.
glopts | pointer to twolame options pointer |