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

s16tofloat32swab.c

00001 /*****************************************************************************
00002  * s16tofloat32swab.c : converter from signed 16 bits integer to float32
00003  *                      with endianness change
00004  *****************************************************************************
00005  * Copyright (C) 2002-2005 the VideoLAN team
00006  * $Id: s16tofloat32swab.c 11664 2005-07-09 06:17:09Z courmisch $
00007  *
00008  * Authors: Samuel Hocevar <[email protected]>
00009  *          Henri Fallon <[email protected]>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00024  *****************************************************************************/
00025 
00026 /*****************************************************************************
00027  * Preamble
00028  *****************************************************************************/
00029 #include <stdlib.h>                                      /* malloc(), free() */
00030 #include <string.h>
00031 
00032 #include <vlc/vlc.h>
00033 
00034 #ifdef HAVE_UNISTD_H
00035 #   include <unistd.h>
00036 #endif
00037 
00038 #ifdef HAVE_ALLOCA_H
00039 #   include <alloca.h>
00040 #endif
00041 
00042 #include "audio_output.h"
00043 #include "aout_internal.h"
00044 
00045 /*****************************************************************************
00046  * Local prototypes
00047  *****************************************************************************/
00048 static int  Create    ( vlc_object_t * );
00049 
00050 static void DoWork    ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
00051                         aout_buffer_t * );
00052 static void DoWork24  ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
00053                         aout_buffer_t * );
00054 
00055 /*****************************************************************************
00056  * Module descriptor
00057  *****************************************************************************/
00058 vlc_module_begin();
00059     set_category( CAT_AUDIO );
00060     set_subcategory( SUBCAT_AUDIO_MISC );
00061     set_description(
00062             _("audio filter for s16->float32 with endianness conversion") );
00063     set_capability( "audio filter", 1 );
00064     set_callbacks( Create, NULL );
00065 vlc_module_end();
00066 
00067 /*****************************************************************************
00068  * Create: allocate trivial mixer
00069  *****************************************************************************
00070  * This function allocates and initializes a Crop vout method.
00071  *****************************************************************************/
00072 static int Create( vlc_object_t *p_this )
00073 {
00074     aout_filter_t * p_filter = (aout_filter_t *)p_this;
00075 
00076     if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
00077     {
00078         return -1;
00079     }
00080 
00081     if ( (p_filter->input.i_format == VLC_FOURCC('s','1','6','l') ||
00082          p_filter->input.i_format == VLC_FOURCC('s','1','6','b'))
00083          && p_filter->output.i_format == VLC_FOURCC('f','l','3','2')
00084          && p_filter->input.i_format != AOUT_FMT_S16_NE )
00085     {
00086         p_filter->pf_do_work = DoWork;
00087         p_filter->b_in_place = VLC_TRUE;
00088 
00089         return 0;
00090     }
00091 
00092     if ( (p_filter->input.i_format == VLC_FOURCC('s','2','4','l') ||
00093          p_filter->input.i_format == VLC_FOURCC('s','2','4','b'))
00094          && p_filter->output.i_format == VLC_FOURCC('f','l','3','2')
00095          && p_filter->input.i_format != AOUT_FMT_S24_NE )
00096     {
00097         p_filter->pf_do_work = DoWork24;
00098         p_filter->b_in_place = VLC_TRUE;
00099 
00100         return 0;
00101     }
00102 
00103     return -1;
00104 }
00105 
00106 /*****************************************************************************
00107  * DoWork: convert a buffer
00108  *****************************************************************************/
00109 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
00110                     aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00111 {
00112     int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->input );
00113 
00114     /* We start from the end because b_in_place is true */
00115     int16_t * p_in;
00116     float * p_out = (float *)p_out_buf->p_buffer + i - 1;
00117 
00118 #ifdef HAVE_SWAB
00119 #   ifdef HAVE_ALLOCA
00120     int16_t * p_swabbed = alloca( i * sizeof(int16_t) );
00121 #   else
00122     int16_t * p_swabbed = malloc( i * sizeof(int16_t) );
00123 #   endif
00124 
00125     swab( p_in_buf->p_buffer, (void *)p_swabbed, i * sizeof(int16_t) );
00126     p_in = p_swabbed + i - 1;
00127 
00128 #else
00129     byte_t p_tmp[2];
00130     p_in = (int16_t *)p_in_buf->p_buffer + i - 1;
00131 #endif
00132 
00133     while( i-- )
00134     {
00135 #ifndef HAVE_SWAB
00136         p_tmp[0] = ((byte_t *)p_in)[1];
00137         p_tmp[1] = ((byte_t *)p_in)[0];
00138         *p_out = (float)( *(int16_t *)p_tmp ) / 32768.0;
00139 #else
00140         *p_out = (float)*p_in / 32768.0;
00141 #endif
00142         p_in--; p_out--;
00143     }
00144 
00145 #ifdef HAVE_SWAB
00146 #   ifndef HAVE_ALLOCA
00147     free( p_swabbed );
00148 #   endif
00149 #endif
00150 
00151     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00152     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 2;
00153 }
00154 
00155 static void DoWork24( aout_instance_t * p_aout, aout_filter_t * p_filter,
00156                       aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00157 {
00158     int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->input );
00159 
00160     /* We start from the end because b_in_place is true */
00161     uint8_t * p_in = (uint8_t *)p_in_buf->p_buffer + (i - 1) * 3;
00162     float * p_out = (float *)p_out_buf->p_buffer + i - 1;
00163 
00164     byte_t p_tmp[3];
00165 
00166     while( i-- )
00167     {
00168         p_tmp[0] = p_in[2];
00169         p_tmp[1] = p_in[1];
00170         p_tmp[2] = p_in[0];
00171 
00172 #ifdef WORDS_BIGENDIAN
00173         *p_out = ((float)( (((int32_t)*(int16_t *)(p_tmp)) << 8) + p_tmp[2]))
00174 #else
00175         *p_out = ((float)( (((int32_t)*(int16_t *)(p_tmp+1)) << 8) + p_tmp[0]))
00176 #endif
00177             / 8388608.0;
00178 
00179         p_in -= 3; p_out--;
00180     }
00181 
00182     p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00183     p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 4 / 3;
00184 }

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