]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/resampler/trivial.c
* another round of dutch translations. only stupid wizard is left.
[vlc] / modules / audio_filter / resampler / trivial.c
index d3264c1d3c8db5ce7272b9dc9b0ead71650d2eea..1d97f659f6f35dafd3e210bb804559aa41917a93 100644 (file)
@@ -2,7 +2,7 @@
  * trivial.c : trivial resampler (skips samples or pads with zeroes)
  *****************************************************************************
  * Copyright (C) 2002 VideoLAN
- * $Id: trivial.c,v 1.3 2002/08/12 22:12:50 massiot Exp $
+ * $Id: trivial.c,v 1.11 2003/03/04 03:27:40 gbazin Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -24,7 +24,6 @@
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <errno.h>
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>
 
@@ -44,28 +43,32 @@ static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("aout filter for trivial resampling") );
+    set_description( _("audio filter for trivial resampling") );
     set_capability( "audio filter", 1 );
     set_callbacks( Create, NULL );
 vlc_module_end();
 
 /*****************************************************************************
  * Create: allocate trivial resampler
- *****************************************************************************
- * This function allocates and initializes a Crop vout method.
  *****************************************************************************/
 static int Create( vlc_object_t *p_this )
 {
     aout_filter_t * p_filter = (aout_filter_t *)p_this;
 
     if ( p_filter->input.i_rate == p_filter->output.i_rate
-          || p_filter->input.i_format != p_filter->output.i_format )
+          || p_filter->input.i_format != p_filter->output.i_format
+          || p_filter->input.i_physical_channels
+              != p_filter->output.i_physical_channels
+          || p_filter->input.i_original_channels
+              != p_filter->output.i_original_channels
+          || (p_filter->input.i_format != VLC_FOURCC('f','l','3','2')
+               && p_filter->input.i_format != VLC_FOURCC('f','i','3','2')) )
     {
         return -1;
     }
 
     p_filter->pf_do_work = DoWork;
-    p_filter->b_in_place = 1;
+    p_filter->b_in_place = VLC_TRUE;
 
     return 0;
 }
@@ -79,21 +82,33 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     int i_in_nb = p_in_buf->i_nb_samples;
     int i_out_nb = i_in_nb * p_filter->output.i_rate
                     / p_filter->input.i_rate;
+    int i_sample_bytes = aout_FormatNbChannels( &p_filter->input )
+                          * sizeof(int32_t);
+
+    /* Check if we really need to run the resampler */
+    if( p_aout->mixer.mixer.i_rate == p_filter->input.i_rate )
+    {
+        return;
+    }
 
     if ( p_out_buf != p_in_buf )
     {
         /* For whatever reason the buffer allocator decided to allocate
-         * a new buffer. */
+         * a new buffer. Currently, this never happens. */
         p_aout->p_vlc->pf_memcpy( p_out_buf->p_buffer, p_in_buf->p_buffer,
-                                  __MIN(i_out_nb, i_in_nb) );
+                                  __MIN(i_out_nb, i_in_nb) * i_sample_bytes );
     }
 
     if ( i_out_nb > i_in_nb )
     {
         /* Pad with zeroes. */
-        memset( p_out_buf->p_buffer + i_in_nb, 0, i_out_nb - i_in_nb );
+        memset( p_out_buf->p_buffer + i_in_nb * i_sample_bytes,
+                0, (i_out_nb - i_in_nb) * i_sample_bytes );
     }
 
     p_out_buf->i_nb_samples = i_out_nb;
+    p_out_buf->i_nb_bytes = i_out_nb * i_sample_bytes;
+    p_out_buf->start_date = p_in_buf->start_date;
+    p_out_buf->end_date = p_out_buf->start_date + p_out_buf->i_nb_samples *
+        1000000 / p_filter->output.i_rate;
 }
-