]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/normvol.c
Qt is GPLv2+
[vlc] / modules / audio_filter / normvol.c
index 90a7603b7657189f8bc529f78e8178c490d8c07e..6bcacdb55b30f6850f96c81ffe043746b4b85d39 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * normvol.c: volume normalizer
  *****************************************************************************
- * Copyright (C) 2001, 2006 the VideoLAN team
+ * Copyright (C) 2001, 2006 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * 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
- * GNU General Public License for more details.
+ * 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 General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*
 # include "config.h"
 #endif
 
-#include <errno.h>                                                 /* ENOMEM */
-#include <ctype.h>
-#include <signal.h>
-
 #include <math.h>
 
-
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 
@@ -73,7 +68,7 @@ struct filter_sys_t
                 "increase the response time of the filter to a spike " \
                 "but will make it less sensitive to short variations." )
 
-#define LEVEL_TEXT N_("Max level" )
+#define LEVEL_TEXT N_("Maximal volume level" )
 #define LEVEL_LONGTEXT N_("If the average power over the last N buffers " \
                "is higher than this value, the volume will be normalized. " \
                "This value is a positive floating point number. A value " \
@@ -85,9 +80,9 @@ vlc_module_begin ()
     set_category( CAT_AUDIO )
     set_subcategory( SUBCAT_AUDIO_AFILTER )
     add_shortcut( "volnorm" )
-    add_integer( "norm-buff-size", 20 ,NULL ,BUFF_TEXT, BUFF_LONGTEXT,
+    add_integer( "norm-buff-size", 20  ,BUFF_TEXT, BUFF_LONGTEXT,
                  true )
-    add_float( "norm-max-level", 2.0, NULL, LEVEL_TEXT,
+    add_float( "norm-max-level", 2.0, LEVEL_TEXT,
                LEVEL_LONGTEXT, true )
     set_capability( "audio filter", 0 )
     set_callbacks( Open, Close )
@@ -102,25 +97,6 @@ static int Open( vlc_object_t *p_this )
     unsigned i_channels;
     filter_sys_t *p_sys;
 
-    if( p_filter->fmt_in.audio.i_format != VLC_CODEC_FL32 ||
-        p_filter->fmt_out.audio.i_format != VLC_CODEC_FL32 )
-    {
-        p_filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
-        p_filter->fmt_out.audio.i_format = VLC_CODEC_FL32;
-        msg_Warn( p_filter, "bad input or output format" );
-        return VLC_EGENERIC;
-    }
-
-    if ( !AOUT_FMTS_SIMILAR( &p_filter->fmt_in.audio, &p_filter->fmt_out.audio ) )
-    {
-        memcpy( &p_filter->fmt_out.audio, &p_filter->fmt_in.audio,
-                sizeof(audio_sample_format_t) );
-        msg_Warn( p_filter, "input and output formats are not similar" );
-        return VLC_EGENERIC;
-    }
-
-    p_filter->pf_audio_filter = DoWork;
-
     i_channels = aout_FormatNbChannels( &p_filter->fmt_in.audio );
 
     p_sys = p_filter->p_sys = malloc( sizeof( *p_sys ) );
@@ -139,6 +115,10 @@ static int Open( vlc_object_t *p_this )
         return VLC_ENOMEM;
     }
 
+    p_filter->fmt_in.audio.i_format = VLC_CODEC_FL32;
+    p_filter->fmt_out.audio = p_filter->fmt_in.audio;
+    p_filter->pf_audio_filter = DoWork;
+
     return VLC_SUCCESS;
 }
 
@@ -176,8 +156,7 @@ static block_t *DoWork( filter_t *p_filter, block_t *p_in_buf )
         for( i_chan = 0; i_chan < i_channels; i_chan++ )
         {
             float f_sample = p_in[i_chan];
-            float f_square = pow( f_sample, 2 );
-            pf_sum[i_chan] += f_square;
+            pf_sum[i_chan] += f_sample * f_sample;
         }
         p_in += i_channels;
     }