diff options
author | jstebbins <[email protected]> | 2010-05-13 14:48:18 +0000 |
---|---|---|
committer | jstebbins <[email protected]> | 2010-05-13 14:48:18 +0000 |
commit | 8ed88a9c59f4bd74804290dcc87e7483ce06f896 (patch) | |
tree | 6bc22c0294d03b445427096ac7c08ab50697080c /libhb/enclame.c | |
parent | 675c7146fe298cd566fa8e446c762a3ded12e0d7 (diff) |
allow mono mixdown with lame encoder
enable mono mode in lame encoder when mixdown is mono.
use lame_encode_buffer_float instead of lame_encode_buffer_interleave. this
eliminates the clipping issue in lame without reducing the level of the input.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3294 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/enclame.c')
-rw-r--r-- | libhb/enclame.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/libhb/enclame.c b/libhb/enclame.c index a3f4a3882..9692eef29 100644 --- a/libhb/enclame.c +++ b/libhb/enclame.c @@ -29,6 +29,7 @@ struct hb_work_private_s lame_global_flags * lame; int done; + int out_discrete_channels; unsigned long input_samples; unsigned long output_bytes; uint8_t * buf; @@ -41,6 +42,7 @@ 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; @@ -53,16 +55,25 @@ int enclameInit( hb_work_object_t * w, hb_job_t * job ) lame_set_VBR_mean_bitrate_kbps( pv->lame, audio->config.out.bitrate ); lame_set_in_samplerate( pv->lame, audio->config.out.samplerate ); lame_set_out_samplerate( pv->lame, audio->config.out.samplerate ); - lame_init_params( pv->lame ); + + pv->out_discrete_channels = HB_AMIXDOWN_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 ( audio->config.out.bitrate >= 128 ) + 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 * 2; + pv->input_samples = 1152 * pv->out_discrete_channels; pv->output_bytes = LAME_MAXMP3BUFFER; pv->buf = malloc( pv->input_samples * sizeof( float ) ); @@ -98,9 +109,9 @@ static hb_buffer_t * Encode( hb_work_object_t * w ) hb_work_private_t * pv = w->private_data; hb_audio_t * audio = w->audio; hb_buffer_t * buf; - int16_t samples_s16[1152 * 2]; + float samples[2][1152]; uint64_t pts, pos; - int i; + int i, j; if( hb_list_bytes( pv->list ) < pv->input_samples * sizeof( float ) ) { @@ -110,16 +121,22 @@ static hb_buffer_t * Encode( hb_work_object_t * w ) hb_list_getbytes( pv->list, pv->buf, pv->input_samples * sizeof( float ), &pts, &pos); - for( i = 0; i < 1152 * 2; i++ ) + memset(samples, 0, 2*1152*sizeof(float)); + for( i = 0; i < 1152; i++ ) { - samples_s16[i] = ((float*) pv->buf)[i]; + for( j = 0; j < pv->out_discrete_channels; j++ ) + { + samples[j][i] = ((float *) pv->buf)[(pv->out_discrete_channels * i + j)]; + } } buf = hb_buffer_init( pv->output_bytes ); - buf->start = pts + 90000 * pos / 2 / sizeof( float ) / audio->config.out.samplerate; + buf->start = pts + 90000 * pos / pv->out_discrete_channels / sizeof( float ) / audio->config.out.samplerate; buf->stop = buf->start + 90000 * 1152 / audio->config.out.samplerate; - buf->size = lame_encode_buffer_interleaved( pv->lame, samples_s16, + buf->size = lame_encode_buffer_float( + pv->lame, samples[0], samples[1], 1152, buf->data, LAME_MAXMP3BUFFER ); + buf->frametype = HB_FRAME_AUDIO; if( !buf->size ) |