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
00042
00043
00044
00045 vlc_module_begin();
00046 set_description( _("audio filter for ugly resampling") );
00047 set_capability( "audio filter", 2 );
00048 set_category( CAT_AUDIO );
00049 set_subcategory( SUBCAT_AUDIO_MISC );
00050 set_callbacks( Create, NULL );
00051 vlc_module_end();
00052
00053
00054
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_rate == p_filter->output.i_rate
00061 || p_filter->input.i_format != p_filter->output.i_format
00062 || p_filter->input.i_physical_channels
00063 != p_filter->output.i_physical_channels
00064 || p_filter->input.i_original_channels
00065 != p_filter->output.i_original_channels
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 VLC_EGENERIC;
00070 }
00071
00072 p_filter->pf_do_work = DoWork;
00073
00074
00075
00076 p_filter->b_in_place = VLC_TRUE;
00077
00078 return VLC_SUCCESS;
00079 }
00080
00081
00082
00083
00084 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
00085 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00086 {
00087 int32_t *p_in, *p_out = (int32_t*)p_out_buf->p_buffer;
00088 #ifndef HAVE_ALLOCA
00089 int32_t *p_in_orig;
00090 #endif
00091
00092 unsigned int i_nb_channels = aout_FormatNbChannels( &p_filter->input );
00093 unsigned int i_in_nb = p_in_buf->i_nb_samples;
00094 unsigned int i_out_nb = i_in_nb * p_filter->output.i_rate
00095 / p_filter->input.i_rate;
00096 unsigned int i_sample_bytes = i_nb_channels * sizeof(int32_t);
00097 unsigned int i_out, i_chan, i_remainder = 0;
00098
00099
00100 if( p_aout->mixer.mixer.i_rate == p_filter->input.i_rate )
00101 {
00102 return;
00103 }
00104
00105 #ifdef HAVE_ALLOCA
00106 p_in = (int32_t *)alloca( p_in_buf->i_nb_bytes );
00107 #else
00108 p_in_orig = p_in = (int32_t *)malloc( p_in_buf->i_nb_bytes );
00109 #endif
00110 if( p_in == NULL )
00111 {
00112 return;
00113 }
00114
00115 p_aout->p_vlc->pf_memcpy( p_in, p_in_buf->p_buffer, p_in_buf->i_nb_bytes );
00116
00117 for( i_out = i_out_nb ; i_out-- ; )
00118 {
00119 for( i_chan = i_nb_channels ; i_chan ; )
00120 {
00121 i_chan--;
00122 p_out[i_chan] = p_in[i_chan];
00123 }
00124 p_out += i_nb_channels;
00125
00126 i_remainder += p_filter->input.i_rate;
00127 while( i_remainder >= p_filter->output.i_rate )
00128 {
00129 p_in += i_nb_channels;
00130 i_remainder -= p_filter->output.i_rate;
00131 }
00132 }
00133
00134 p_out_buf->i_nb_samples = i_out_nb;
00135 p_out_buf->i_nb_bytes = i_out_nb * i_sample_bytes;
00136 p_out_buf->start_date = p_in_buf->start_date;
00137 p_out_buf->end_date = p_out_buf->start_date + p_out_buf->i_nb_samples *
00138 1000000 / p_filter->output.i_rate;
00139
00140 #ifndef HAVE_ALLOCA
00141 free( p_in_orig );
00142 #endif
00143
00144 }