[FFmpeg-devel] [PATCH] examples: add resampling_audio.c file
Stefano Sabatini
stefasab at gmail.com
Mon Dec 3 13:31:34 CET 2012
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.
[...]
> > + /* 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.
--
FFmpeg = Friendly and Fancy Meaningful Puristic Extravagant Game
More information about the ffmpeg-devel
mailing list