]> git.sesse.net Git - vlc/blobdiff - modules/audio_filter/converter/mpgatofixed32.c
Removes trailing spaces. Removes tabs.
[vlc] / modules / audio_filter / converter / mpgatofixed32.c
index de5fd41aefc4043cc9d918ce93bd6008fa2d0ca0..387e11ea3c55d0a71187de98f31b3d808f3e066a 100644 (file)
@@ -2,17 +2,17 @@
  * mpgatofixed32.c: MPEG-1 & 2 audio layer I, II, III + MPEG 2.5 decoder,
  * using MAD (MPEG Audio Decoder)
  *****************************************************************************
- * Copyright (C) 2001 by Jean-Paul Saman
+ * Copyright (C) 2001-2005 the VideoLAN team
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
- *          Jean-Paul Saman <jpsaman@wxs.nl>
- *      
+ *          Jean-Paul Saman <jpsaman _at_ videolan _dot_ 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
  * (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
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>                                              /* strdup() */
 
 #include <mad.h>
 
 #include <vlc/vlc.h>
-#include <vlc/decoder.h>
-#include "aout_internal.h"
+#include <vlc_aout.h>
+#include <vlc_block.h>
 #include "vlc_filter.h"
 
 /*****************************************************************************
@@ -41,7 +39,7 @@
  *****************************************************************************/
 static int  Create    ( vlc_object_t * );
 static void Destroy   ( vlc_object_t * );
-static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,  
+static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
                         aout_buffer_t * );
 
 static int  OpenFilter ( vlc_object_t * );
@@ -54,16 +52,18 @@ static block_t *Convert( filter_t *, block_t * );
 struct filter_sys_t
 {
     struct mad_stream mad_stream;
-    struct mad_frame mad_frame;
-    struct mad_synth mad_synth;
+    struct mad_frame  mad_frame;
+    struct mad_synth  mad_synth;
+
+    int               i_reject_count;
 };
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_category( CAT_AUDIO );
-    set_subcategory( SUBCAT_AUDIO_MISC );
+    set_category( CAT_INPUT );
+    set_subcategory( SUBCAT_INPUT_ACODEC );
     set_description( _("MPEG audio decoder") );
     set_capability( "audio filter", 100 );
     set_callbacks( Create, Destroy );
