Commit 90e27ff8 authored by Jan Gerber's avatar Jan Gerber
Browse files

add ffmpeg 5.1 patch

parent d37f6cba
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<n;i++) {
- *output1++ = *input++;
- *output2++ = *input++;
+ if (channels == 2) {
+ /* simple stereo to stereo. Input is: l, r */
+ l = input[0];
+ r = input[1];
+ } else if (channels == 6) {
+ /* 5.1 to stereo. l, c, r, ls, rs, sw */
+ int fl,fr,c,rl,rr,lfe;
+ fl = input[0];
+ c = input[1];
+ fr = input[2];
+ rl = input[3];
+ rr = input[4];
+ lfe = input[5];
+
+ l = clip_short(fl + (0.5 * rl) + (0.7 * c));
+ r = clip_short(fr + (0.5 * rr) + (0.7 * c));
+ } else {
+ /* channels must be 3-5, or >= 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));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment