MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / audio_resample

Function audio_resample

libavcodec/resample.c:233–362  ·  view source on GitHub ↗

resample audio. 'nb_samples' is the number of input samples */ XXX: optimize it ! */

Source from the content-addressed store, hash-verified

231/* resample audio. 'nb_samples' is the number of input samples */
232/* XXX: optimize it ! */
233int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
234{
235 int i, nb_samples1;
236 short *bufin[2];
237 short *bufout[2];
238 short *buftmp2[2], *buftmp3[2];
239 short *output_bak = NULL;
240 int lenout;
241
242 if (s->input_channels == s->output_channels && s->ratio == 1.0 && 0) {
243 /* nothing to do */
244 memcpy(output, input, nb_samples * s->input_channels * sizeof(short));
245 return nb_samples;
246 }
247
248 if (s->sample_fmt[0] != SAMPLE_FMT_S16) {
249 int istride[1] = { s->sample_size[0] };
250 int ostride[1] = { 2 };
251 const void *ibuf[1] = { input };
252 void *obuf[1];
253 unsigned input_size = nb_samples*s->input_channels*2;
254
255 if (!s->buffer_size[0] || s->buffer_size[0] < input_size) {
256 av_free(s->buffer[0]);
257 s->buffer_size[0] = input_size;
258 s->buffer[0] = av_malloc(s->buffer_size[0]);
259 if (!s->buffer[0]) {
260 av_log(s->resample_context, AV_LOG_ERROR, "Could not allocate buffer\n");
261 return 0;
262 }
263 }
264
265 obuf[0] = s->buffer[0];
266
267 if (av_audio_convert(s->convert_ctx[0], obuf, ostride,
268 ibuf, istride, nb_samples*s->input_channels) < 0) {
269 av_log(s->resample_context, AV_LOG_ERROR, "Audio sample format conversion failed\n");
270 return 0;
271 }
272
273 input = s->buffer[0];
274 }
275
276 lenout= 4*nb_samples * s->ratio + 16;
277
278 if (s->sample_fmt[1] != SAMPLE_FMT_S16) {
279 output_bak = output;
280
281 if (!s->buffer_size[1] || s->buffer_size[1] < lenout) {
282 av_free(s->buffer[1]);
283 s->buffer_size[1] = lenout;
284 s->buffer[1] = av_malloc(s->buffer_size[1]);
285 if (!s->buffer[1]) {
286 av_log(s->resample_context, AV_LOG_ERROR, "Could not allocate buffer\n");
287 return 0;
288 }
289 }
290

Callers 1

do_audio_outFunction · 0.85

Calls 11

av_freeFunction · 0.85
av_mallocFunction · 0.85
av_logFunction · 0.85
av_audio_convertFunction · 0.85
stereo_to_monoFunction · 0.85
stereo_splitFunction · 0.85
av_resampleFunction · 0.85
av_reallocFunction · 0.85
mono_to_stereoFunction · 0.85
stereo_muxFunction · 0.85
ac3_5p1_muxFunction · 0.85

Tested by

no test coverage detected