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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
29 #include <math.h> /* sqrt */
32 # include <stdint.h> /* int16_t .. */
33 #elif defined(HAVE_INTTYPES_H)
34 # include <inttypes.h> /* int16_t .. */
43 #include <vlc_block.h>
44 #include <vlc_filter.h>
47 /*****************************************************************************
49 *****************************************************************************/
50 static int OpenFilter ( vlc_object_t * );
51 static void CloseFilter ( vlc_object_t * );
53 static block_t *Convert( filter_t *p_filter, block_t *p_block );
55 static unsigned int stereo_to_mono( aout_instance_t *, aout_filter_t *,
56 aout_buffer_t *, aout_buffer_t * );
57 static unsigned int mono( aout_instance_t *, aout_filter_t *,
58 aout_buffer_t *, aout_buffer_t * );
59 static void stereo2mono_downmix( aout_instance_t *, aout_filter_t *,
60 aout_buffer_t *, aout_buffer_t * );
62 /*****************************************************************************
64 *****************************************************************************/
65 struct atomic_operation_t
67 int i_source_channel_offset;
68 int i_dest_channel_offset;
69 unsigned int i_delay;/* in sample unit */
70 double d_amplitude_factor;
77 unsigned int i_nb_channels; /* number of int16_t per sample */
78 int i_channel_selected;
81 size_t i_overflow_buffer_size;/* in bytes */
82 byte_t * p_overflow_buffer;
83 unsigned int i_nb_atomic_operations;
84 struct atomic_operation_t * p_atomic_operations;
87 #define MONO_DOWNMIX_TEXT N_("Use downmix algorithme.")
88 #define MONO_DOWNMIX_LONGTEXT N_("This option selects a stereo to mono " \
89 "downmix algorithm that is used in the headphone channel mixer. It" \
90 "gives the effect of standing in a room full of speakers." )
92 #define MONO_CHANNEL_TEXT N_("Select channel to keep")
93 #define MONO_CHANNEL_LONGTEXT N_("This option silences all other channels " \
94 "except the selected channel. Choose one from (0=left, 1=right " \
95 "2=rear left, 3=rear right, 4=center, 5=left front)")
97 static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5 };
98 static const char *ppsz_pos_descriptions[] =
99 { N_("Left"), N_("Right"), N_("Left rear"), N_("Right rear"), N_("Center"),
102 /* our internal channel order (WG-4 order) */
103 static const uint32_t pi_channels_out[] =
104 { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
105 AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0 };
107 #define MONO_CFG "sout-mono-"
108 /*****************************************************************************
110 *****************************************************************************/
112 set_description( _("Audio filter for stereo to mono conversion") );
113 set_capability( "audio filter2", 0 );
115 add_bool( MONO_CFG "downmix", VLC_FALSE, NULL, MONO_DOWNMIX_TEXT,
116 MONO_DOWNMIX_LONGTEXT, VLC_FALSE );
117 add_integer( MONO_CFG "channel", -1, NULL, MONO_CHANNEL_TEXT,
118 MONO_CHANNEL_LONGTEXT, VLC_FALSE );
119 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
121 set_category( CAT_AUDIO );
122 set_subcategory( SUBCAT_AUDIO_MISC );
123 set_callbacks( OpenFilter, CloseFilter );
124 set_shortname( "Mono" );
127 /* Init() and ComputeChannelOperations() -
128 * Code taken from modules/audio_filter/channel_mixer/headphone.c
129 * converted from float into int16_t based downmix
130 * Written by Boris Dorès <babal@via.ecp.fr>
133 /*****************************************************************************
134 * Init: initialize internal data structures
135 * and computes the needed atomic operations
136 *****************************************************************************/
137 /* x and z represent the coordinates of the virtual speaker
138 * relatively to the center of the listener's head, measured in meters :
147 * rear left rear right
151 static void ComputeChannelOperations( struct filter_sys_t * p_data,
152 unsigned int i_rate, unsigned int i_next_atomic_operation,
153 int i_source_channel_offset, double d_x, double d_z,
154 double d_compensation_length, double d_channel_amplitude_factor )
156 double d_c = 340; /*sound celerity (unit: m/s)*/
157 double d_compensation_delay = (d_compensation_length-0.1) / d_c * i_rate;
160 p_data->p_atomic_operations[i_next_atomic_operation]
161 .i_source_channel_offset = i_source_channel_offset;
162 p_data->p_atomic_operations[i_next_atomic_operation]
163 .i_dest_channel_offset = 0;/* left */
164 p_data->p_atomic_operations[i_next_atomic_operation]
165 .i_delay = (int)( sqrt( (-0.1-d_x)*(-0.1-d_x) + (0-d_z)*(0-d_z) )
166 / d_c * i_rate - d_compensation_delay );
169 p_data->p_atomic_operations[i_next_atomic_operation]
170 .d_amplitude_factor = d_channel_amplitude_factor * 1.1 / 2;
174 p_data->p_atomic_operations[i_next_atomic_operation]
175 .d_amplitude_factor = d_channel_amplitude_factor * 0.9 / 2;
179 p_data->p_atomic_operations[i_next_atomic_operation]
180 .d_amplitude_factor = d_channel_amplitude_factor / 2;
184 p_data->p_atomic_operations[i_next_atomic_operation + 1]
185 .i_source_channel_offset = i_source_channel_offset;
186 p_data->p_atomic_operations[i_next_atomic_operation + 1]
187 .i_dest_channel_offset = 1;/* right */
188 p_data->p_atomic_operations[i_next_atomic_operation + 1]
189 .i_delay = (int)( sqrt( (0.1-d_x)*(0.1-d_x) + (0-d_z)*(0-d_z) )
190 / d_c * i_rate - d_compensation_delay );
193 p_data->p_atomic_operations[i_next_atomic_operation + 1]
194 .d_amplitude_factor = d_channel_amplitude_factor * 0.9 / 2;
198 p_data->p_atomic_operations[i_next_atomic_operation + 1]
199 .d_amplitude_factor = d_channel_amplitude_factor * 1.1 / 2;
203 p_data->p_atomic_operations[i_next_atomic_operation + 1]
204 .d_amplitude_factor = d_channel_amplitude_factor / 2;
208 static int Init( vlc_object_t *p_this, struct filter_sys_t * p_data,
209 unsigned int i_nb_channels, uint32_t i_physical_channels,
210 unsigned int i_rate )
212 double d_x = config_GetInt( p_this, "headphone-dim" );
214 double d_z_rear = -d_x/3;
216 unsigned int i_next_atomic_operation;
217 int i_source_channel_offset;
222 msg_Dbg( p_this, "passing a null pointer as argument" );
226 if( config_GetInt( p_this, "headphone-compensate" ) )
228 /* minimal distance to any speaker */
229 if( i_physical_channels & AOUT_CHAN_REARCENTER )
239 /* Number of elementary operations */
240 p_data->i_nb_atomic_operations = i_nb_channels * 2;
241 if( i_physical_channels & AOUT_CHAN_CENTER )
243 p_data->i_nb_atomic_operations += 2;
245 p_data->p_atomic_operations = malloc( sizeof(struct atomic_operation_t)
246 * p_data->i_nb_atomic_operations );
247 if( p_data->p_atomic_operations == NULL )
249 msg_Err( p_this, "out of memory" );
253 /* For each virtual speaker, computes elementary wave propagation time
255 i_next_atomic_operation = 0;
256 i_source_channel_offset = 0;
257 if( i_physical_channels & AOUT_CHAN_LEFT )
259 ComputeChannelOperations( p_data , i_rate
260 , i_next_atomic_operation , i_source_channel_offset
261 , -d_x , d_z , d_min , 2.0 / i_nb_channels );
262 i_next_atomic_operation += 2;
263 i_source_channel_offset++;
265 if( i_physical_channels & AOUT_CHAN_RIGHT )
267 ComputeChannelOperations( p_data , i_rate
268 , i_next_atomic_operation , i_source_channel_offset
269 , d_x , d_z , d_min , 2.0 / i_nb_channels );
270 i_next_atomic_operation += 2;
271 i_source_channel_offset++;
273 if( i_physical_channels & AOUT_CHAN_MIDDLELEFT )
275 ComputeChannelOperations( p_data , i_rate
276 , i_next_atomic_operation , i_source_channel_offset
277 , -d_x , 0 , d_min , 1.5 / i_nb_channels );
278 i_next_atomic_operation += 2;
279 i_source_channel_offset++;
281 if( i_physical_channels & AOUT_CHAN_MIDDLERIGHT )
283 ComputeChannelOperations( p_data , i_rate
284 , i_next_atomic_operation , i_source_channel_offset
285 , d_x , 0 , d_min , 1.5 / i_nb_channels );
286 i_next_atomic_operation += 2;
287 i_source_channel_offset++;
289 if( i_physical_channels & AOUT_CHAN_REARLEFT )
291 ComputeChannelOperations( p_data , i_rate
292 , i_next_atomic_operation , i_source_channel_offset
293 , -d_x , d_z_rear , d_min , 1.5 / i_nb_channels );
294 i_next_atomic_operation += 2;
295 i_source_channel_offset++;
297 if( i_physical_channels & AOUT_CHAN_REARRIGHT )
299 ComputeChannelOperations( p_data , i_rate
300 , i_next_atomic_operation , i_source_channel_offset
301 , d_x , d_z_rear , d_min , 1.5 / i_nb_channels );
302 i_next_atomic_operation += 2;
303 i_source_channel_offset++;
305 if( i_physical_channels & AOUT_CHAN_REARCENTER )
307 ComputeChannelOperations( p_data , i_rate
308 , i_next_atomic_operation , i_source_channel_offset
309 , 0 , -d_z , d_min , 1.5 / i_nb_channels );
310 i_next_atomic_operation += 2;
311 i_source_channel_offset++;
313 if( i_physical_channels & AOUT_CHAN_CENTER )
315 /* having two center channels increases the spatialization effect */
316 ComputeChannelOperations( p_data , i_rate
317 , i_next_atomic_operation , i_source_channel_offset
318 , d_x / 5.0 , d_z , d_min , 0.75 / i_nb_channels );
319 i_next_atomic_operation += 2;
320 ComputeChannelOperations( p_data , i_rate
321 , i_next_atomic_operation , i_source_channel_offset
322 , -d_x / 5.0 , d_z , d_min , 0.75 / i_nb_channels );
323 i_next_atomic_operation += 2;
324 i_source_channel_offset++;
326 if( i_physical_channels & AOUT_CHAN_LFE )
328 ComputeChannelOperations( p_data , i_rate
329 , i_next_atomic_operation , i_source_channel_offset
330 , 0 , d_z_rear , d_min , 5.0 / i_nb_channels );
331 i_next_atomic_operation += 2;
332 i_source_channel_offset++;
335 /* Initialize the overflow buffer
336 * we need it because the process induce a delay in the samples */
337 p_data->i_overflow_buffer_size = 0;
338 for( i = 0 ; i < p_data->i_nb_atomic_operations ; i++ )
340 if( p_data->i_overflow_buffer_size
341 < p_data->p_atomic_operations[i].i_delay * 2 * sizeof (int16_t) )
343 p_data->i_overflow_buffer_size
344 = p_data->p_atomic_operations[i].i_delay * 2 * sizeof (int16_t);
347 p_data->p_overflow_buffer = malloc( p_data->i_overflow_buffer_size );
348 if( p_data->p_atomic_operations == NULL )
350 msg_Err( p_this, "out of memory" );
353 memset( p_data->p_overflow_buffer, 0, p_data->i_overflow_buffer_size );
359 /*****************************************************************************
361 *****************************************************************************/
362 static int OpenFilter( vlc_object_t *p_this )
364 filter_t * p_filter = (filter_t *)p_this;
365 filter_sys_t *p_sys = NULL;
367 if( aout_FormatNbChannels( &(p_filter->fmt_in.audio) ) == 1 )
369 msg_Dbg( p_filter, "filter discarded (incompatible format)" );
373 if( (p_filter->fmt_in.i_codec != AOUT_FMT_S16_NE) ||
374 (p_filter->fmt_out.i_codec != AOUT_FMT_S16_NE) )
376 msg_Err( p_this, "filter discarded (invalid format)" );
380 if( (p_filter->fmt_in.audio.i_format != p_filter->fmt_out.audio.i_format) &&
381 (p_filter->fmt_in.audio.i_rate != p_filter->fmt_out.audio.i_rate) &&
382 (p_filter->fmt_in.audio.i_format != AOUT_FMT_S16_NE) &&
383 (p_filter->fmt_out.audio.i_format != AOUT_FMT_S16_NE) &&
384 (p_filter->fmt_in.audio.i_bitspersample !=
385 p_filter->fmt_out.audio.i_bitspersample))
387 msg_Err( p_this, "couldn't load mono filter" );
391 /* Allocate the memory needed to store the module's structure */
392 p_sys = p_filter->p_sys = malloc( sizeof(filter_sys_t) );
395 msg_Err( p_filter, "out of memory" );
399 var_Create( p_this, MONO_CFG "downmix",
400 VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
401 p_sys->b_downmix = var_GetBool( p_this, MONO_CFG "downmix" );
403 var_Create( p_this, MONO_CFG "channel",
404 VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
405 p_sys->i_channel_selected =
406 (unsigned int) var_GetInteger( p_this, MONO_CFG "channel" );
408 if( p_sys->b_downmix )
410 msg_Dbg( p_this, "using stereo to mono downmix" );
411 p_filter->fmt_out.audio.i_physical_channels = AOUT_CHAN_CENTER;
412 p_filter->fmt_out.audio.i_channels = 1;
416 msg_Dbg( p_this, "using pseudo mono" );
417 p_filter->fmt_out.audio.i_physical_channels =
418 (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT);
419 p_filter->fmt_out.audio.i_channels = 2;
422 p_filter->fmt_out.audio.i_rate = p_filter->fmt_in.audio.i_rate;
423 p_filter->fmt_out.audio.i_format = p_filter->fmt_out.i_codec;
425 p_sys->i_nb_channels = aout_FormatNbChannels( &(p_filter->fmt_in.audio) );
426 p_sys->i_bitspersample = p_filter->fmt_out.audio.i_bitspersample;
428 p_sys->i_overflow_buffer_size = 0;
429 p_sys->p_overflow_buffer = NULL;
430 p_sys->i_nb_atomic_operations = 0;
431 p_sys->p_atomic_operations = NULL;
433 if( Init( VLC_OBJECT(p_filter), p_filter->p_sys,
434 aout_FormatNbChannels( &p_filter->fmt_in.audio ),
435 p_filter->fmt_in.audio.i_physical_channels,
436 p_filter->fmt_in.audio.i_rate ) < 0 )
441 p_filter->pf_audio_filter = Convert;
443 msg_Dbg( p_this, "%4.4s->%4.4s, channels %d->%d, bits per sample: %i->%i",
444 (char *)&p_filter->fmt_in.i_codec,
445 (char *)&p_filter->fmt_out.i_codec,
446 p_filter->fmt_in.audio.i_physical_channels,
447 p_filter->fmt_out.audio.i_physical_channels,
448 p_filter->fmt_in.audio.i_bitspersample,
449 p_filter->fmt_out.audio.i_bitspersample );
454 /*****************************************************************************
456 *****************************************************************************/
457 static void CloseFilter( vlc_object_t *p_this)
459 filter_t *p_filter = (filter_t *) p_this;
460 filter_sys_t *p_sys = p_filter->p_sys;
462 var_Destroy( p_this, MONO_CFG "channel" );
463 var_Destroy( p_this, MONO_CFG "downmix" );
467 /*****************************************************************************
469 *****************************************************************************/
470 static block_t *Convert( filter_t *p_filter, block_t *p_block )
472 aout_filter_t aout_filter;
473 aout_buffer_t in_buf, out_buf;
474 block_t *p_out = NULL;
475 unsigned int i_samples;
478 if( !p_block || !p_block->i_samples )
481 p_block->pf_release( p_block );
485 i_out_size = p_block->i_samples * p_filter->p_sys->i_bitspersample/8 *
486 aout_FormatNbChannels( &(p_filter->fmt_out.audio) );
488 p_out = p_filter->pf_audio_buffer_new( p_filter, i_out_size );
491 msg_Warn( p_filter, "can't get output buffer" );
492 p_block->pf_release( p_block );
495 p_out->i_samples = (p_block->i_samples / p_filter->p_sys->i_nb_channels) *
496 aout_FormatNbChannels( &(p_filter->fmt_out.audio) );
497 p_out->i_dts = p_block->i_dts;
498 p_out->i_pts = p_block->i_pts;
499 p_out->i_length = p_block->i_length;
501 aout_filter.p_sys = (struct aout_filter_sys_t *)p_filter->p_sys;
502 aout_filter.input = p_filter->fmt_in.audio;
503 aout_filter.input.i_format = p_filter->fmt_in.i_codec;
504 aout_filter.output = p_filter->fmt_out.audio;
505 aout_filter.output.i_format = p_filter->fmt_out.i_codec;
507 in_buf.p_buffer = p_block->p_buffer;
508 in_buf.i_nb_bytes = p_block->i_buffer;
509 in_buf.i_nb_samples = p_block->i_samples;
512 unsigned int i_in_size = in_buf.i_nb_samples * (p_filter->p_sys->i_bitspersample/8) *
513 aout_FormatNbChannels( &(p_filter->fmt_in.audio) );
514 if( (in_buf.i_nb_bytes != i_in_size) && ((i_in_size % 32) != 0) ) /* is it word aligned?? */
516 msg_Err( p_filter, "input buffer is not word aligned" );
517 /* Fix output buffer to be word aligned */
521 out_buf.p_buffer = p_out->p_buffer;
522 out_buf.i_nb_bytes = p_out->i_buffer;
523 out_buf.i_nb_samples = p_out->i_samples;
525 memset( p_out->p_buffer, 0, i_out_size );
526 if( p_filter->p_sys->b_downmix )
528 stereo2mono_downmix( (aout_instance_t *)p_filter, &aout_filter,
530 i_samples = mono( (aout_instance_t *)p_filter, &aout_filter,
535 i_samples = stereo_to_mono( (aout_instance_t *)p_filter, &aout_filter,
539 p_out->i_buffer = out_buf.i_nb_bytes;
540 p_out->i_samples = out_buf.i_nb_samples;
542 p_block->pf_release( p_block );
546 /* stereo2mono_downmix - stereo channels into one mono channel.
547 * Code taken from modules/audio_filter/channel_mixer/headphone.c
548 * converted from float into int16_t based downmix
549 * Written by Boris Dorès <babal@via.ecp.fr>
551 static void stereo2mono_downmix( aout_instance_t * p_aout, aout_filter_t * p_filter,
552 aout_buffer_t * p_in_buf, aout_buffer_t * p_out_buf )
554 filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
556 int i_input_nb = aout_FormatNbChannels( &p_filter->input );
557 int i_output_nb = aout_FormatNbChannels( &p_filter->output );
559 int16_t * p_in = (int16_t*) p_in_buf->p_buffer;
564 size_t i_overflow_size; /* in bytes */
565 size_t i_out_size; /* in bytes */
569 int i_source_channel_offset;
570 int i_dest_channel_offset;
571 unsigned int i_delay;
572 double d_amplitude_factor;
574 /* out buffer characterisitcs */
575 p_out_buf->i_nb_samples = p_in_buf->i_nb_samples;
576 p_out_buf->i_nb_bytes = p_in_buf->i_nb_bytes * i_output_nb / i_input_nb;
577 p_out = p_out_buf->p_buffer;
578 i_out_size = p_out_buf->i_nb_bytes;
582 /* Slide the overflow buffer */
583 p_overflow = p_sys->p_overflow_buffer;
584 i_overflow_size = p_sys->i_overflow_buffer_size;
586 if ( i_out_size > i_overflow_size )
587 memcpy( p_out, p_overflow, i_overflow_size );
589 memcpy( p_out, p_overflow, i_out_size );
591 p_slide = p_sys->p_overflow_buffer;
592 while( p_slide < p_overflow + i_overflow_size )
594 if( p_slide + i_out_size < p_overflow + i_overflow_size )
596 memset( p_slide, 0, i_out_size );
597 if( p_slide + 2 * i_out_size < p_overflow + i_overflow_size )
598 memcpy( p_slide, p_slide + i_out_size, i_out_size );
600 memcpy( p_slide, p_slide + i_out_size,
601 p_overflow + i_overflow_size - ( p_slide + i_out_size ) );
605 memset( p_slide, 0, p_overflow + i_overflow_size - p_slide );
607 p_slide += i_out_size;
610 /* apply the atomic operations */
611 for( i = 0; i < p_sys->i_nb_atomic_operations; i++ )
613 /* shorter variable names */
614 i_source_channel_offset
615 = p_sys->p_atomic_operations[i].i_source_channel_offset;
616 i_dest_channel_offset
617 = p_sys->p_atomic_operations[i].i_dest_channel_offset;
618 i_delay = p_sys->p_atomic_operations[i].i_delay;
620 = p_sys->p_atomic_operations[i].d_amplitude_factor;
622 if( p_out_buf->i_nb_samples > i_delay )
624 /* current buffer coefficients */
625 for( j = 0; j < p_out_buf->i_nb_samples - i_delay; j++ )
627 ((int16_t*)p_out)[ (i_delay+j)*i_output_nb + i_dest_channel_offset ]
628 += p_in[ j * i_input_nb + i_source_channel_offset ]
629 * d_amplitude_factor;
632 /* overflow buffer coefficients */
633 for( j = 0; j < i_delay; j++ )
635 ((int16_t*)p_overflow)[ j*i_output_nb + i_dest_channel_offset ]
636 += p_in[ (p_out_buf->i_nb_samples - i_delay + j)
637 * i_input_nb + i_source_channel_offset ]
638 * d_amplitude_factor;
643 /* overflow buffer coefficients only */
644 for( j = 0; j < p_out_buf->i_nb_samples; j++ )
646 ((int16_t*)p_overflow)[ (i_delay - p_out_buf->i_nb_samples + j)
647 * i_output_nb + i_dest_channel_offset ]
648 += p_in[ j * i_input_nb + i_source_channel_offset ]
649 * d_amplitude_factor;
656 memset( p_out, 0, i_out_size );
660 /* Simple stereo to mono mixing. */
661 static unsigned int mono( aout_instance_t * p_aout, aout_filter_t *p_filter,
662 aout_buffer_t *p_output, aout_buffer_t *p_input )
664 filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
665 int16_t *p_in, *p_out;
666 unsigned int n = 0, r = 0;
668 p_in = (int16_t *) p_input->p_buffer;
669 p_out = (int16_t *) p_output->p_buffer;
671 while( n < (p_input->i_nb_samples * p_sys->i_nb_channels) )
673 p_out[r] = (p_in[n] + p_in[n+1]) >> 1;
680 /* Simple stereo to mono mixing. */
681 static unsigned int stereo_to_mono( aout_instance_t * p_aout, aout_filter_t *p_filter,
682 aout_buffer_t *p_output, aout_buffer_t *p_input )
684 filter_sys_t *p_sys = (filter_sys_t *)p_filter->p_sys;
685 int16_t *p_in, *p_out;
688 p_in = (int16_t *) p_input->p_buffer;
689 p_out = (int16_t *) p_output->p_buffer;
691 for( n = 0; n < (p_input->i_nb_samples * p_sys->i_nb_channels); n++ )
693 /* Fake real mono. */
694 if( p_sys->i_channel_selected == -1)
696 p_out[n] = p_out[n+1] = (p_in[n] + p_in[n+1]) >> 1;
699 else if( (n % p_sys->i_nb_channels) == (unsigned int) p_sys->i_channel_selected )
701 p_out[n] = p_out[n+1] = p_in[n];