Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

trivial.c

00001 /*****************************************************************************
00002  * trivial.c : trivial channel mixer plug-in (drops unwanted channels)
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id: trivial.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Christophe Massiot <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>                                      /* malloc(), free() */
00028 #include <string.h>
00029 
00030 #include <vlc/vlc.h>
00031 #include "audio_output.h"
00032 #include "aout_internal.h"
00033 
00034 /*****************************************************************************
00035  * Local prototypes
00036  *****************************************************************************/
00037 static int  Create    ( vlc_object_t * );
00038 
00039 static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
00040                         aout_buffer_t * );
00041 
00042 /*****************************************************************************
00043  * Module descriptor
00044  *****************************************************************************/
00045 vlc_module_begin();
00046     set_description( _("audio filter for trivial channel mixing") );
00047     set_capability( "audio filter", 1 );
00048     set_category( CAT_AUDIO );
00049     set_subcategory( SUBCAT_AUDIO_MISC );
00050     set_callbacks( Create, NULL );
00051 vlc_module_end();
00052 
00053 /*****************************************************************************
00054  * Create: allocate trivial channel mixer
00055  *****************************************************************************/
00056 static int Create( vlc_object_t *p_this )
00057 {
00058     aout_filter_t * p_filter = (aout_filter_t *)p_this;
00059 
00060     if ( (p_filter->input.i_physical_channels
00061            == p_filter->output.i_physical_channels
00062            && p_filter->input.i_original_channels
00063                == p_filter->output.i_original_channels)
00064           || p_filter->input.i_format != p_filter->output.i_format
00065           || p_filter->input.i_rate != p_filter->output.i_rate
00066           || (p_filter->input.i_format != VLC_FOURCC('f','l','3','2')
00067                && p_filter->input.i_format != VLC_FOURCC('f','i','3','2')) )
00068     {
00069         return -1;
00070     }
00071 
00072     p_filter->pf_do_work = DoWork;
00073     if ( aout_FormatNbChannels( &p_filter->input )
00074            > aout_FormatNbChannels( &p_filter->output ) )
00075     {
00076         /* Downmixing */
00077         p_filter->b_in_place = 1;
00078     }
00079     else
00080     {
00081         /* Upmixing */
00082         p_filter->b_in_place = 0;
00083     }
00084 
00085     return 0;
00086 }
00087 
00088 /*****************************************************************************
00089  * SparseCopy: trivially downmix or upmix a buffer
00090  *****************************************************************************/
00091 static void SparseCopy( int32_t * p_dest, const int32_t * p_src, size_t i_len,
00092                         int i_output_stride, int i_input_stride )
00093 {
00094     int i;
00095     for ( i = i_len; i--; )
00096     {
00097         int j;
00098         for ( j = 0; j < i_output_stride; j++ )
00099         {
00100             p_dest[j] = p_src[j % i_input_stride];
00101         }
00102         p_src += i_input_stride;
00103         p_dest += i_output_stride;
00104     }
00105 }
00106 
00107 /*****************************************************************************
00108  * DoWork: convert a buffer
00109  *****************************************************************************/
00110 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
00111                     aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00112 {
00113     int i_input_nb = aout_FormatNbChannels( &p_filter->input );
00114     int i_output_nb = aout_FormatNbChannels( &p_filter->output );
00115     int32_t * p_dest = (int32_t *)p_out_buf->p_buffer;
00116     int32_t * p_src = (int32_t *)p_in_buf->p_buffer;
00117 
00118     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00119     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * i_output_nb / i_input_nb;
00120 
00121     if ( (p_filter->output.i_original_channels & AOUT_CHAN_PHYSMASK)
00122                 != (p_filter->input.i_original_channels & AOUT_CHAN_PHYSMASK)
00123            && (p_filter->input.i_original_channels & AOUT_CHAN_PHYSMASK)
00124                 == (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT) )
00125     {
00126         int i;
00127         /* This is a bit special. */
00128         if ( !(p_filter->output.i_original_channels & AOUT_CHAN_LEFT) )
00129         {
00130             p_src++;
00131         }
00132         if ( p_filter->output.i_physical_channels == AOUT_CHAN_CENTER )
00133         {
00134             /* Mono mode */
00135             for ( i = p_in_buf->i_nb_samples; i--; )
00136             {
00137                 *p_dest = *p_src;
00138                 p_dest++;
00139                 p_src += 2;
00140             }
00141         }
00142         else
00143         {
00144             /* Fake-stereo mode */
00145             for ( i = p_in_buf->i_nb_samples; i--; )
00146             {
00147                 *p_dest = *p_src;
00148                 p_dest++;
00149                 *p_dest = *p_src;
00150                 p_dest++;
00151                 p_src += 2;
00152             }
00153         }
00154     }
00155     else if ( p_filter->output.i_original_channels
00156                                     & AOUT_CHAN_REVERSESTEREO )
00157     {
00158         /* Reverse-stereo mode */
00159         int i;
00160         for ( i = p_in_buf->i_nb_samples; i--; )
00161         {
00162             *p_dest = p_src[1];
00163             p_dest++;
00164             *p_dest = p_src[0];
00165             p_dest++;
00166             p_src += 2;
00167         }
00168     }
00169     else
00170     {
00171         SparseCopy( p_dest, p_src, p_in_buf->i_nb_samples, i_output_nb,
00172                     i_input_nb );
00173     }
00174 }
00175 

Generated on Tue Dec 20 10:14:27 2005 for vlc-0.8.4a by  doxygen 1.4.2