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

Stefano Sabatini stefasab at gmail.com
Thu Dec 6 10:18:18 CET 2012


On date Wednesday 2012-12-05 23:43:48 +0100, Michael Niedermayer encoded:
> On Tue, Dec 04, 2012 at 10:55:24PM +0100, Stefano Sabatini wrote:
> > On date Tuesday 2012-12-04 18:14:53 +0100, Michael Niedermayer encoded:
> > > On Tue, Dec 04, 2012 at 10:58:48AM +0100, Stefano Sabatini wrote:
> > [...]
> > > > > > 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().
> > > > 
> > > > I realized that the swr_get_delay() in the example is useless, since it
> > > > is called before the first conversion is performed (so it is always
> > > > 0). On the other hand the destination size is computed so that it
> > > > should contain *all* the converted samples, so I assume that if the
> > > > output buffer is big enough then no buffering will occurr at all.  Is
> > > > this correct?
> > > 
> > > resampling needs a delay and this delay may vary slightly due filter
> > > parameters and timestamp drift.
> > > this variation may occasionally cause a tiny bit more samples to be
> > > available than the rounded up value.
> > 
> > Updated.
> > -- 
> > FFmpeg = Frenzy and Faithless Mastodontic Peaceless Enlightened Gigant
> 
> >  Makefile           |    1 
> >  resampling_audio.c |  223 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 224 insertions(+)
> > 62217adca41e0f174aec7a2e45556450d002afe2  0001-examples-add-resampling_audio.c-file.patch
> > From 27783bea1d83b3358d70d8ad78bcc06f5174787c Mon Sep 17 00:00:00 2001
> > From: Stefano Sabatini <stefasab at gmail.com>
> > Date: Fri, 30 Nov 2012 13:51:40 +0100
> > Subject: [PATCH] examples: add resampling_audio.c file
> > 
> > ---
> >  doc/examples/Makefile           |    1 +
> >  doc/examples/resampling_audio.c |  223 +++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 224 insertions(+)
> >  create mode 100644 doc/examples/resampling_audio.c
> > 
> > diff --git a/doc/examples/Makefile b/doc/examples/Makefile
> > index 36c949a..c849daa 100644
> > --- a/doc/examples/Makefile
> > +++ b/doc/examples/Makefile
> > @@ -17,6 +17,7 @@ EXAMPLES=       decoding_encoding                  \
> >                  filtering_audio                    \
> >                  metadata                           \
> >                  muxing                             \
> > +                resampling_audio                   \
> >                  scaling_video                      \
> >  
> >  OBJS=$(addsuffix .o,$(EXAMPLES))
> > diff --git a/doc/examples/resampling_audio.c b/doc/examples/resampling_audio.c
> > new file mode 100644
> > index 0000000..a2f3be9
> > --- /dev/null
> > +++ b/doc/examples/resampling_audio.c
> > @@ -0,0 +1,223 @@
> > +/*
> > + * Copyright (c) 2012 Stefano Sabatini
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a copy
> > + * of this software and associated documentation files (the "Software"), to deal
> > + * in the Software without restriction, including without limitation the rights
> > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> > + * copies of the Software, and to permit persons to whom the Software is
> > + * furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> > + * THE SOFTWARE.
> > + */
> > +
> 
> > +/**
> > + * @file
> > + * libswresample API use example.
> > + */
> 
> might make sense to point to
> libswresample/swresample-test.c
> as another example
> 
> [...]
> > +/**
> > + * Fill dst buffer with nb_samples, generated starting from t.
> > + */
> > +void fill_samples(double *dst, int nb_samples, int nb_channels, int sample_rate, double *t)
> > +{
> > +    int i, j;
> > +    double tincr = (double)1 / sample_rate, *dstp = dst;
> 
> 1.0
> 
> 
> > +    const double c = 2 * M_PI * (double)440.0;
> 
> the double cast is unneeded
> 
> [..]
> > +    if (src_data[0])
> > +        av_freep(&src_data[0]);
> 
> the if() looks unneeded

Changed to if (src_data) ...
Fixes a crash.

> 
> no more comments from me

Updated, and applied, thanks.
-- 
FFmpeg = Friendly and Fundamentalist Meaningful Programmable Extended God


More information about the ffmpeg-devel mailing list