Index: libavcodec/resample.c =================================================================== --- libavcodec/resample.c (revision 11509) +++ libavcodec/resample.c (working copy) @@ -37,6 +37,17 @@ int input_channels, output_channels, filter_channels; }; +/* +*/ +static short clip_short(int v) { + if (v < -32768) + v = -32768; + else if (v > 32767) + v = 32767; + return (short) v; +} + + /* n1: number of samples */ static void stereo_to_mono(short *output, short *input, int n1) { @@ -88,14 +99,43 @@ } } -/* XXX: should use more abstract 'N' channels system */ -static void stereo_split(short *output1, short *output2, short *input, int n) -{ +/* XXX: make this better. channels will always be >= 2. + - Left = front_left + rear_gain * rear_left + center_gain * center + - Right = front_right + rear_gain * rear_right + center_gain * center + where rear_gain is usually around 0.5-1.0 and center_gain is almost always 0.7 (-3 dB) if I recall correctly. */ +static void multi_to_stereo_split(short *output1, short *output2, short *input, int n, int channels) { int i; + short l,r; for(i=0;i= 7. l, c, r, ? */ + l = input[0]; + r = input[2]; + } + + /* output l & r. */ + *output1++ = l; + *output2++ = r; + + /* increment input. */ + input += channels; } } @@ -131,9 +171,9 @@ { ReSampleContext *s; - if ( input_channels > 2) + if ((input_channels > 2) && (input_channels != 6)) { - av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than 2 unsupported.\n"); + av_log(NULL, AV_LOG_ERROR, "Resampling with input channels other than 1,2, or 6 is unsupported.\n"); return NULL; } @@ -205,7 +245,7 @@ } else if (s->output_channels >= 2) { buftmp3[0] = bufout[0]; buftmp3[1] = bufout[1]; - stereo_split(buftmp2[0], buftmp2[1], input, nb_samples); + multi_to_stereo_split(buftmp2[0], buftmp2[1], input, nb_samples, s->input_channels); } else { buftmp3[0] = output; memcpy(buftmp2[0], input, nb_samples*sizeof(short));