1 /*****************************************************************************
2 * mono.c : stereo2mono downmixsimple channel mixer plug-in
3 *****************************************************************************
4 * Copyright (C) 2006 M2X
7 * Authors: Jean-Paul Saman <jpsaman at m2x dot nl>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
31 #include <math.h> /* sqrt */
34 # include <stdint.h> /* int16_t .. */
35 #elif defined(HAVE_INTTYPES_H)
36 # include <inttypes.h> /* int16_t .. */
43 #include <vlc_common.h>
44 #include <vlc_plugin.h>
46 #include <vlc_block.h>
47 #include <vlc_filter.h>
50 /*****************************************************************************
52 *****************************************************************************/
53 static int OpenFilter ( vlc_object_t * );
54 static void CloseFilter ( vlc_object_t * );
56 static block_t *Convert( filter_t *p_filter, block_t *p_block );
58 static unsigned int stereo_to_mono( aout_filter_t *, aout_buffer_t *,
60 static unsigned int mono( aout_filter_t *, aout_buffer_t *, aout_buffer_t * );
61 static void stereo2mono_downmix( aout_filter_t *, aout_buffer_t *,
64 /*****************************************************************************
66 *****************************************************************************/
67 struct atomic_operation_t
69 int i_source_channel_offset;
70 int i_dest_channel_offset;
71 unsigned int i_delay;/* in sample unit */
72 double d_amplitude_factor;
79 unsigned int i_nb_channels; /* number of int16_t per sample */
80 int i_channel_selected;
83 size_t i_overflow_buffer_size;/* in bytes */
84 uint8_t * p_overflow_buffer;
85 unsigned int i_nb_atomic_operations;
86 struct atomic_operation_t * p_atomic_operations;
89 #define MONO_DOWNMIX_TEXT N_("Use downmix algorithm")
90 #define MONO_DOWNMIX_LONGTEXT N_("This option selects a stereo to mono " \
91 "downmix algorithm that is used in the headphone channel mixer. It " \
92 "gives the effect of standing in a room full of speakers." )
94 #define MONO_CHANNEL_TEXT N_("Select channel to keep")
95 #define MONO_CHANNEL_LONGTEXT N_("This option silences all other channels " \
96 "except the selected channel. Choose one from (0=left, 1=right, " \
97 "2=rear left, 3=rear right, 4=center, 5=left front)")
99 static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5 };
100 static const char *const ppsz_pos_descriptions[] =
101 { N_("Left"), N_("Right"), N_("Left rear"), N_("Right rear"), N_("Center"),
104 /* our internal channel order (WG-4 order) */
105 static const uint32_t pi_channels_out[] =
106 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
107 AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 };
109 #define MONO_CFG "sout-mono-"
110 /*****************************************************************************
112 *****************************************************************************/
114 set_description( N_("Audio filter for stereo to mono conversion") );
115 set_capability( "audio filter2", 1 );
117 add_bool( MONO_CFG "downmix", true, NULL, MONO_DOWNMIX_TEXT,
118 MONO_DOWNMIX_LONGTEXT, false );
119 add_integer( MONO_CFG "channel", -1, NULL, MONO_CHANNEL_TEXT,
120 MONO_CHANNEL_LONGTEXT, false );
121 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
123 set_category( CAT_AUDIO );
124 set_subcategory( SUBCAT_AUDIO_MISC );
125 set_callbacks( OpenFilter, CloseFilter );
126 set_shortname( "Mono" );
129 /* Init() and ComputeChannelOperations() -
130 * Code taken from modules/audio_filter/channel_mixer/headphone.c
131 * converted from float into int16_t based downmix
132 * Written by Boris Dorès <babal@via.ecp.fr>
135 /*****************************************************************************
136 * Init: initialize internal data structures
137 * and computes the needed atomic operations
138 *****************************************************************************/
139 /* x and z represent the coordinates of the virtual speaker
140 * relatively to the center of the listener's head, measured in meters :
149 * rear left rear right
153 static void ComputeChannelOperations( struct filter_sys_t * p_data,
154 unsigned int i_rate, unsigned int i_next_atomic_operation,
155 int i_source_channel_offset, double d_x, double d_z,
156 double d_compensation_length, double d_channel_amplitude_factor )
158 double d_c = 340; /*sound celerity (unit: m/s)*/
159 double d_compensation_delay = (d_compensation_length-0.1) / d_c * i_rate;
162 p_data->p_atomic_operations[i_next_atomic_operation]
163 .i_source_channel_offset = i_source_channel_offset;
164 p_data->p_atomic_operations[i_next_atomic_operation]
165 .i_dest_channel_offset = 0;/* left */
166 p_data->p_atomic_operations[i_next_atomic_operation]
167 .i_delay = (int)( sqrt( (-0.1-d_x)*(-0.1-d_x) + (0-d_z)*(0-d_z) )
168 / d_c * i_rate - d_compensation_delay );
171 p_data->p_atomic_operations[i_next_atomic_operation]
172 .d_amplitude_factor = d_channel_amplitude_factor * 1.1 / 2;
176 p_data->p_atomic_operations[i_next_atomic_operation]
177 .d_amplitude_factor = d_channel_amplitude_factor * 0.9 / 2;
181 p_data->p_atomic_operations[i_next_atomic_operation]
182 .d_amplitude_factor = d_channel_amplitude_factor / 2;
186 p_data->p_atomic_operations[i_next_atomic_operation + 1]
187 .i_source_channel_offset = i_source_channel_offset;
188 p_data->p_atomic_operations[i_next_atomic_operation + 1]
189 .i_dest_channel_offset = 1;/* right */
190 p_data->p_atomic_operations[i_next_atomic_operation + 1]
191 .i_delay = (int)( sqrt( (0.1-d_x)*(0.1-d_x) + (0-d_z)*(0-d_z) )
192 / d_c * i_rate - d_compensation_delay );
195 p_data->p_atomic_operations[i_next_atomic_operation + 1]
196 .d_amplitude_factor = d_channel_amplitude_factor * 0.9 / 2;
200 p_data->p_atomic_operations[i_next_atomic_operation + 1]
201 .d_amplitude_factor = d_channel_amplitude_factor * 1.1 / 2;
205 p_data->p_atomic_operations[i_next_atomic_operation + 1]
206 .d_amplitude_factor = d_channel_amplitude_factor / 2;
210 static int Init( vlc_object_t *p_this, struct filter_sys_t * p_data,
211 unsigned int i_nb_channels, uint32_t i_physical_channels,
212 unsigned int i_rate )
214 double d_x = config_GetInt( p_this, "headphone-dim" );
216 double d_z_rear = -d_x/3;
218 unsigned int i_next_atomic_operation;
219 int i_source_channel_offset;
222 if( config_GetInt( p_this, "headphone-compensate" ) )
224 /* minimal distance to any speaker */
225 if( i_physical_channels & AOUT_CHAN_REARCENTER )
235 /* Number of elementary operations */
236 p_data->i_nb_atomic_operations = i_nb_channels * 2;
237 if( i_physical_channels & AOUT_CHAN_CENTER )
239 p_data->i_nb_atomic_operations += 2;
241 p_data->p_atomic_operations = malloc( sizeof(struct atomic_operation_t)
242 * p_data->i_nb_atomic_operations );
243 if( p_data->p_atomic_operations == NULL )
246 /* For each virtual speaker, computes elementary wave propagation time
248 i_next_atomic_operation = 0;
249 i_source_channel_offset = 0;
250 if( i_physical_channels & AOUT_CHAN_LEFT )
252 ComputeChannelOperations( p_data , i_rate
253 , i_next_atomic_operation , i_source_channel_offset
254 , -d_x , d_z , d_min , 2.0 / i_nb_channels );
255 i_next_atomic_operation += 2;
256 i_source_channel_offset++;
258 if( i_physical_channels & AOUT_CHAN_RIGHT )
260 ComputeChannelOperations( p_data , i_rate
261 , i_next_atomic_operation , i_source_channel_offset
262 , d_x , d_z , d_min , 2.0 / i_nb_channels );
263 i_next_atomic_operation += 2;
264 i_source_channel_offset++;
266 if( i_physical_channels & AOUT_CHAN_MIDDLELEFT )
268 ComputeChannelOperations( p_data , i_rate
269 , i_next_atomic_operation , i_source_channel_offset
270 , -d_x , 0 , d_min , 1.5 / i_nb_channels );
271 i_next_atomic_operation += 2;
272 i_source_channel_offset++;
274 if( i_physical_channels & AOUT_CHAN_MIDDLERIGHT )
276 ComputeChannelOperations( p_data , i_rate
277 , i_next_atomic_operation , i_source_channel_offset
278 , d_x , 0 , d_min , 1.5 / i_nb_channels );
279 i_next_atomic_operation += 2;
280 i_source_channel_offset++;
282 if( i_physical_channels & AOUT_CHAN_REARLEFT )
284 ComputeChannelOperations( p_data , i_rate
285 , i_next_atomic_operation , i_source_channel_offset
286 , -d_x , d_z_rear , d_min , 1.5 / i_nb_channels );
287 i_next_atomic_operation += 2;
288 i_source_channel_offset++;
290 if( i_physical_channels & AOUT_CHAN_REARRIGHT )
292 ComputeChannelOperations( p_data , i_rate
293 , i_next_atomic_operation , i_source_channel_offset
294 , d_x , d_z_rear , d_min , 1.5 / i_nb_channels );
295 i_next_atomic_operation += 2;
296 i_source_channel_offset++;
298 if( i_physical_channels & AOUT_CHAN_REARCENTER )
300 ComputeChannelOperations( p_data , i_rate
301 , i_next_atomic_operation , i_source_channel_offset
302 , 0 , -d_z , d_min , 1.5 / i_nb_channels );
303 i_next_atomic_operation += 2;
304 i_source_channel_offset++;
306 if( i_physical_channels & AOUT_CHAN_CENTER )
308 /* having two center channels increases the spatialization effect */
309 ComputeChannelOperations( p_data , i_rate
310 , i_next_atomic_operation , i_source_channel_offset
311 , d_x / 5.0 , d_z , d_min , 0.75 / i_nb_channels );
312 i_next_atomic_operation += 2;
313 ComputeChannelOperations( p_data , i_rate
314 , i_next_atomic_operation , i_source_channel_offset
315 , -d_x / 5.0 , d_z , d_min , 0.75 / i_nb_channels );
316 i_next_atomic_operation += 2;
317 i_source_channel_offset++;
319 if( i_physical_channels & AOUT_CHAN_LFE )
321 ComputeChannelOperations( p_data , i_rate
322 , i_next_atomic_operation , i_source_channel_offset
323 , 0 , d_z_rear , d_min , 5.0 / i_nb_channels );
324 i_next_atomic_operation += 2;
325 i_source_channel_offset++;
328 /* Initialize the overflow buffer
329 * we need it because the process induce a delay in the samples */
330 p_data->i_overflow_buffer_size = 0;
331 for( i = 0 ; i < p_data->i_nb_atomic_operations ; i++ )
333 if( p_data->i_overflow_buffer_size
334 < p_data->p_atomic_operations[i].i_delay * 2 * sizeof (int16_t) )
336 p_data->i_overflow_buffer_size
337 = p_data->p_atomic_operations[i].i_delay * 2 * sizeof (int16_t);
340 p_data->p_overflow_buffer = malloc( p_data->i_overflow_buffer_size );
341 if( p_data->p_overflow_buffer == NULL )
343 free( p_data->p_atomic_operations );
346 memset( p_data->p_overflow_buffer, 0, p_data->i_overflow_buffer_size );
352 /*****************************************************************************
354 *****************************************************************************/
355 static int OpenFilter( vlc_object_t *p_this )
357 filter_t * p_filter = (filter_t *)p_this;
358 filter_sys_t *p_sys = NULL;
360 if( aout_FormatNbChannels( &(p_filter->fmt_in.audio) ) == 1 )
362 msg_Dbg( p_filter, "filter discarded (incompatible format)" );
366 if( (p_filter->fmt_in.i_codec != AOUT_FMT_S16_NE) ||
367 (p_filter->fmt_out.i_codec != AOUT_FMT_S16_NE) )
369 msg_Err( p_this, "filter discarded (invalid format)" );
373 if( (p_filter->fmt_in.audio.i_format != p_filter->fmt_out.audio.i_format) &&
374 (p_filter->fmt_in.audio.i_rate != p_filter->fmt_out.audio.i_rate) &&
375 (p_filter->fmt_in.audio.i_format != AOUT_FMT_S16_NE) &&
376 (p_filter->fmt_out.audio.i_format != AOUT_FMT_S16_NE) &&
377 (p_filter->fmt_in.audio.i_bitspersample !=
378 p_filter->fmt_out.audio.i_bitspersample))
380 msg_Err( p_this, "couldn't load mono filter" );
384 /* Allocate the memory needed to store the module's structure */
385 p_sys = p_filter->p_sys = malloc( sizeof(filter_sys_t) );
389 var_Create( p_this, MONO_CFG "downmix",
390 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
391 p_sys->b_downmix = var_GetBool( p_this, MONO_CFG "downmix" );
393 var_Create( p_this, MONO_CFG "channel",
394 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
395 p_sys->i_channel_selected =
396 (unsigned int) var_GetInteger( p_this, MONO_CFG "channel" );
398 if( p_sys->b_downmix )
400 msg_Dbg( p_this, "using stereo to mono downmix" );
401 p_filter->fmt_out.audio.i_physical_channels = AOUT_CHAN_CENTER;
402 p_filter->fmt_out.audio.i_channels = 1;
406 msg_Dbg( p_this, "using pseudo mono" );
407 p_filter->fmt_out.audio.i_physical_channels =
408 (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT);
409 p_filter->fmt_out.audio.i_channels = 2;
412 p_filter->fmt_out.audio.i_rate = p_filter->fmt_in.audio.i_rate;
413 p_filter->fmt_out.audio.i_format = p_filter->fmt_out.i_codec;
415 p_sys->i_nb_channels = aout_FormatNbChannels( &(p_filter->fmt_in.audio) );
416 p_sys->i_bitspersample = p_filter->fmt_out.audio.i_bitspersample;
418 p_sys->i_overflow_buffer_size = 0;
419 p_sys->p_overflow_buffer = NULL;
420 p_sys->i_nb_atomic_operations = 0;
421 p_sys->p_atomic_operations = NULL;
423 if( Init( VLC_OBJECT(p_filter), p_filter->p_sys,
424 aout_FormatNbChannels( &p_filter->fmt_in.audio ),
425 p_filter->fmt_in.audio.i_physical_channels,
426 p_filter->fmt_in.audio.i_rate ) < 0 )
428 var_Destroy( p_this, MONO_CFG "channel" );
429 var_Destroy( p_this, MONO_CFG "downmix" );
434 p_filter->pf_audio_filter = Convert;
436 msg_Dbg( p_this, "%4.4s->%4.4s, channels %d->%d, bits per sample: %i->%i",
437 (char *)&p_filter->fmt_in.i_codec,
438 (char *)&p_filter->fmt_out.i_codec,
439 p_filter->fmt_in.audio.i_physical_channels,
440 p_filter->fmt_out.audio.i_physical_channels,
441 p_filter->fmt_in.audio.i_bitspersample,
442 p_filter->fmt_out.audio.i_bitspersample );
447 /*****************************************************************************
449 *****************************************************************************/
450 static void CloseFilter( vlc_object_t *p_this)
452 filter_t *p_filter = (filter_t *) p_this;
453 filter_sys_t *p_sys = p_filter->p_sys;
455 var_Destroy( p_this, MONO_CFG "channel" );
456 var_Destroy( p_this, MONO_CFG "downmix" );
457 free( p_sys->p_atomic_operations );
458 free( p_sys->p_overflow_buffer );
462 /*****************************************************************************
464 *****************************************************************************/
465 static block_t *Convert( filter_t *p_filter, block_t *p_block )
467 aout_filter_t aout_filter;
468 aout_buffer_t in_buf, out_buf;
469 block_t *p_out = NULL;
470 unsigned int i_samples;
473 if( !p_block || !p_block->i_samples )
476 block_Release( p_block );
480 i_out_size = p_block->i_samples * p_filter->p_sys->i_bitspersample/8 *
481 aout_FormatNbChannels( &(p_filter->fmt_out.audio) );
483 p_out = p_filter->pf_audio_buffer_new( p_filter, i_out_size );
486 msg_Warn( p_filter, "can't get output buffer" );
487 block_Release( p_block );
490 p_out->i_samples = (p_block->i_samples / p_filter->p_sys->i_nb_channels) *
491 aout_FormatNbChannels( &(p_filter->fmt_out.audio) );
492 p_out->i_dts = p_block->i_dts;
493 p_out->i_pts = p_block->i_pts;
494 p_out->i_length = p_block->i_length;
496 aout_filter.p_sys = (struct aout_filter_sys_t *)p_filter->p_sys;
497 aout_filter.input = p_filter->fmt_in.audio;
498 aout_filter.input.i_format = p_filter->fmt_in.i_codec;
499 aout_filter.output = p_filter->fmt_out.audio;
500 aout_filter.output.i_format = p_filter->fmt_out.i_codec;
502 in_buf.p_buffer = p_block->p_buffer;
503 in_buf.i_nb_bytes = p_block->i_buffer;
504 in_buf.i_nb_samples = p_block->i_samples;
507 unsigned int i_in_size = in_buf.i_nb_samples * (p_filter->p_sys->i_bitspersample/8) *
508 aout_FormatNbChannels( &(p_filter->fmt_in.audio) );
509 if( (in_buf.i_nb_bytes != i_in_size) && ((i_in_size % 32) != 0) ) /* is it word aligned?? */
511 msg_Err( p_filter, "input buffer is not word aligned" );
512 /* Fix output buffer to be word aligned */
516 out_buf.p_buffer = p_out->p_buffer;
517 out_buf.i_nb_bytes = p_out->i_buffer;
518 out_buf.i_nb_samples = p_out->i_samples;
520 memset( p_out->p_buffer, 0, i_out_size );
521 if( p_filter->p_sys->b_downmix )
523 stereo2mono_downmix( &aout_filter, &in_buf, &out_buf );
524 i_samples = mono( &aout_filter, &out_buf, &in_buf );
528 i_samples = stereo_to_mono( &aout_filter, &out_buf, &in_buf );
531 p_out->i_buffer = out_buf.i_nb_bytes;
532 p_out->i_samples = out_buf.i_nb_samples;
534 block_Release( p_block );
538 /* stereo2mono_downmix - stereo channels into one mono channel.
539 * Code taken from modules/audio_filter/channel_mixer/headphone.c
540 * converted from float into int16_t based downmix
541 * Written by Boris Dorès <babal@via.ecp.fr>
543 static void stereo2mono_downmix( aout_filter_t * p_filter,
544 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
546 filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
548 int i_input_nb = aout_FormatNbChannels( &p_filter->input );
549 int i_output_nb = aout_FormatNbChannels( &p_filter->output );
551 int16_t * p_in = (int16_t*) p_in_buf->p_buffer;
553 uint8_t * p_overflow;
556 size_t i_overflow_size; /* in bytes */
557 size_t i_out_size; /* in bytes */
561 int i_source_channel_offset;
562 int i_dest_channel_offset;
563 unsigned int i_delay;
564 double d_amplitude_factor;
566 /* out buffer characterisitcs */
567 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
568 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * i_output_nb / i_input_nb;
569 p_out = p_out_buf->p_buffer;
570 i_out_size = p_out_buf->i_nb_bytes;
574 /* Slide the overflow buffer */
575 p_overflow = p_sys->p_overflow_buffer;
576 i_overflow_size = p_sys->i_overflow_buffer_size;
578 if ( i_out_size > i_overflow_size )
579 memcpy( p_out, p_overflow, i_overflow_size );
581 memcpy( p_out, p_overflow, i_out_size );
583 p_slide = p_sys->p_overflow_buffer;
584 while( p_slide < p_overflow + i_overflow_size )
586 if( p_slide + i_out_size < p_overflow + i_overflow_size )
588 memset( p_slide, 0, i_out_size );
589 if( p_slide + 2 * i_out_size < p_overflow + i_overflow_size )
590 memcpy( p_slide, p_slide + i_out_size, i_out_size );
592 memcpy( p_slide, p_slide + i_out_size,
593 p_overflow + i_overflow_size - ( p_slide + i_out_size ) );
597 memset( p_slide, 0, p_overflow + i_overflow_size - p_slide );
599 p_slide += i_out_size;
602 /* apply the atomic operations */
603 for( i = 0; i < p_sys->i_nb_atomic_operations; i++ )
605 /* shorter variable names */
606 i_source_channel_offset
607 = p_sys->p_atomic_operations[i].i_source_channel_offset;
608 i_dest_channel_offset
609 = p_sys->p_atomic_operations[i].i_dest_channel_offset;
610 i_delay = p_sys->p_atomic_operations[i].i_delay;
612 = p_sys->p_atomic_operations[i].d_amplitude_factor;
614 if( p_out_buf->i_nb_samples > i_delay )
616 /* current buffer coefficients */
617 for( j = 0; j < p_out_buf->i_nb_samples - i_delay; j++ )
619 ((int16_t*)p_out)[ (i_delay+j)*i_output_nb + i_dest_channel_offset ]
620 += p_in[ j * i_input_nb + i_source_channel_offset ]
621 * d_amplitude_factor;
624 /* overflow buffer coefficients */
625 for( j = 0; j < i_delay; j++ )
627 ((int16_t*)p_overflow)[ j*i_output_nb + i_dest_channel_offset ]
628 += p_in[ (p_out_buf->i_nb_samples - i_delay + j)
629 * i_input_nb + i_source_channel_offset ]
630 * d_amplitude_factor;
635 /* overflow buffer coefficients only */
636 for( j = 0; j < p_out_buf->i_nb_samples; j++ )
638 ((int16_t*)p_overflow)[ (i_delay - p_out_buf->i_nb_samples + j)
639 * i_output_nb + i_dest_channel_offset ]
640 += p_in[ j * i_input_nb + i_source_channel_offset ]
641 * d_amplitude_factor;
648 memset( p_out, 0, i_out_size );
652 /* Simple stereo to mono mixing. */
653 static unsigned int mono( aout_filter_t *p_filter,
654 aout_buffer_t *p_output, aout_buffer_t *p_input )
656 filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
657 int16_t *p_in, *p_out;
658 unsigned int n = 0, r = 0;
660 p_in = (int16_t *) p_input->p_buffer;
661 p_out = (int16_t *) p_output->p_buffer;
663 while( n < (p_input->i_nb_samples * p_sys->i_nb_channels) )
665 p_out[r] = (p_in[n] + p_in[n+1]) >> 1;
672 /* Simple stereo to mono mixing. */
673 static unsigned int stereo_to_mono( aout_filter_t *p_filter,
674 aout_buffer_t *p_output, aout_buffer_t *p_input )
676 filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
677 int16_t *p_in, *p_out;
680 p_in = (int16_t *) p_input->p_buffer;
681 p_out = (int16_t *) p_output->p_buffer;
683 for( n = 0; n < (p_input->i_nb_samples * p_sys->i_nb_channels); n++ )
685 /* Fake real mono. */
686 if( p_sys->i_channel_selected == -1)
688 p_out[n] = p_out[n+1] = (p_in[n] + p_in[n+1]) >> 1;
691 else if( (n % p_sys->i_nb_channels) == (unsigned int) p_sys->i_channel_selected )
693 p_out[n] = p_out[n+1] = p_in[n];