[vlc-commits] aout: premultiply gain before mixing

Rémi Denis-Courmont git at videolan.org
Tue Jul 26 21:19:59 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Jul 26 22:15:43 2011 +0300| [d1136fc4fedb9bdb9b39e7050a35e95f563297a6] | committer: Rémi Denis-Courmont

aout: premultiply gain before mixing

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d1136fc4fedb9bdb9b39e7050a35e95f563297a6
---

 include/vlc_aout_mixer.h         |    4 ----
 modules/audio_mixer/fixed32.c    |    8 ++++++--
 modules/audio_mixer/float32.c    |    4 ++--
 src/audio_output/aout_internal.h |    1 +
 src/audio_output/dec.c           |    2 +-
 src/audio_output/input.c         |    8 ++++----
 6 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/include/vlc_aout_mixer.h b/include/vlc_aout_mixer.h
index a38de40..7b3e022 100644
--- a/include/vlc_aout_mixer.h
+++ b/include/vlc_aout_mixer.h
@@ -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_fifo_t fifo;
-
-    /* Software multiplier */
-    float       multiplier;
 } aout_mixer_input_t;
 
 /** 
diff --git a/modules/audio_mixer/fixed32.c b/modules/audio_mixer/fixed32.c
index 65fd6ed..7f3c96b 100644
--- a/modules/audio_mixer/fixed32.c
+++ b/modules/audio_mixer/fixed32.c
@@ -60,7 +60,7 @@ static int Activate (vlc_object_t *obj)
 
 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)
         return;
@@ -72,11 +72,13 @@ static void FilterFI32 (aout_mixer_t *mixer, block_t *block, float volume)
         *p = (*p * mult) >> FIXED32_FRACBITS;
         p++;
     }
+
+    (void) mixer;
 }
 
 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)
         return;
@@ -88,4 +90,6 @@ static void FilterS16N (aout_mixer_t *mixer, block_t *block, float volume)
         *p = (*p * mult) >> 16;
         p++;
     }
+
+    (void) mixer;
 }
diff --git a/modules/audio_mixer/float32.c b/modules/audio_mixer/float32.c
index 27cc1de..aa23ee8 100644
--- a/modules/audio_mixer/float32.c
+++ b/modules/audio_mixer/float32.c
@@ -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,
                     float f_multiplier )
 {
-    f_multiplier *= p_mixer->input->multiplier;
-
     if( f_multiplier == 1.0 )
         return; /* nothing to do */
 
     float *p = (float *)p_buffer->p_buffer;
     for( size_t i = p_buffer->i_buffer / sizeof(float); i > 0; i-- )
         *(p++) *= f_multiplier;
+
+    (void) p_mixer;
 }
diff --git a/src/audio_output/aout_internal.h b/src/audio_output/aout_internal.h
index 2324fc5..54a470a 100644
--- a/src/audio_output/aout_internal.h
+++ b/src/audio_output/aout_internal.h
@@ -54,6 +54,7 @@ block_t *aout_FilterBufferNew( filter_t *, int );
 struct aout_input_t
 {
     audio_sample_format_t   input;
+    float                   multiplier; /**< Replay gain multiplier */
 
     /* pre-filters */
     filter_t *              pp_filters[AOUT_MAX_FILTERS];
diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c
index f86f76d..1509a5a 100644
--- a/src/audio_output/dec.c
+++ b/src/audio_output/dec.c
@@ -198,7 +198,7 @@ int aout_DecPlay( audio_output_t * p_aout, aout_input_t * p_input,
     aout_InputCheckAndRestart( p_aout, p_input );
     aout_InputPlay( p_aout, p_input, p_buffer, i_input_rate );
     /* 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 );
     return 0;
 }
diff --git a/src/audio_output/input.c b/src/audio_output/input.c
index b510064..5e9f772 100644
--- a/src/audio_output/input.c
+++ b/src/audio_output/input.c
@@ -874,7 +874,7 @@ static void ReplayGainSelect( audio_output_t *p_aout, aout_input_t *p_input )
     int i_use;
     float f_gain;
 
-    p_input->mixer.multiplier = 1.0;
+    p_input->multiplier = 1.0;
 
     if( !psz_replay_gain )
         return;
@@ -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" );
     else
         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] &&
         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 );



More information about the vlc-commits mailing list