]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/resampler/bandlimited.c
Declared many static variables const
[vlc] / modules / audio_filter / resampler / bandlimited.c
index 4b67db46ee03a1a88ea0be393aa747833bfd5a29..b7587393605b0ca9971b5fd2106079038150824d 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * bandlimited.c : bandlimited interpolation resampler
+ * bandlimited.c : band-limited interpolation resampler
  *****************************************************************************
- * Copyright (C) 2002 VideoLAN
- * $Id: bandlimited.c,v 1.5 2003/03/05 22:37:05 gbazin Exp $
+ * Copyright (C) 2002, 2006 the VideoLAN team
+ * $Id$
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *
@@ -10,7 +10,7 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 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
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble:
  *
- * This implementation of the bandlimited interpolationis based on the
+ * This implementation of the band-limited interpolationis based on the
  * following paper:
  * http://ccrma-www.stanford.edu/~jos/resample/resample.html
  *
  * filter is 13 samples.
  *
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
 
-#include <vlc/vlc.h>
-#include "audio_output.h"
-#include "aout_internal.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_aout.h>
+
 #include "bandlimited.h"
 
 /*****************************************************************************
@@ -48,12 +51,12 @@ static void Close     ( vlc_object_t * );
 static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
                         aout_buffer_t * );
 
-static void FilterFloatUP( float Imp[], float ImpD[], uint16_t Nwing,
+static void FilterFloatUP( const float Imp[], const float ImpD[], uint16_t Nwing,
                            float *f_in, float *f_out, uint32_t ui_remainder,
                            uint32_t ui_output_rate, int16_t Inc,
                            int i_nb_channels );
 
-static void FilterFloatUD( float Imp[], float ImpD[], uint16_t Nwing,
+static void FilterFloatUD( const float Imp[], const float ImpD[], uint16_t Nwing,
                            float *f_in, float *f_out, uint32_t ui_remainder,
                            uint32_t ui_output_rate, uint32_t ui_input_rate,
                            int16_t Inc, int i_nb_channels );
@@ -79,7 +82,9 @@ struct aout_filter_sys_t
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("audio filter for bandlimited interpolation resampling") );
+    set_category( CAT_AUDIO );
+    set_subcategory( SUBCAT_AUDIO_MISC );
+    set_description( N_("Audio filter for band-limited interpolation resampling") );
     set_capability( "audio filter", 20 );
     set_callbacks( Create, Close );
 vlc_module_end();
@@ -104,17 +109,21 @@ static int Create( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
+#if !defined( __APPLE__ )
+    if( !config_GetInt( p_this, "hq-resampling" ) )
+    {
+        return VLC_EGENERIC;
+    }
+#endif
+
     /* Allocate the memory needed to store the module's structure */
     p_filter->p_sys = malloc( sizeof(struct aout_filter_sys_t) );
     if( p_filter->p_sys == NULL )
-    {
-        msg_Err( p_filter, "out of memory" );
         return VLC_ENOMEM;
-    }
 
     /* Calculate worst case for the length of the filter wing */
     d_factor = (double)p_filter->output.i_rate
-                        / p_filter->input.i_rate;
+                        / p_filter->input.i_rate / AOUT_MAX_INPUT_RATE;
     i_filter_wing = ((SMALL_FILTER_NMULT + 1)/2.0)
                       * __MAX(1.0, 1.0/d_factor) + 10;
     p_filter->p_sys->i_buf_size = aout_FormatNbChannels( &p_filter->input ) *
@@ -123,17 +132,14 @@ static int Create( vlc_object_t *p_this )
     /* Allocate enough memory to buffer previous samples */
     p_filter->p_sys->p_buf = malloc( p_filter->p_sys->i_buf_size );
     if( p_filter->p_sys->p_buf == NULL )
-    {
-        msg_Err( p_filter, "out of memory" );
         return VLC_ENOMEM;
-    }
 
     p_filter->p_sys->i_old_wing = 0;
     p_filter->pf_do_work = DoWork;
 
     /* We don't want a new buffer to be created because we're not sure we'll
      * actually need to resample anything. */
-    p_filter->b_in_place = VLC_TRUE;
+    p_filter->b_in_place = true;
 
     return VLC_SUCCESS;
 }
