From 63ee07ac2348ba5e4e47834656e1941df96814e1 Mon Sep 17 00:00:00 2001 From: jbrjake Date: Sat, 8 Dec 2007 18:15:38 +0000 Subject: Adds extra, user-selectable dynamic range compression to the liba52 interface, making softer sounds louder. Based on code from liba52's A52Decoder, used in Perian's preferences pane. Set with a job->dynamic_range_compression float, with valid values being 1.0 - 4.0. Controlled from the CLI with --dynamic-range-compression or -D. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1108 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/common.h | 1 + libhb/deca52.c | 32 ++++++++++++++++++++++++++++++++ libhb/work.c | 3 +++ 3 files changed, 36 insertions(+) (limited to 'libhb') diff --git a/libhb/common.h b/libhb/common.h index 988ea3d55..be174d17e 100644 --- a/libhb/common.h +++ b/libhb/common.h @@ -236,6 +236,7 @@ struct hb_job_s int acodec; int abitrate; int arate; + float dynamic_range_compression; /* Subtitle settings: subtitle: index in hb_title_t's subtitles list, starting diff --git a/libhb/deca52.c b/libhb/deca52.c index 94bf8a540..90dd9e738 100644 --- a/libhb/deca52.c +++ b/libhb/deca52.c @@ -20,6 +20,7 @@ struct hb_work_private_s int rate; int bitrate; float level; + float dynamic_range_compression; int error; int sync; @@ -55,6 +56,30 @@ hb_work_object_t hb_deca52 = **********************************************************************/ static hb_buffer_t * Decode( hb_work_object_t * w ); +/*********************************************************************** + * dynrng_call + *********************************************************************** + * Boosts soft audio -- taken from gbooker's work in A52Decoder, comment and all.. + * Two cases + * 1) The user requested a compression of 1 or less, return the typical power rule + * 2) The user requested a compression of more than 1 (decompression): + * If the stream's requested compression is less than 1.0 (loud sound), return the normal compression + * If the stream's requested compression is more than 1.0 (soft sound), use power rule (which will make + * it louder in this case). + * + **********************************************************************/ +static sample_t dynrng_call (sample_t c, void *data) +{ + double *level = (double *)data; + float levelToUse = (float)*level; + if(c > 1.0 || levelToUse <= 1.0) + { + return powf(c, levelToUse); + } + else + return c; +} + /*********************************************************************** * hb_work_deca52_init *********************************************************************** @@ -80,6 +105,8 @@ int deca52Init( hb_work_object_t * w, hb_job_t * job ) pv->out_discrete_channels = HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT(w->amixdown); pv->level = 32768.0; + pv->dynamic_range_compression = job->dynamic_range_compression; + pv->next_expected_pts = 0; pv->sequence = 0; @@ -201,6 +228,11 @@ static hb_buffer_t * Decode( hb_work_object_t * w ) /* Feed liba52 */ a52_frame( pv->state, pv->frame, &pv->flags_out, &pv->level, 0 ); + if ( pv->dynamic_range_compression ) + { + a52_dynrng( pv->state, dynrng_call, &pv->dynamic_range_compression); + } + /* 6 blocks per frame, 256 samples per block, channelsused channels */ buf = hb_buffer_init( 6 * 256 * pv->out_discrete_channels * sizeof( float ) ); if (pts == -1) diff --git a/libhb/work.c b/libhb/work.c index 19c498f0f..daabf9962 100644 --- a/libhb/work.c +++ b/libhb/work.c @@ -324,6 +324,9 @@ static void do_job( hb_job_t * job, int cpu_count ) "faac" : ( ( job->acodec & HB_ACODEC_LAME ) ? "lame" : "vorbis" ) ); } + + if ( job->dynamic_range_compression ) + hb_log(" + dynamic range compression: %f", job->dynamic_range_compression); /* if we are doing AC3 passthru, then remove any non-AC3 audios from the job */ /* otherwise, Bad Things will happen */ -- cgit v1.2.3