00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdlib.h>
00028 #include <string.h>
00029
00030 #include <vlc/vlc.h>
00031 #include "audio_output.h"
00032 #include "aout_internal.h"
00033
00034
00035
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 static void DoWork24 ( aout_instance_t *, aout_filter_t *, aout_buffer_t *,
00042 aout_buffer_t * );
00043
00044
00045
00046
00047 vlc_module_begin();
00048 set_category( CAT_AUDIO );
00049 set_subcategory( SUBCAT_AUDIO_MISC );
00050 set_description( _("audio filter for s16->float32 conversion") );
00051 set_capability( "audio filter", 1 );
00052 set_callbacks( Create, NULL );
00053 vlc_module_end();
00054
00055
00056
00057
00058
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 != AOUT_FMT_S16_NE &&
00065 p_filter->input.i_format != AOUT_FMT_S24_NE )
00066 || p_filter->output.i_format != VLC_FOURCC('f','l','3','2') )
00067 {
00068 return -1;
00069 }
00070
00071 if ( !AOUT_FMTS_SIMILAR( &p_filter->input, &p_filter->output ) )
00072 {
00073 return -1;
00074 }
00075
00076 if( p_filter->input.i_format == AOUT_FMT_S24_NE )
00077 p_filter->pf_do_work = DoWork24;
00078 else
00079 p_filter->pf_do_work = DoWork;
00080
00081 p_filter->b_in_place = VLC_TRUE;
00082
00083 return 0;
00084 }
00085
00086
00087
00088
00089 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
00090 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00091 {
00092 int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->input );
00093
00094
00095 int16_t * p_in = (int16_t *)p_in_buf->p_buffer + i - 1;
00096 float * p_out = (float *)p_out_buf->p_buffer + i - 1;
00097
00098 while( i-- )
00099 {
00100 #if 0
00101
00102 *p_out = (float)*p_in / 32768.0;
00103 #else
00104
00105
00106
00107 union { float f; int32_t i; } u;
00108 u.i = *p_in + 0x43c00000;
00109 *p_out = u.f - 384.0;
00110 #endif
00111
00112 p_in--; p_out--;
00113 }
00114
00115 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00116 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 2;
00117 }
00118
00119 static void DoWork24( aout_instance_t * p_aout, aout_filter_t * p_filter,
00120 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00121 {
00122 int i = p_in_buf->i_nb_samples * aout_FormatNbChannels( &p_filter->input );
00123
00124
00125 uint8_t * p_in = (uint8_t *)p_in_buf->p_buffer + (i - 1) * 3;
00126 float * p_out = (float *)p_out_buf->p_buffer + i - 1;
00127
00128 while( i-- )
00129 {
00130 #ifdef WORDS_BIGENDIAN
00131 *p_out = ((float)( (((int32_t)*(int16_t *)(p_in)) << 8) + p_in[2]))
00132 #else
00133 *p_out = ((float)( (((int32_t)*(int16_t *)(p_in+1)) << 8) + p_in[0]))
00134 #endif
00135 / 8388608.0;
00136
00137 p_in -= 3; p_out--;
00138 }
00139
00140 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00141 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * 4 / 3;
00142 }