summaryrefslogtreecommitdiff
path: root/libavcodec/resample.c
diff options
context:
space:
mode:
authorjan gerber <j@v2v.cc>2011-05-23 17:22:02 +0200
committerMichael Niedermayer <michaelni@gmx.at>2011-05-23 17:22:02 +0200
commit02260ccc3b7f8b88c11af4739252f5c5f97fa6e7 (patch)
tree03986041d02fff905c1008679b36b88e4b6def7b /libavcodec/resample.c
parent01a73d6cef70dfa90fdf79f7afd55b817b4c9342 (diff)
add 5.1 to stereo downmix to resample.c
this is based on previous 6to2channel-resample.patch from ffmpeg2theora but updated to work with trunk and using av_clip_int16.
Diffstat (limited to 'libavcodec/resample.c')
-rw-r--r--libavcodec/resample.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/libavcodec/resample.c b/libavcodec/resample.c
index 9e6defefdf..8c4eebe3c4 100644
--- a/libavcodec/resample.c
+++ b/libavcodec/resample.c
@@ -108,6 +108,39 @@ static void mono_to_stereo(short *output, short *input, int n1)
}
}
+/*
+5.1 to stereo input: [fl, fr, c, lfe, rl, rr]
+- 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)
+*/
+static void surround_to_stereo(short **output, short *input, int channels, int samples)
+{
+ int i;
+ short l, r;
+
+ for (i = 0; i < samples; i++) {
+ int fl,fr,c,rl,rr,lfe;
+ fl = input[0];
+ fr = input[1];
+ c = input[2];
+ lfe = input[3];
+ rl = input[4];
+ rr = input[5];
+
+ l = av_clip_int16(fl + (0.5 * rl) + (0.7 * c));
+ r = av_clip_int16(fr + (0.5 * rr) + (0.7 * c));
+
+ /* output l & r. */
+ *output[0]++ = l;
+ *output[1]++ = r;
+
+ /* increment input. */
+ input += channels;
+ }
+}
+
static void deinterleave(short **output, short *input, int channels, int samples)
{
int i, j;
@@ -301,6 +334,10 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
} else if (s->output_channels >= 2 && s->input_channels == 1) {
buftmp3[0] = bufout[0];
memcpy(buftmp2[0], input, nb_samples * sizeof(short));
+ } else if (s->input_channels == 6 && s->output_channels ==2) {
+ buftmp3[0] = bufout[0];
+ buftmp3[1] = bufout[1];
+ surround_to_stereo(buftmp2, input, s->input_channels, nb_samples);
} else if (s->output_channels >= s->input_channels && s->input_channels >= 2) {
for (i = 0; i < s->input_channels; i++) {
buftmp3[i] = bufout[i];
@@ -330,7 +367,8 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_sampl
mono_to_stereo(output, buftmp3[0], nb_samples1);
} else if (s->output_channels == 6 && s->input_channels == 2) {
ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
- } else if (s->output_channels == s->input_channels && s->input_channels >= 2) {
+ } else if ((s->output_channels == s->input_channels && s->input_channels >= 2) ||
+ (s->output_channels == 2 && s->input_channels == 6)) {
interleave(output, buftmp3, s->output_channels, nb_samples1);
}