[FFmpeg-devel] [PATCH] examples: add resampling_audio.c file

Michael Niedermayer michaelni at gmx.at
Tue Dec 4 01:54:21 CET 2012


On Tue, Dec 04, 2012 at 12:12:53AM +0100, Stefano Sabatini wrote:
> On date Monday 2012-12-03 16:42:03 +0100, Michael Niedermayer encoded:
> > On Mon, Dec 03, 2012 at 01:31:34PM +0100, Stefano Sabatini wrote:
> > > On date Sunday 2012-12-02 00:34:03 +0100, Michael Niedermayer encoded:
> > > > On Sat, Dec 01, 2012 at 08:21:47PM +0100, Stefano Sabatini wrote:
> [...]
> > > [...] 
> > > > > +    /* allocate source and destination samples buffers */
> > > > > +
> > > > > +    src_nb_channels = av_get_channel_layout_nb_channels(src_ch_layout);
> > > > > +    ret = alloc_samples_array_and_data(&src_data, &src_linesize, src_nb_channels,
> > > > > +                                       src_nb_samples, src_sample_fmt, 0);
> > > > > +    if (ret < 0) {
> > > > > +        fprintf(stderr, "Could not allocate source samples\n");
> > > > > +        goto end;
> > > > > +    }
> > > > > +
> > > > 
> > > 
> > > > > +    /* compute the number of converted samples: buffering is avoided
> > > > > +     * ensuring that the output buffer will contain at least all the
> > > > > +     * converted input samples */

> > > > > +    dst_nb_samples = av_rescale_rnd(swr_get_delay(swr_ctx, dst_rate) + src_nb_samples,
> > > > > +                                    dst_rate, src_rate, AV_ROUND_UP);
[...]
> >  * av_opt_set_int(swr, "in_sample_rate",     48000,                0);
> >  * av_opt_set_int(swr, "out_sample_rate",    44100,                0);
> > [....]
> >  *     int out_samples = av_rescale_rnd(swr_get_delay(swr, 48000) +
> >  *                                      in_samples, 44100, 48000, AV_ROUND_UP);
> 
> dst_rate = 44100
> src_rate = 48000

this would make:

> > > > > +    dst_nb_samples = av_rescale_rnd(swr_get_delay(swr_ctx, dst_rate) + src_nb_samples,
> > > > > +                                    dst_rate, src_rate, AV_ROUND_UP);

to this:

> > > > > +    dst_nb_samples = av_rescale_rnd(swr_get_delay(swr_ctx, 44100) + src_nb_samples,
> > > > > +                                    44100, 48000, AV_ROUND_UP);

which is not what the example says


> 
> And I'm not sure why swr_get_delay() is useful/required.

If you ever feed "more" in than take out then these samples get
buffered. Such samples would be stuck in there until flushing
at the end without the swr_get_delay().

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121204/cbeea578/attachment.asc>


More information about the ffmpeg-devel mailing list