@@ -75,7 +75,7 @@ vlc_module_begin();
 vlc_module_end();
 
 /*****************************************************************************
- * Create: 
+ * Create:
  *****************************************************************************/
 static int Create( vlc_object_t *p_this )
 {
@@ -109,6 +109,7 @@ static int Create( vlc_object_t *p_this )
     mad_frame_init( &p_sys->mad_frame );
     mad_synth_init( &p_sys->mad_synth );
     mad_stream_options( &p_sys->mad_stream, MAD_OPTION_IGNORECRC );
+    p_sys->i_reject_count = 0;
 
     p_filter->pf_do_work = DoWork;
     p_filter->b_in_place = 0;
@@ -125,8 +126,8 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
 
     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
-    p_out_buf->i_nb_bytes = p_in_buf->i_nb_samples * sizeof(vlc_fixed_t) * 
-                               aout_FormatNbChannels( &p_filter->input );
+    p_out_buf->i_nb_bytes = p_in_buf->i_nb_samples * sizeof(vlc_fixed_t) *
+                               aout_FormatNbChannels( &p_filter->output );
 
     /* Do the actual decoding now. */
     mad_stream_buffer( &p_sys->mad_stream, p_in_buf->p_buffer,
@@ -135,11 +136,20 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
     {
         msg_Dbg( p_aout, "libmad error: %s",
                   mad_stream_errorstr( &p_sys->mad_stream ) );
+        p_sys->i_reject_count = 3;
+    }
+    else if( p_in_buf->b_discontinuity )
+    {
+        p_sys->i_reject_count = 3;
+    }
+
+    if( p_sys->i_reject_count > 0 )
+    {
         if( p_filter->output.i_format == VLC_FOURCC('f','l','3','2') )
         {
             int i;
             int i_size = p_out_buf->i_nb_bytes / sizeof(float);
-            
+
             float * a = (float *)p_out_buf->p_buffer;
             for ( i = 0 ; i < i_size ; i++ )
                 *a++ = 0.0;
@@ -148,9 +158,11 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
         {
             memset( p_out_buf->p_buffer, 0, p_out_buf->i_nb_bytes );
         }
+        p_sys->i_reject_count--;
         return;
     }
 
+
     mad_synth_frame( &p_sys->mad_synth, &p_sys->mad_frame );
 
     if ( p_filter->output.i_format == VLC_FOURCC('f','i','3','2') )
@@ -165,20 +177,46 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
         switch ( p_pcm->channels )
         {
         case 2:
-            while ( i_samples-- )
+            if ( p_filter->output.i_physical_channels == AOUT_CHAN_CENTER )
+            {
+                while ( i_samples-- )
+                {
+                    *p_samples++ = (*p_left++ >> 1) + (*p_right++ >> 1);
+                }
+            }
+            else if ( p_filter->output.i_original_channels == AOUT_CHAN_LEFT )
+            {
+                while ( i_samples-- )
+                {
+                    *p_samples++ = *p_left;
+                    *p_samples++ = *p_left++;
+                }
+            }
+            else if ( p_filter->output.i_original_channels == AOUT_CHAN_RIGHT )
             {
-                *p_samples++ = *p_left++;
-                *p_samples++ = *p_right++;
+                while ( i_samples-- )
+                {
+                    *p_samples++ = *p_right;
+                    *p_samples++ = *p_right++;
+                }
+            }
+            else
+            {
+                while ( i_samples-- )
+                {
+                    *p_samples++ = *p_left++;
+                    *p_samples++ = *p_right++;
+                }
             }
             break;
 
         case 1:
-            p_filter->p_vlc->pf_memcpy( p_samples, p_left,
+            p_filter->p_libvlc->pf_memcpy( p_samples, p_left,
                                         i_samples * sizeof(mad_fixed_t) );
             break;
 
         default:
-            msg_Err( p_filter, "cannot interleave %i channels",
+            msg_Err( p_aout, "cannot interleave %i channels",
                      p_pcm->channels );
         }
     }
@@ -191,14 +229,41 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
         mad_fixed_t const * p_left = p_pcm->samples[0];
         mad_fixed_t const * p_right = p_pcm->samples[1];
         float f_temp = (float)FIXED32_ONE;
-        
+
         switch ( p_pcm->channels )
         {
         case 2:
-            while ( i_samples-- )
+            if ( p_filter->output.i_physical_channels == AOUT_CHAN_CENTER )
             {
-                *p_samples++ = (float)*p_left++ / f_temp;
-                *p_samples++ = (float)*p_right++ / f_temp;
+                while ( i_samples-- )
+                {
+                    *p_samples++ = (float)*p_left++ / f_temp / 2 +
+                                   (float)*p_right++ / f_temp / 2;
+                }
+            }
+            else if ( p_filter->output.i_original_channels == AOUT_CHAN_LEFT )
+            {
+                while ( i_samples-- )
+                {
+                    *p_samples++ = (float)*p_left / f_temp;
+                    *p_samples++ = (float)*p_left++ / f_temp;
+                }
+            }
+            else if ( p_filter->output.i_original_channels == AOUT_CHAN_RIGHT )
+            {
+                while ( i_samples-- )
+                {
+                    *p_samples++ = (float)*p_right / f_temp;
+                    *p_samples++ = (float)*p_right++ / f_temp;
+                }
+            }
+            else
+            {
+                while ( i_samples-- )
+                {
+                    *p_samples++ = (float)*p_left++ / f_temp;
+                    *p_samples++ = (float)*p_right++ / f_temp;
+                }
             }
             break;
 
@@ -210,7 +275,7 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
             break;
 
         default:
-            msg_Err( p_filter, "cannot interleave %i channels",
+            msg_Err( p_aout, "cannot interleave %i channels",
                      p_pcm->channels );
         }
     }
@@ -231,7 +296,7 @@ static void Destroy( vlc_object_t *p_this )
 }
 
 /*****************************************************************************
- * OpenFilter: 
+ * OpenFilter:
  *****************************************************************************/
 static int OpenFilter( vlc_object_t *p_this )
 {
@@ -251,6 +316,7 @@ static int OpenFilter( vlc_object_t *p_this )
         msg_Err( p_filter, "out of memory" );
         return -1;
     }
+    p_sys->i_reject_count = 0;
 
     p_filter->pf_audio_filter = Convert;
 
@@ -260,14 +326,18 @@ static int OpenFilter( vlc_object_t *p_this )
     mad_synth_init( &p_sys->mad_synth );
     mad_stream_options( &p_sys->mad_stream, MAD_OPTION_IGNORECRC );
 
+    if( vlc_CPU() & CPU_CAPABILITY_FPU )
+        p_filter->fmt_out.i_codec = VLC_FOURCC('f','l','3','2');
+    else
+        p_filter->fmt_out.i_codec = VLC_FOURCC('f','i','3','2');
+    p_filter->fmt_out.audio.i_format = p_filter->fmt_out.i_codec;
+
+    p_filter->fmt_out.audio.i_rate = p_filter->fmt_in.audio.i_rate;
+
     msg_Dbg( p_this, "%4.4s->%4.4s, bits per sample: %i",
              (char *)&p_filter->fmt_in.i_codec,
              (char *)&p_filter->fmt_out.i_codec,
-             p_filter->fmt_out.audio.i_bitspersample );
-
-    p_filter->fmt_out.i_codec =
-        p_filter->fmt_out.audio.i_format = VLC_FOURCC('f','l','3','2');
-    p_filter->fmt_out.audio.i_bitspersample = sizeof(float);
+             p_filter->fmt_in.audio.i_bitspersample );
 
     return 0;
 }
@@ -323,6 +393,7 @@ static block_t *Convert( filter_t *p_filter, block_t *p_block )
     aout_filter.output.i_format = p_filter->fmt_out.i_codec;
 
     in_buf.p_buffer = p_block->p_buffer;
+    in_buf.b_discontinuity = VLC_FALSE;
     in_buf.i_nb_bytes = p_block->i_buffer;
     in_buf.i_nb_samples = p_block->i_samples;
     out_buf.p_buffer = p_out->p_buffer;