annotate resample.c @ 5431:192360fa9b06 libavcodec

get rid of a useless variable
author michael
date Tue, 31 Jul 2007 21:00:17 +0000
parents 45d083bbbbe7
children f64d8abf92e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
5355
45d083bbbbe7 typo fixes
diego
parents: 4712
diff changeset
2 * samplerate conversion for both audio and video
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
3 * Copyright (c) 2000 Fabrice Bellard.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
15 * Lesser General Public License for more details.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
16 *
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3036
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
21
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
22 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
23 * @file resample.c
5355
45d083bbbbe7 typo fixes
diego
parents: 4712
diff changeset
24 * samplerate conversion for both audio and video
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
25 */
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
26
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
27 #include "avcodec.h"
1125
0980ae063f4e restoring OS/2 compatibility patch by ("Slavik Gnatenko" <miracle9 at newmail dot ru>)
michaelni
parents: 1106
diff changeset
28
2082
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
29 struct AVResampleContext;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
30
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 struct ReSampleContext {
2082
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
32 struct AVResampleContext *resample_context;
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
33 short *temp[2];
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
34 int temp_len;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
35 float ratio;
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 /* channel convert */
986e461dc072 Initial revision
glantau
parents:
diff changeset
37 int input_channels, output_channels, filter_channels;
986e461dc072 Initial revision
glantau
parents:
diff changeset
38 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
39
986e461dc072 Initial revision
glantau
parents:
diff changeset
40 /* n1: number of samples */
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 static void stereo_to_mono(short *output, short *input, int n1)
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 short *p, *q;
986e461dc072 Initial revision
glantau
parents:
diff changeset
44 int n = n1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
45
986e461dc072 Initial revision
glantau
parents:
diff changeset
46 p = input;
986e461dc072 Initial revision
glantau
parents:
diff changeset
47 q = output;
986e461dc072 Initial revision
glantau
parents:
diff changeset
48 while (n >= 4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
49 q[0] = (p[0] + p[1]) >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 q[1] = (p[2] + p[3]) >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 q[2] = (p[4] + p[5]) >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 q[3] = (p[6] + p[7]) >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 q += 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
54 p += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 n -= 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
56 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 while (n > 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
58 q[0] = (p[0] + p[1]) >> 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 q++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 p += 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 n--;
986e461dc072 Initial revision
glantau
parents:
diff changeset
62 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
64
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 /* n1: number of samples */
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 static void mono_to_stereo(short *output, short *input, int n1)
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
68 short *p, *q;
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 int n = n1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
70 int v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
71
986e461dc072 Initial revision
glantau
parents:
diff changeset
72 p = input;
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 q = output;
986e461dc072 Initial revision
glantau
parents:
diff changeset
74 while (n >= 4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 v = p[0]; q[0] = v; q[1] = v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 v = p[1]; q[2] = v; q[3] = v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 v = p[2]; q[4] = v; q[5] = v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
78 v = p[3]; q[6] = v; q[7] = v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
79 q += 8;
986e461dc072 Initial revision
glantau
parents:
diff changeset
80 p += 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 n -= 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
82 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 while (n > 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 v = p[0]; q[0] = v; q[1] = v;
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 q += 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 p += 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 n--;
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
90
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 /* XXX: should use more abstract 'N' channels system */
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 static void stereo_split(short *output1, short *output2, short *input, int n)
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 int i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
95
986e461dc072 Initial revision
glantau
parents:
diff changeset
96 for(i=0;i<n;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 *output1++ = *input++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 *output2++ = *input++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
101
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 static void stereo_mux(short *output, short *input1, short *input2, int n)
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 int i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
105
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 for(i=0;i<n;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 *output++ = *input1++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 *output++ = *input2++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
109 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
110 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
111
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
112 static void ac3_5p1_mux(short *output, short *input1, short *input2, int n)
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
113 {
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
114 int i;
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
115 short l,r;
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
116
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
117 for(i=0;i<n;i++) {
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
118 l=*input1++;
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
119 r=*input2++;
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
120 *output++ = l; /* left */
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
121 *output++ = (l/2)+(r/2); /* center */
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
122 *output++ = r; /* right */
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
123 *output++ = 0; /* left surround */
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
124 *output++ = 0; /* right surroud */
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
125 *output++ = 0; /* low freq */
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
126 }
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
127 }
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
128
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
129 ReSampleContext *audio_resample_init(int output_channels, int input_channels,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
130 int output_rate, int input_rate)
986e461dc072 Initial revision
glantau
parents:
diff changeset
131 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
132 ReSampleContext *s;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
133
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
134 if ( input_channels > 2)
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
135 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
136 av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than 2 unsupported.");
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
137 return NULL;
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
138 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
139
986e461dc072 Initial revision
glantau
parents:
diff changeset
140 s = av_mallocz(sizeof(ReSampleContext));
986e461dc072 Initial revision
glantau
parents:
diff changeset
141 if (!s)
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
142 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
143 av_log(NULL, AV_LOG_ERROR, "Can't allocate memory for resample context.");
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
144 return NULL;
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
145 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
146
986e461dc072 Initial revision
glantau
parents:
diff changeset
147 s->ratio = (float)output_rate / (float)input_rate;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
148
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
149 s->input_channels = input_channels;
986e461dc072 Initial revision
glantau
parents:
diff changeset
150 s->output_channels = output_channels;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
151
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
152 s->filter_channels = s->input_channels;
986e461dc072 Initial revision
glantau
parents:
diff changeset
153 if (s->output_channels < s->filter_channels)
986e461dc072 Initial revision
glantau
parents:
diff changeset
154 s->filter_channels = s->output_channels;
986e461dc072 Initial revision
glantau
parents:
diff changeset
155
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
156 /*
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
157 * ac3 output is the only case where filter_channels could be greater than 2.
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
158 * input channels can't be greater than 2, so resample the 2 channels and then
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
159 * expand to 6 channels after the resampling.
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
160 */
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
161 if(s->filter_channels>2)
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
162 s->filter_channels = 2;
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
163
4712
5c0c96d437f2 set more reasonable cutoff for audio rate conversion
michael
parents: 3947
diff changeset
164 #define TAPS 16
5c0c96d437f2 set more reasonable cutoff for audio rate conversion
michael
parents: 3947
diff changeset
165 s->resample_context= av_resample_init(output_rate, input_rate, TAPS, 10, 0, 0.8);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
166
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
167 return s;
986e461dc072 Initial revision
glantau
parents:
diff changeset
168 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
169
986e461dc072 Initial revision
glantau
parents:
diff changeset
170 /* resample audio. 'nb_samples' is the number of input samples */
986e461dc072 Initial revision
glantau
parents:
diff changeset
171 /* XXX: optimize it ! */
986e461dc072 Initial revision
glantau
parents:
diff changeset
172 int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
986e461dc072 Initial revision
glantau
parents:
diff changeset
173 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
174 int i, nb_samples1;
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
175 short *bufin[2];
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
176 short *bufout[2];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
177 short *buftmp2[2], *buftmp3[2];
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
178 int lenout;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
179
2109
84637c6ca74e various resampling fixes
michael
parents: 2084
diff changeset
180 if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
181 /* nothing to do */
986e461dc072 Initial revision
glantau
parents:
diff changeset
182 memcpy(output, input, nb_samples * s->input_channels * sizeof(short));
986e461dc072 Initial revision
glantau
parents:
diff changeset
183 return nb_samples;
986e461dc072 Initial revision
glantau
parents:
diff changeset
184 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
185
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
186 /* XXX: move those malloc to resample init code */
2082
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
187 for(i=0; i<s->filter_channels; i++){
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
188 bufin[i]= (short*) av_malloc( (nb_samples + s->temp_len) * sizeof(short) );
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
189 memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short));
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
190 buftmp2[i] = bufin[i] + s->temp_len;
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
191 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2522
diff changeset
192
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
193 /* make some zoom to avoid round pb */
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
194 lenout= (int)(nb_samples * s->ratio) + 16;
396
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 373
diff changeset
195 bufout[0]= (short*) av_malloc( lenout * sizeof(short) );
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 373
diff changeset
196 bufout[1]= (short*) av_malloc( lenout * sizeof(short) );
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
197
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
198 if (s->input_channels == 2 &&
986e461dc072 Initial revision
glantau
parents:
diff changeset
199 s->output_channels == 1) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
200 buftmp3[0] = output;
986e461dc072 Initial revision
glantau
parents:
diff changeset
201 stereo_to_mono(buftmp2[0], input, nb_samples);
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
202 } else if (s->output_channels >= 2 && s->input_channels == 1) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
203 buftmp3[0] = bufout[0];
2082
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
204 memcpy(buftmp2[0], input, nb_samples*sizeof(short));
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
205 } else if (s->output_channels >= 2) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
206 buftmp3[0] = bufout[0];
986e461dc072 Initial revision
glantau
parents:
diff changeset
207 buftmp3[1] = bufout[1];
986e461dc072 Initial revision
glantau
parents:
diff changeset
208 stereo_split(buftmp2[0], buftmp2[1], input, nb_samples);
986e461dc072 Initial revision
glantau
parents:
diff changeset
209 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
210 buftmp3[0] = output;
2082
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
211 memcpy(buftmp2[0], input, nb_samples*sizeof(short));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
212 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
213
2082
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
214 nb_samples += s->temp_len;
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
215
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
216 /* resample each channel */
986e461dc072 Initial revision
glantau
parents:
diff changeset
217 nb_samples1 = 0; /* avoid warning */
986e461dc072 Initial revision
glantau
parents:
diff changeset
218 for(i=0;i<s->filter_channels;i++) {
2082
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
219 int consumed;
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
220 int is_last= i+1 == s->filter_channels;
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
221
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
222 nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last);
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
223 s->temp_len= nb_samples - consumed;
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
224 s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short));
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
225 memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
226 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
227
986e461dc072 Initial revision
glantau
parents:
diff changeset
228 if (s->output_channels == 2 && s->input_channels == 1) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
229 mono_to_stereo(output, buftmp3[0], nb_samples1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
230 } else if (s->output_channels == 2) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
231 stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
1408
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
232 } else if (s->output_channels == 6) {
4d67eb341a0c AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
michaelni
parents: 1128
diff changeset
233 ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
234 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
235
2084
michael
parents: 2082
diff changeset
236 for(i=0; i<s->filter_channels; i++)
michael
parents: 2082
diff changeset
237 av_free(bufin[i]);
64
5aa6292a1660 win32 fixes
glantau
parents: 0
diff changeset
238
396
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 373
diff changeset
239 av_free(bufout[0]);
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 373
diff changeset
240 av_free(bufout[1]);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
241 return nb_samples1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
242 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
243
986e461dc072 Initial revision
glantau
parents:
diff changeset
244 void audio_resample_close(ReSampleContext *s)
986e461dc072 Initial revision
glantau
parents:
diff changeset
245 {
2082
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
246 av_resample_close(s->resample_context);
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
247 av_freep(&s->temp[0]);
3dc9bbe1b152 polyphase kaiser windowed sinc and blackman nuttall windowed sinc audio resample filters
michael
parents: 1598
diff changeset
248 av_freep(&s->temp[1]);
396
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 373
diff changeset
249 av_free(s);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
250 }