mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
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.
This commit is contained in:
parent
01a73d6cef
commit
02260ccc3b
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user