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 simple channel mixing") );
00047 set_capability( "audio filter", 10 );
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_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 {
00068 return -1;
00069 }
00070
00071
00072 if( p_filter->output.i_physical_channels !=
00073 (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT) ) return -1;
00074
00075
00076 if( (p_filter->input.i_physical_channels & ~AOUT_CHAN_LFE) !=
00077 (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
00078 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT) &&
00079 (p_filter->input.i_physical_channels & ~AOUT_CHAN_LFE) !=
00080 (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER |
00081 AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT |
00082 AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT) )
00083 {
00084 return -1;
00085 }
00086
00087 p_filter->pf_do_work = DoWork;
00088 p_filter->b_in_place = 0;
00089
00090 return 0;
00091 }
00092
00093
00094
00095
00096 static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
00097 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
00098 {
00099 int i_input_nb = aout_FormatNbChannels( &p_filter->input );
00100 int i_output_nb = aout_FormatNbChannels( &p_filter->output );
00101 float *p_dest = (float *)p_out_buf->p_buffer;
00102 float *p_src = (float *)p_in_buf->p_buffer;
00103 int i;
00104
00105 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
00106 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * i_output_nb / i_input_nb;
00107
00108 if( p_filter->input.i_physical_channels & AOUT_CHAN_MIDDLELEFT )
00109 for( i = p_in_buf->i_nb_samples; i--; )
00110 {
00111 *p_dest = p_src[6] + 0.5 * p_src[0] + p_src[2] / 4 + p_src[4] / 4;
00112 p_dest++;
00113 *p_dest = p_src[6] + 0.5 * p_src[1] + p_src[3] / 4 + p_src[5] / 4;
00114 p_dest++;
00115
00116 p_src += 7;
00117
00118 if( p_filter->input.i_physical_channels & AOUT_CHAN_LFE ) p_src++;
00119 }
00120 else
00121 for( i = p_in_buf->i_nb_samples; i--; )
00122 {
00123 *p_dest = p_src[4] + 0.5 * p_src[0] + 0.33 * p_src[2];
00124 p_dest++;
00125 *p_dest = p_src[4] + 0.5 * p_src[1] + 0.33 * p_src[3];
00126 p_dest++;
00127
00128 p_src += 5;
00129
00130 if( p_filter->input.i_physical_channels & AOUT_CHAN_LFE ) p_src++;
00131 }
00132 }