]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/gain.c
equalizer: fix crash and allow custom eq-band values without known preset
[vlc] / modules / audio_filter / gain.c
index b137823a63e149865947abe06a982e82bc792fba..c6c9339c4046b243d6b56113d4fb9e832e6eaa37 100644 (file)
@@ -12,7 +12,7 @@
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
@@ -30,8 +30,9 @@
 
 #include <vlc_common.h>
 #include <vlc_aout.h>
-#include <vlc_aout_mixer.h>
+#include <vlc_aout_volume.h>
 #include <vlc_filter.h>
+#include <vlc_modules.h>
 #include <vlc_plugin.h>
 
 
@@ -45,11 +46,11 @@ static block_t  *Process    ( filter_t *, block_t * );
 
 struct filter_sys_t
 {
+    audio_volume_t volume;
     float f_gain;
-    audio_mixer_t* p_mixer;
+    module_t *module;
 };
 
-
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -78,29 +79,24 @@ vlc_module_end()
 static int Open( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
-    filter_sys_t *p_sys;
-
-    if ( !AOUT_FMTS_IDENTICAL( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) )
-    {
-        msg_Warn( p_filter, "bad input or output format" );
-        return VLC_EGENERIC;
-    }
-
-    p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
-    if( !p_sys )
+    filter_sys_t *p_sys = vlc_object_create( p_this, sizeof( *p_sys ) );
+    if( unlikely( p_sys == NULL ) )
         return VLC_ENOMEM;
 
-    p_sys->p_mixer = aout_MixerNew( p_this, p_filter->fmt_in.audio.i_format );
-    if( !p_sys->p_mixer )
+    p_filter->p_sys = p_sys;
+    p_sys->volume.format = p_filter->fmt_in.audio.i_format;
+    p_sys->module = module_need( &p_sys->volume, "audio volume", NULL, false );
+    if( p_sys->module == NULL )
     {
         msg_Warn( p_filter, "unsupported format" );
-        free( p_sys );
+        vlc_object_release( &p_sys->volume );
         return VLC_EGENERIC;
     }
 
     p_sys->f_gain = var_InheritFloat( p_filter->p_parent, "gain-value" );
     msg_Dbg( p_filter, "gain multiplier sets to %.2fx", p_sys->f_gain );
 
+    p_filter->fmt_out.audio = p_filter->fmt_in.audio;
     p_filter->pf_audio_filter = Process;
     return VLC_SUCCESS;
 }
@@ -114,8 +110,7 @@ static block_t *Process( filter_t *p_filter, block_t *p_block )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    aout_MixerRun( p_sys->p_mixer, p_block, p_sys->f_gain );
-
+    p_sys->volume.amplify( &p_sys->volume, p_block, p_sys->f_gain );
     return p_block;
 }
 
@@ -129,6 +124,6 @@ static void Close( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t*)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    aout_MixerDelete( p_sys->p_mixer );
-    free( p_sys );
+    module_unneed( &p_sys->volume, p_sys->module );
+    vlc_object_release( &p_sys->volume );
 }