[FFmpeg-devel] [PATCH] examples: add resampling_audio.c file
Michael Niedermayer
michaelni at gmx.at
Mon Dec 3 16:42:03 CET 2012
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:
> [...]
> > > +static int get_format_from_sample_fmt(const char **fmt,
> > > + enum AVSampleFormat sample_fmt)
> > > +{
> > > + int i;
> > > + struct sample_fmt_entry {
> > > + enum AVSampleFormat sample_fmt; const char *fmt_be, *fmt_le;
> > > + } sample_fmt_entries[] = {
> > > + { AV_SAMPLE_FMT_U8, "u8", "u8" },
> > > + { AV_SAMPLE_FMT_S16, "s16be", "s16le" },
> > > + { AV_SAMPLE_FMT_S32, "s32be", "s32le" },
> > > + { AV_SAMPLE_FMT_FLT, "f32be", "f32le" },
> > > + { AV_SAMPLE_FMT_DBL, "f64be", "f64le" },
> > > + };
> > > + *fmt = NULL;
> > > +
> > > + for (i = 0; i < FF_ARRAY_ELEMS(sample_fmt_entries); i++) {
> > > + struct sample_fmt_entry *entry = &sample_fmt_entries[i];
> > > + if (sample_fmt == entry->sample_fmt) {
> > > + *fmt = AV_NE(entry->fmt_be, entry->fmt_le);
> > > + return 0;
> > > + }
> > > + }
> >
>
> > something like
> > { AV_SAMPLE_FMT_U8, AV_NE("u8", "u8" ) },
> > { AV_SAMPLE_FMT_S16, AV_NE("s16be", "s16le") },
> > ...
> > should be slightly simpler
>
> Tried it, but I prefer slightly the current variant (more information
> stored in the struct), and requires less characters.
fine with me too
>
> [...]
> > > + /* 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);
> >
> > isnt this mixing up src and dst rates ?
>
> Yes, it is:
>
> N2 = N1 * R2 / R1
>
> and it is copied from the swresample.h doxy.
from where?
the doxy says this:
* 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);
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
What does censorship reveal? It reveals fear. -- Julian Assange
-------------- 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/20121203/d73591b6/attachment.asc>
More information about the ffmpeg-devel
mailing list