From ad257c9dac38fe3f7502b1058247b4458465c0a8 Mon Sep 17 00:00:00 2001 From: jstebbins Date: Wed, 1 Aug 2012 23:05:00 +0000 Subject: libhb: Allow control of audio mix normalization Since switching to libavresample for audio mixing, our output volume levels have been reduced because libavresample does mix level normalization by default. This change applies a patch to libav to allow us to disable this behavior and adds a new field to hb_audio_config_t to allow the hb frontends to control this feature. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4884 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/audio_resample.c | 21 +++++++++++++-------- libhb/audio_resample.h | 4 +++- libhb/common.c | 3 +++ libhb/common.h | 1 + libhb/decavcodec.c | 3 ++- libhb/declpcm.c | 3 ++- libhb/encavcodecaudio.c | 2 +- 7 files changed, 25 insertions(+), 12 deletions(-) (limited to 'libhb') diff --git a/libhb/audio_resample.c b/libhb/audio_resample.c index 3f67da87c..ea09b38a2 100644 --- a/libhb/audio_resample.c +++ b/libhb/audio_resample.c @@ -13,20 +13,23 @@ hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat output_sample_fmt, uint64_t output_channel_layout, - enum AVMatrixEncoding matrix_encoding) + enum AVMatrixEncoding matrix_encoding, + int normalize_mix_level) { hb_audio_resample_t *resample = malloc(sizeof(hb_audio_resample_t)); if (resample == NULL) return NULL; - resample->out.sample_fmt = output_sample_fmt; - resample->out.sample_size = av_get_bytes_per_sample(output_sample_fmt); - resample->out.channel_layout = output_channel_layout; - resample->out.channels = + resample->out.sample_fmt = output_sample_fmt; + resample->out.sample_size = + av_get_bytes_per_sample(output_sample_fmt); + resample->out.channel_layout = output_channel_layout; + resample->out.channels = av_get_channel_layout_nb_channels(output_channel_layout); - resample->out.matrix_encoding = matrix_encoding; - resample->resample_needed = 0; - resample->avresample = NULL; + resample->out.matrix_encoding = matrix_encoding; + resample->out.normalize_mix_level = normalize_mix_level; + resample->resample_needed = 0; + resample->avresample = NULL; return resample; } @@ -72,6 +75,8 @@ int hb_audio_resample_update(hb_audio_resample_t *resample, resample->out.channel_layout, 0); av_opt_set_int(resample->avresample, "matrix_encoding", resample->out.matrix_encoding, 0); + av_opt_set_int(resample->avresample, "normalize_mix_level", + resample->out.normalize_mix_level, 0); } else if (resample_changed) { diff --git a/libhb/audio_resample.h b/libhb/audio_resample.h index 5982905e6..4b1586e73 100644 --- a/libhb/audio_resample.h +++ b/libhb/audio_resample.h @@ -39,6 +39,7 @@ typedef struct int channels; int linesize; int sample_size; + int normalize_mix_level; uint64_t channel_layout; enum AVSampleFormat sample_fmt; enum AVMatrixEncoding matrix_encoding; @@ -52,7 +53,8 @@ typedef struct */ hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat output_sample_fmt, uint64_t output_channel_layout, - enum AVMatrixEncoding matrix_encoding); + enum AVMatrixEncoding matrix_encoding, + int normalize_mix_level); /* Update an hb_audio_resample_t, setting the input sample characteristics. * diff --git a/libhb/common.c b/libhb/common.c index 13a2e1d95..9ff9f44a3 100644 --- a/libhb/common.c +++ b/libhb/common.c @@ -1637,6 +1637,7 @@ void hb_audio_config_init(hb_audio_config_t * audiocfg) audiocfg->out.mixdown = HB_INVALID_AMIXDOWN; audiocfg->out.dynamic_range_compression = 0; audiocfg->out.gain = 0; + audiocfg->out.normalize_mix_level = 0; audiocfg->out.name = NULL; } @@ -1684,6 +1685,7 @@ int hb_audio_add(const hb_job_t * job, const hb_audio_config_t * audiocfg) audio->config.out.mixdown = HB_AMIXDOWN_NONE; audio->config.out.dynamic_range_compression = 0; audio->config.out.gain = 0; + audio->config.out.normalize_mix_level = 0; audio->config.out.compression_level = -1; audio->config.out.quality = HB_INVALID_AUDIO_QUALITY; } @@ -1698,6 +1700,7 @@ int hb_audio_add(const hb_job_t * job, const hb_audio_config_t * audiocfg) audio->config.out.dynamic_range_compression = audiocfg->out.dynamic_range_compression; audio->config.out.mixdown = audiocfg->out.mixdown; audio->config.out.gain = audiocfg->out.gain; + audio->config.out.normalize_mix_level = audiocfg->out.normalize_mix_level; } if (audiocfg->out.name && *audiocfg->out.name) { diff --git a/libhb/common.h b/libhb/common.h index 5b2fc08fa..1650f8002 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -452,6 +452,7 @@ struct hb_audio_config_s float compression_level; /* Output compression level (encoder-specific) */ double dynamic_range_compression; /* Amount of DRC applied to this track */ double gain; /* Gain (in dB), negative is quieter */ + int normalize_mix_level; /* mix level normalization (boolean) */ char * name; /* Output track name */ } out; diff --git a/libhb/decavcodec.c b/libhb/decavcodec.c index 17f814d61..934f7611e 100644 --- a/libhb/decavcodec.c +++ b/libhb/decavcodec.c @@ -192,7 +192,8 @@ static int decavcodecaInit( hb_work_object_t * w, hb_job_t * job ) int mode; uint64_t layout = hb_ff_mixdown_xlat(w->audio->config.out.mixdown, &mode); - pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode); + pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode, + w->audio->config.out.normalize_mix_level); if (pv->resample == NULL) { hb_error("decavcodecaInit: hb_audio_resample_init() failed"); diff --git a/libhb/declpcm.c b/libhb/declpcm.c index e48bf5db7..0d4e449d1 100644 --- a/libhb/declpcm.c +++ b/libhb/declpcm.c @@ -164,7 +164,8 @@ static int declpcmInit( hb_work_object_t * w, hb_job_t * job ) int mode; uint64_t layout = hb_ff_mixdown_xlat(w->audio->config.out.mixdown, &mode); - pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode); + pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode, + w->audio->config.out.normalize_mix_level); if (pv->resample == NULL) { hb_error("declpcmInit: hb_audio_resample_init() failed"); diff --git a/libhb/encavcodecaudio.c b/libhb/encavcodecaudio.c index 28eb0d9ae..ef5297cca 100644 --- a/libhb/encavcodecaudio.c +++ b/libhb/encavcodecaudio.c @@ -119,7 +119,7 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job_t *job) // sample_fmt conversion pv->resample = hb_audio_resample_init(context->sample_fmt, context->channel_layout, - AV_MATRIX_ENCODING_NONE); + AV_MATRIX_ENCODING_NONE, 0); if (hb_audio_resample_update(pv->resample, AV_SAMPLE_FMT_FLT, context->channel_layout, context->channels)) { -- cgit v1.2.3