Mercurial > libavcodec.hg
comparison resample.c @ 1408:4d67eb341a0c libavcodec
AC3 encoding patch ba (Ross Martin <ffmpeg at ross dot interwrx dot com>)
| author | michaelni |
|---|---|
| date | Wed, 20 Aug 2003 07:57:00 +0000 |
| parents | 300961b1ef4f |
| children | daa70b33fc44 |
comparison
equal
deleted
inserted
replaced
| 1407:69f4f4fb8a50 | 1408:4d67eb341a0c |
|---|---|
| 192 *output++ = *input1++; | 192 *output++ = *input1++; |
| 193 *output++ = *input2++; | 193 *output++ = *input2++; |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 static void ac3_5p1_mux(short *output, short *input1, short *input2, int n) | |
| 198 { | |
| 199 int i; | |
| 200 short l,r; | |
| 201 | |
| 202 for(i=0;i<n;i++) { | |
| 203 l=*input1++; | |
| 204 r=*input2++; | |
| 205 *output++ = l; /* left */ | |
| 206 *output++ = (l/2)+(r/2); /* center */ | |
| 207 *output++ = r; /* right */ | |
| 208 *output++ = 0; /* left surround */ | |
| 209 *output++ = 0; /* right surroud */ | |
| 210 *output++ = 0; /* low freq */ | |
| 211 } | |
| 212 } | |
| 213 | |
| 197 static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples) | 214 static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples) |
| 198 { | 215 { |
| 199 short *buf1; | 216 short *buf1; |
| 200 short *buftmp; | 217 short *buftmp; |
| 201 | 218 |
| 223 int output_rate, int input_rate) | 240 int output_rate, int input_rate) |
| 224 { | 241 { |
| 225 ReSampleContext *s; | 242 ReSampleContext *s; |
| 226 int i; | 243 int i; |
| 227 | 244 |
| 228 if (output_channels > 2 || input_channels > 2) | 245 if ( input_channels > 2) |
| 229 return NULL; | 246 { |
| 247 printf("Resampling with input channels greater than 2 unsupported."); | |
| 248 return NULL; | |
| 249 } | |
| 230 | 250 |
| 231 s = av_mallocz(sizeof(ReSampleContext)); | 251 s = av_mallocz(sizeof(ReSampleContext)); |
| 232 if (!s) | 252 if (!s) |
| 233 return NULL; | 253 { |
| 254 printf("Can't allocate memory for resample context."); | |
| 255 return NULL; | |
| 256 } | |
| 234 | 257 |
| 235 s->ratio = (float)output_rate / (float)input_rate; | 258 s->ratio = (float)output_rate / (float)input_rate; |
| 236 | 259 |
| 237 s->input_channels = input_channels; | 260 s->input_channels = input_channels; |
| 238 s->output_channels = output_channels; | 261 s->output_channels = output_channels; |
| 239 | 262 |
| 240 s->filter_channels = s->input_channels; | 263 s->filter_channels = s->input_channels; |
| 241 if (s->output_channels < s->filter_channels) | 264 if (s->output_channels < s->filter_channels) |
| 242 s->filter_channels = s->output_channels; | 265 s->filter_channels = s->output_channels; |
| 243 | 266 |
| 267 /* | |
| 268 * ac3 output is the only case where filter_channels could be greater than 2. | |
| 269 * input channels can't be greater than 2, so resample the 2 channels and then | |
| 270 * expand to 6 channels after the resampling. | |
| 271 */ | |
| 272 if(s->filter_channels>2) | |
| 273 s->filter_channels = 2; | |
| 274 | |
| 244 for(i=0;i<s->filter_channels;i++) { | 275 for(i=0;i<s->filter_channels;i++) { |
| 245 init_mono_resample(&s->channel_ctx[i], s->ratio); | 276 init_mono_resample(&s->channel_ctx[i], s->ratio); |
| 246 } | 277 } |
| 247 return s; | 278 return s; |
| 248 } | 279 } |
| 277 if (s->input_channels == 2 && | 308 if (s->input_channels == 2 && |
| 278 s->output_channels == 1) { | 309 s->output_channels == 1) { |
| 279 buftmp2[0] = bufin[0]; | 310 buftmp2[0] = bufin[0]; |
| 280 buftmp3[0] = output; | 311 buftmp3[0] = output; |
| 281 stereo_to_mono(buftmp2[0], input, nb_samples); | 312 stereo_to_mono(buftmp2[0], input, nb_samples); |
| 282 } else if (s->output_channels == 2 && s->input_channels == 1) { | 313 } else if (s->output_channels >= 2 && s->input_channels == 1) { |
| 283 buftmp2[0] = input; | 314 buftmp2[0] = input; |
| 284 buftmp3[0] = bufout[0]; | 315 buftmp3[0] = bufout[0]; |
| 285 } else if (s->output_channels == 2) { | 316 } else if (s->output_channels >= 2) { |
| 286 buftmp2[0] = bufin[0]; | 317 buftmp2[0] = bufin[0]; |
| 287 buftmp2[1] = bufin[1]; | 318 buftmp2[1] = bufin[1]; |
| 288 buftmp3[0] = bufout[0]; | 319 buftmp3[0] = bufout[0]; |
| 289 buftmp3[1] = bufout[1]; | 320 buftmp3[1] = bufout[1]; |
| 290 stereo_split(buftmp2[0], buftmp2[1], input, nb_samples); | 321 stereo_split(buftmp2[0], buftmp2[1], input, nb_samples); |
| 301 | 332 |
| 302 if (s->output_channels == 2 && s->input_channels == 1) { | 333 if (s->output_channels == 2 && s->input_channels == 1) { |
| 303 mono_to_stereo(output, buftmp3[0], nb_samples1); | 334 mono_to_stereo(output, buftmp3[0], nb_samples1); |
| 304 } else if (s->output_channels == 2) { | 335 } else if (s->output_channels == 2) { |
| 305 stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1); | 336 stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1); |
| 337 } else if (s->output_channels == 6) { | |
| 338 ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1); | |
| 306 } | 339 } |
| 307 | 340 |
| 308 av_free(bufin[0]); | 341 av_free(bufin[0]); |
| 309 av_free(bufin[1]); | 342 av_free(bufin[1]); |
| 310 | 343 |
