Example #1
0
int enclameInit( hb_work_object_t * w, hb_job_t * job )
{
    hb_work_private_t * pv = calloc( 1, sizeof( hb_work_private_t ) );
    hb_audio_t * audio = w->audio;

    w->private_data = pv;

    pv->job   = job;

    hb_log( "enclame: opening libmp3lame" );

    pv->lame = lame_init();
    // use ABR
    lame_set_scale( pv->lame, 32768.0 );
    if( audio->config.out.compression_level >= 0 )
    {
        lame_set_quality( pv->lame, audio->config.out.compression_level );
    }
    if( audio->config.out.bitrate > 0 )
    {
        lame_set_VBR( pv->lame, vbr_abr );
        lame_set_VBR_mean_bitrate_kbps( pv->lame, audio->config.out.bitrate );
    }
    else if( audio->config.out.quality >= 0 )
    {
        lame_set_brate( pv->lame, 0 );
        lame_set_VBR( pv->lame, vbr_default );
        lame_set_VBR_quality( pv->lame, audio->config.out.quality );
    }
    lame_set_in_samplerate( pv->lame, audio->config.out.samplerate );
    lame_set_out_samplerate( pv->lame, audio->config.out.samplerate );

    pv->out_discrete_channels = hb_mixdown_get_discrete_channel_count( audio->config.out.mixdown );
    // Lame's default encoding mode is JOINT_STEREO.  This subtracts signal
    // that is "common" to left and right (within some threshold) and encodes
    // it separately.  This improves quality at low bitrates, but hurts 
    // imaging (channel separation) at higher bitrates.  So if the bitrate
    // is suffeciently high, use regular STEREO mode.
    if ( pv->out_discrete_channels == 1 )
    {
        lame_set_mode( pv->lame, MONO );
        lame_set_num_channels( pv->lame, 1 );
    }
    else if ( audio->config.out.bitrate >= 128 )
    {
        lame_set_mode( pv->lame, STEREO );
    }
    lame_init_params( pv->lame );

    pv->input_samples = 1152 * pv->out_discrete_channels;
    pv->output_bytes = LAME_MAXMP3BUFFER;
    pv->buf  = malloc( pv->input_samples * sizeof( float ) );
    audio->config.out.samples_per_frame = 1152;

    pv->list = hb_list_init();
    pv->pts  = -1;

    return 0;
}
void lame_encoder_impl_internal::set_scale(float _Scale)
{
    int lameRet = lame_set_scale(m_Lame.get(), _Scale);
    DT_LAME_CHECK_ERR(lameRet);
}