Commit d1136fc4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

aout: premultiply gain before mixing

parent ce42f29a
...@@ -41,11 +41,7 @@ typedef struct aout_mixer_sys_t aout_mixer_sys_t; ...@@ -41,11 +41,7 @@ typedef struct aout_mixer_sys_t aout_mixer_sys_t;
typedef struct aout_mixer_t aout_mixer_t; typedef struct aout_mixer_t aout_mixer_t;
typedef struct { typedef struct {
/* */
aout_fifo_t fifo; aout_fifo_t fifo;
/* Software multiplier */
float multiplier;
} aout_mixer_input_t; } aout_mixer_input_t;
/** /**
......
...@@ -60,7 +60,7 @@ static int Activate (vlc_object_t *obj) ...@@ -60,7 +60,7 @@ static int Activate (vlc_object_t *obj)
static void FilterFI32 (aout_mixer_t *mixer, block_t *block, float volume) static void FilterFI32 (aout_mixer_t *mixer, block_t *block, float volume)
{ {
const int64_t mult = volume * mixer->input->multiplier * FIXED32_ONE; const int64_t mult = volume * FIXED32_ONE;
if (mult == FIXED32_ONE) if (mult == FIXED32_ONE)
return; return;
...@@ -72,11 +72,13 @@ static void FilterFI32 (aout_mixer_t *mixer, block_t *block, float volume) ...@@ -72,11 +72,13 @@ static void FilterFI32 (aout_mixer_t *mixer, block_t *block, float volume)
*p = (*p * mult) >> FIXED32_FRACBITS; *p = (*p * mult) >> FIXED32_FRACBITS;
p++; p++;
} }
(void) mixer;
} }
static void FilterS16N (aout_mixer_t *mixer, block_t *block, float volume) static void FilterS16N (aout_mixer_t *mixer, block_t *block, float volume)
{ {
const int32_t mult = volume * mixer->input->multiplier * 0x10000; const int32_t mult = volume * 0x10000;
if (mult == 0x10000) if (mult == 0x10000)
return; return;
...@@ -88,4 +90,6 @@ static void FilterS16N (aout_mixer_t *mixer, block_t *block, float volume) ...@@ -88,4 +90,6 @@ static void FilterS16N (aout_mixer_t *mixer, block_t *block, float volume)
*p = (*p * mult) >> 16; *p = (*p * mult) >> 16;
p++; p++;
} }
(void) mixer;
} }
...@@ -72,12 +72,12 @@ static int Create( vlc_object_t *p_this ) ...@@ -72,12 +72,12 @@ static int Create( vlc_object_t *p_this )
static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t *p_buffer, static void DoWork( aout_mixer_t * p_mixer, aout_buffer_t *p_buffer,
float f_multiplier ) float f_multiplier )
{ {
f_multiplier *= p_mixer->input->multiplier;
if( f_multiplier == 1.0 ) if( f_multiplier == 1.0 )
return; /* nothing to do */ return; /* nothing to do */
float *p = (float *)p_buffer->p_buffer; float *p = (float *)p_buffer->p_buffer;
for( size_t i = p_buffer->i_buffer / sizeof(float); i > 0; i-- ) for( size_t i = p_buffer->i_buffer / sizeof(float); i > 0; i-- )
*(p++) *= f_multiplier; *(p++) *= f_multiplier;
(void) p_mixer;
} }
...@@ -54,6 +54,7 @@ block_t *aout_FilterBufferNew( filter_t *, int ); ...@@ -54,6 +54,7 @@ block_t *aout_FilterBufferNew( filter_t *, int );
struct aout_input_t struct aout_input_t
{ {
audio_sample_format_t input; audio_sample_format_t input;
float multiplier; /**< Replay gain multiplier */
/* pre-filters */ /* pre-filters */
filter_t * pp_filters[AOUT_MAX_FILTERS]; filter_t * pp_filters[AOUT_MAX_FILTERS];
......
...@@ -198,7 +198,7 @@ int aout_DecPlay( audio_output_t * p_aout, aout_input_t * p_input, ...@@ -198,7 +198,7 @@ int aout_DecPlay( audio_output_t * p_aout, aout_input_t * p_input,
aout_InputCheckAndRestart( p_aout, p_input ); aout_InputCheckAndRestart( p_aout, p_input );
aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate ); aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate );
/* Run the mixer if it is able to run. */ /* Run the mixer if it is able to run. */
aout_MixerRun( p_aout, p_aout->mixer_multiplier ); aout_MixerRun( p_aout, p_aout->mixer_multiplier * p_input->multiplier );
aout_unlock( p_aout ); aout_unlock( p_aout );
return 0; return 0;
} }
......
...@@ -874,7 +874,7 @@ static void ReplayGainSelect( audio_output_t *p_aout, aout_input_t *p_input ) ...@@ -874,7 +874,7 @@ static void ReplayGainSelect( audio_output_t *p_aout, aout_input_t *p_input )
int i_use; int i_use;
float f_gain; float f_gain;
p_input->mixer.multiplier = 1.0; p_input->multiplier = 1.0;
if( !psz_replay_gain ) if( !psz_replay_gain )
return; return;
...@@ -905,14 +905,14 @@ static void ReplayGainSelect( audio_output_t *p_aout, aout_input_t *p_input ) ...@@ -905,14 +905,14 @@ static void ReplayGainSelect( audio_output_t *p_aout, aout_input_t *p_input )
f_gain = var_GetFloat( p_aout, "audio-replay-gain-default" ); f_gain = var_GetFloat( p_aout, "audio-replay-gain-default" );
else else
f_gain = 0.0; f_gain = 0.0;
p_input->mixer.multiplier = pow( 10.0, f_gain / 20.0 ); p_input->multiplier = pow( 10.0, f_gain / 20.0 );
/* */ /* */
if( p_input->replay_gain.pb_peak[i_use] && if( p_input->replay_gain.pb_peak[i_use] &&
var_GetBool( p_aout, "audio-replay-gain-peak-protection" ) && var_GetBool( p_aout, "audio-replay-gain-peak-protection" ) &&
p_input->replay_gain.pf_peak[i_use] * p_input->mixer.multiplier > 1.0 ) p_input->replay_gain.pf_peak[i_use] * p_input->multiplier > 1.0 )
{ {
p_input->mixer.multiplier = 1.0f / p_input->replay_gain.pf_peak[i_use]; p_input->multiplier = 1.0f / p_input->replay_gain.pf_peak[i_use];
} }
free( psz_replay_gain ); free( psz_replay_gain );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment