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

fixed32tofloat32.c

00001 /*****************************************************************************
00002  * fixed32float32.c : converter from fixed32 to float32 bits integer
00003  *****************************************************************************
00004  * Copyright (C) 2002 the VideoLAN team
00005  * $Id: fixed32tofloat32.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Jean-Paul Saman <[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 FixedToFloat ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
00040                            aout_buffer_t * );
00041 static void FloatToFixed ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
00042                            aout_buffer_t * );
00043 
00044 /*****************************************************************************
00045  * Module descriptor
00046  *****************************************************************************/
00047 vlc_module_begin();
00048     set_category( CAT_AUDIO );
00049     set_subcategory( SUBCAT_AUDIO_MISC );
00050     set_description( _("audio filter for fixed32<->float32 conversion") );
00051     set_capability( "audio filter", 10 );
00052     set_callbacks( Create, NULL );
00053 vlc_module_end();
00054 
00055 /*****************************************************************************
00056  * Create: allocate trivial mixer
00057  *****************************************************************************
00058  * This function allocates and initializes a Crop vout method.
00059  *****************************************************************************/
00060 static int Create( vlc_object_t *p_this )
00061 {
00062     aout_filter_t * p_filter = (aout_filter_t *)p_this;
00063 
00064     if( ( p_filter->input.i_format != VLC_FOURCC('f','i','3','2')
00065            || p_filter->output.i_format != VLC_FOURCC('f','l','3','2') )
00066       && ( p_filter->input.i_format != VLC_FOURCC('f','l','3','2')
00067             || p_filter->output.i_format != VLC_FOURCC('f','i','3','2') ) )
00068     {
00069         return -1;
00070     }
00071 
00072     if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
00073     {
00074         return -1;
00075     }
00076 
00077     if( p_filter->input.i_format == VLC_FOURCC('f','i','3','2') )
00078     {
00079         p_filter->pf_do_work = FixedToFloat;
00080     }
00081     else
00082     {
00083         p_filter->pf_do_work = FloatToFixed;
00084     }
00085 
00086     p_filter->b_in_place = 1;
00087 
00088     return 0;
00089 }
00090 
00091 /*****************************************************************************
00092  * FixedToFloat: convert a buffer
00093  *****************************************************************************/
00094 static void FixedToFloat( aout_instance_t * p_aout, aout_filter_t * p_filter,
00095                           aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00096 {
00097     int i;
00098     vlc_fixed_t * p_in = (vlc_fixed_t *)p_in_buf->p_buffer;
00099     float * p_out = (float *)p_out_buf->p_buffer;
00100 
00101     for ( i = p_in_buf->i_nb_samples
00102                * aout_FormatNbChannels( &p_filter->input ) ; i-- ; )
00103     {
00104         *p_out++ = (float)*p_in++ / (float)FIXED32_ONE;
00105     }
00106 
00107     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00108     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes;
00109 }
00110 
00111 /*****************************************************************************
00112  * FloatToFixed: convert a buffer
00113  *****************************************************************************/
00114 static void FloatToFixed( aout_instance_t * p_aout, aout_filter_t * p_filter,
00115                           aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00116 {
00117     int i;
00118     float * p_in = (float *)p_in_buf->p_buffer;
00119     vlc_fixed_t * p_out = (vlc_fixed_t *)p_out_buf->p_buffer;
00120 
00121     for ( i = p_in_buf->i_nb_samples
00122                * aout_FormatNbChannels( &p_filter->input ) ; i-- ; )
00123     {
00124         *p_out++ = (vlc_fixed_t)( *p_in++ * (float)FIXED32_ONE );
00125     }
00126 
00127     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00128     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes;
00129 }
00130 

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