@@ -168,7 +174,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     /* Check if we really need to run the resampler */
     if( p_aout->mixer.mixer.i_rate == p_filter->input.i_rate )
     {
-        if( //p_filter->b_continuity && /* What difference does it make ? :) */
+        if( /*p_filter->b_continuity && /--* What difference does it make ? :) */
             p_filter->p_sys->i_old_wing &&
             p_in_buf->i_size >=
               p_in_buf->i_nb_bytes + p_filter->p_sys->i_old_wing *
@@ -194,7 +200,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
             p_out_buf->i_nb_bytes = p_out_buf->i_nb_samples *
                 p_filter->input.i_bytes_per_frame;
         }
-        p_filter->b_continuity = VLC_FALSE;
+        p_filter->b_continuity = false;
         p_filter->p_sys->i_old_wing = 0;
         return;
     }
@@ -203,7 +209,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     {
         /* Continuity in sound samples has been broken, we'd better reset
          * everything. */
-        p_filter->b_continuity = VLC_TRUE;
+        p_filter->b_continuity = true;
         p_filter->p_sys->i_remainder = 0;
         aout_DateInit( &p_filter->p_sys->end_date, p_filter->output.i_rate );
         aout_DateSet( &p_filter->p_sys->end_date, p_in_buf->start_date );
@@ -235,14 +241,13 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     /* Copy all our samples in p_in */
     if( p_filter->p_sys->i_old_wing )
     {
-        p_aout->p_vlc->pf_memcpy( p_in, p_filter->p_sys->p_buf,
-                                  p_filter->p_sys->i_old_wing * 2 *
-                                  p_filter->input.i_bytes_per_frame );
+        vlc_memcpy( p_in, p_filter->p_sys->p_buf,
+                    p_filter->p_sys->i_old_wing * 2 *
+                      p_filter->input.i_bytes_per_frame );
     }
-    p_aout->p_vlc->pf_memcpy( p_in + p_filter->p_sys->i_old_wing * 2 *
-                              i_nb_channels, p_in_buf->p_buffer,
-                              p_in_buf->i_nb_samples *
-                              p_filter->input.i_bytes_per_frame );
+    vlc_memcpy( p_in + p_filter->p_sys->i_old_wing * 2 * i_nb_channels,
+                p_in_buf->p_buffer,
+                p_in_buf->i_nb_samples * p_filter->input.i_bytes_per_frame );
 
     /* Make sure the output buffer is reset */
     memset( p_out, 0, p_out_buf->i_size );
@@ -265,8 +270,8 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
         if( p_filter->p_sys->d_old_factor == 1 )
         {
             /* Just copy the samples */
-            memcpy( p_out, p_in, 
-                    p_filter->input.i_bytes_per_frame );          
+            memcpy( p_out, p_in,
+                    p_filter->input.i_bytes_per_frame );
             p_in += i_nb_channels;
             p_out += i_nb_channels;
             i_out++;
@@ -444,11 +449,11 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
 
 }
 
-void FilterFloatUP( float Imp[], float ImpD[], uint16_t Nwing, float *p_in,
+void FilterFloatUP( const float Imp[], const float ImpD[], uint16_t Nwing, float *p_in,
                     float *p_out, uint32_t ui_remainder,
                     uint32_t ui_output_rate, int16_t Inc, int i_nb_channels )
 {
-    float *Hp, *Hdp, *End;
+    const float *Hp, *Hdp, *End;
     float t, temp;
     uint32_t ui_linear_remainder;
     int i;
@@ -487,12 +492,12 @@ void FilterFloatUP( float Imp[], float ImpD[], uint16_t Nwing, float *p_in,
     }
 }
 
-void FilterFloatUD( float Imp[], float ImpD[], uint16_t Nwing, float *p_in,
+void FilterFloatUD( const float Imp[], const float ImpD[], uint16_t Nwing, float *p_in,
                     float *p_out, uint32_t ui_remainder,
                     uint32_t ui_output_rate, uint32_t ui_input_rate,
                     int16_t Inc, int i_nb_channels )
 {
-    float *Hp, *Hdp, *End;
+    const float *Hp, *Hdp, *End;
     float t, temp;
     uint32_t ui_linear_remainder;
     int i, ui_counter = 0;