FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
af_acrusher.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) Markus Schmidt and Christian Holschuh
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/opt.h"
22 #include "avfilter.h"
23 #include "internal.h"
24 #include "audio.h"
25 
26 typedef struct LFOContext {
27  double freq;
28  double offset;
29  int srate;
30  double amount;
31  double pwidth;
32  double phase;
33 } LFOContext;
34 
35 typedef struct SRContext {
36  double target;
37  double real;
38  double samples;
39  double last;
40 } SRContext;
41 
42 typedef struct ACrusherContext {
43  const AVClass *class;
44 
45  double level_in;
46  double level_out;
47  double bits;
48  double mix;
49  int mode;
50  double dc;
51  double idc;
52  double aa;
53  double samples;
54  int is_lfo;
55  double lforange;
56  double lforate;
57 
58  double sqr;
59  double aa1;
60  double coeff;
61  int round;
62  double sov;
63  double smin;
64  double sdiff;
65 
69 
70 #define OFFSET(x) offsetof(ACrusherContext, x)
71 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
72 
73 static const AVOption acrusher_options[] = {
74  { "level_in", "set level in", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
75  { "level_out","set level out", OFFSET(level_out), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
76  { "bits", "set bit reduction", OFFSET(bits), AV_OPT_TYPE_DOUBLE, {.dbl=8}, 1, 64, A },
77  { "mix", "set mix", OFFSET(mix), AV_OPT_TYPE_DOUBLE, {.dbl=.5}, 0, 1, A },
78  { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, A, "mode" },
79  { "lin", "linear", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A, "mode" },
80  { "log", "logarithmic", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A, "mode" },
81  { "dc", "set DC", OFFSET(dc), AV_OPT_TYPE_DOUBLE, {.dbl=1}, .25, 4, A },
82  { "aa", "set anti-aliasing", OFFSET(aa), AV_OPT_TYPE_DOUBLE, {.dbl=.5}, 0, 1, A },
83  { "samples", "set sample reduction", OFFSET(samples), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 250, A },
84  { "lfo", "enable LFO", OFFSET(is_lfo), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A },
85  { "lforange", "set LFO depth", OFFSET(lforange), AV_OPT_TYPE_DOUBLE, {.dbl=20}, 1, 250, A },
86  { "lforate", "set LFO rate", OFFSET(lforate), AV_OPT_TYPE_DOUBLE, {.dbl=.3}, .01, 200, A },
87  { NULL }
88 };
89 
90 AVFILTER_DEFINE_CLASS(acrusher);
91 
92 static double samplereduction(ACrusherContext *s, SRContext *sr, double in)
93 {
94  sr->samples++;
95  if (sr->samples >= s->round) {
96  sr->target += s->samples;
97  sr->real += s->round;
98  if (sr->target + s->samples >= sr->real + 1) {
99  sr->last = in;
100  sr->target = 0;
101  sr->real = 0;
102  }
103  sr->samples = 0;
104  }
105  return sr->last;
106 }
107 
108 static double add_dc(double s, double dc, double idc)
109 {
110  return s > 0 ? s * dc : s * idc;
111 }
112 
113 static double remove_dc(double s, double dc, double idc)
114 {
115  return s > 0 ? s * idc : s * dc;
116 }
117 
118 static inline double factor(double y, double k, double aa1, double aa)
119 {
120  return 0.5 * (sin(M_PI * (fabs(y - k) - aa1) / aa - M_PI_2) + 1);
121 }
122 
123 static double bitreduction(ACrusherContext *s, double in)
124 {
125  const double sqr = s->sqr;
126  const double coeff = s->coeff;
127  const double aa = s->aa;
128  const double aa1 = s->aa1;
129  double y, k;
130 
131  // add dc
132  in = add_dc(in, s->dc, s->idc);
133 
134  // main rounding calculation depending on mode
135 
136  // the idea for anti-aliasing:
137  // you need a function f which brings you to the scale, where
138  // you want to round and the function f_b (with f(f_b)=id) which
139  // brings you back to your original scale.
140  //
141  // then you can use the logic below in the following way:
142  // y = f(in) and k = roundf(y)
143  // if (y > k + aa1)
144  // k = f_b(k) + ( f_b(k+1) - f_b(k) ) * 0.5 * (sin(x - PI/2) + 1)
145  // if (y < k + aa1)
146  // k = f_b(k) - ( f_b(k+1) - f_b(k) ) * 0.5 * (sin(x - PI/2) + 1)
147  //
148  // whereas x = (fabs(f(in) - k) - aa1) * PI / aa
149  // for both cases.
150 
151  switch (s->mode) {
152  case 0:
153  default:
154  // linear
155  y = in * coeff;
156  k = roundf(y);
157  if (k - aa1 <= y && y <= k + aa1) {
158  k /= coeff;
159  } else if (y > k + aa1) {
160  k = k / coeff + ((k + 1) / coeff - k / coeff) *
161  factor(y, k, aa1, aa);
162  } else {
163  k = k / coeff - (k / coeff - (k - 1) / coeff) *
164  factor(y, k, aa1, aa);
165  }
166  break;
167  case 1:
168  // logarithmic
169  y = sqr * log(fabs(in)) + sqr * sqr;
170  k = roundf(y);
171  if(!in) {
172  k = 0;
173  } else if (k - aa1 <= y && y <= k + aa1) {
174  k = in / fabs(in) * exp(k / sqr - sqr);
175  } else if (y > k + aa1) {
176  double x = exp(k / sqr - sqr);
177  k = FFSIGN(in) * (x + (exp((k + 1) / sqr - sqr) - x) *
178  factor(y, k, aa1, aa));
179  } else {
180  double x = exp(k / sqr - sqr);
181  k = in / fabs(in) * (x - (x - exp((k - 1) / sqr - sqr)) *
182  factor(y, k, aa1, aa));
183  }
184  break;
185  }
186 
187  // mix between dry and wet signal
188  k += (in - k) * s->mix;
189 
190  // remove dc
191  k = remove_dc(k, s->dc, s->idc);
192 
193  return k;
194 }
195 
196 static double lfo_get(LFOContext *lfo)
197 {
198  double phs = FFMIN(100., lfo->phase / FFMIN(1.99, FFMAX(0.01, lfo->pwidth)) + lfo->offset);
199  double val;
200 
201  if (phs > 1)
202  phs = fmod(phs, 1.);
203 
204  val = sin((phs * 360.) * M_PI / 180);
205 
206  return val * lfo->amount;
207 }
208 
209 static void lfo_advance(LFOContext *lfo, unsigned count)
210 {
211  lfo->phase = fabs(lfo->phase + count * lfo->freq * (1. / lfo->srate));
212  if (lfo->phase >= 1.)
213  lfo->phase = fmod(lfo->phase, 1.);
214 }
215 
216 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
217 {
218  AVFilterContext *ctx = inlink->dst;
219  ACrusherContext *s = ctx->priv;
220  AVFilterLink *outlink = ctx->outputs[0];
221  AVFrame *out;
222  const double *src = (const double *)in->data[0];
223  double *dst;
224  const double level_in = s->level_in;
225  const double level_out = s->level_out;
226  const double mix = s->mix;
227  int n, c;
228 
229  if (av_frame_is_writable(in)) {
230  out = in;
231  } else {
232  out = ff_get_audio_buffer(inlink, in->nb_samples);
233  if (!out) {
234  av_frame_free(&in);
235  return AVERROR(ENOMEM);
236  }
237  av_frame_copy_props(out, in);
238  }
239 
240  dst = (double *)out->data[0];
241  for (n = 0; n < in->nb_samples; n++) {
242  if (s->is_lfo) {
243  s->samples = s->smin + s->sdiff * (lfo_get(&s->lfo) + 0.5);
244  s->round = round(s->samples);
245  }
246 
247  for (c = 0; c < inlink->channels; c++) {
248  double sample = src[c] * level_in;
249 
250  sample = mix * samplereduction(s, &s->sr[c], sample) + src[c] * (1. - mix) * level_in;
251  dst[c] = bitreduction(s, sample) * level_out;
252  }
253  src += c;
254  dst += c;
255 
256  if (s->is_lfo)
257  lfo_advance(&s->lfo, 1);
258  }
259 
260  if (in != out)
261  av_frame_free(&in);
262 
263  return ff_filter_frame(outlink, out);
264 }
265 
267 {
270  static const enum AVSampleFormat sample_fmts[] = {
273  };
274  int ret;
275 
276  layouts = ff_all_channel_counts();
277  if (!layouts)
278  return AVERROR(ENOMEM);
279  ret = ff_set_common_channel_layouts(ctx, layouts);
280  if (ret < 0)
281  return ret;
282 
283  formats = ff_make_format_list(sample_fmts);
284  if (!formats)
285  return AVERROR(ENOMEM);
286  ret = ff_set_common_formats(ctx, formats);
287  if (ret < 0)
288  return ret;
289 
290  formats = ff_all_samplerates();
291  if (!formats)
292  return AVERROR(ENOMEM);
293  return ff_set_common_samplerates(ctx, formats);
294 }
295 
297 {
298  ACrusherContext *s = ctx->priv;
299 
300  av_freep(&s->sr);
301 }
302 
303 static int config_input(AVFilterLink *inlink)
304 {
305  AVFilterContext *ctx = inlink->dst;
306  ACrusherContext *s = ctx->priv;
307  double rad, sunder, smax, sover;
308 
309  s->idc = 1. / s->dc;
310  s->coeff = exp2(s->bits) - 1;
311  s->sqr = sqrt(s->coeff / 2);
312  s->aa1 = (1. - s->aa) / 2.;
313  s->round = round(s->samples);
314  rad = s->lforange / 2.;
315  s->smin = FFMAX(s->samples - rad, 1.);
316  sunder = s->samples - rad - s->smin;
317  smax = FFMIN(s->samples + rad, 250.);
318  sover = s->samples + rad - smax;
319  smax -= sunder;
320  s->smin -= sover;
321  s->sdiff = smax - s->smin;
322 
323  s->lfo.freq = s->lforate;
324  s->lfo.pwidth = 1.;
325  s->lfo.srate = inlink->sample_rate;
326  s->lfo.amount = .5;
327 
328  s->sr = av_calloc(inlink->channels, sizeof(*s->sr));
329  if (!s->sr)
330  return AVERROR(ENOMEM);
331 
332  return 0;
333 }
334 
336  {
337  .name = "default",
338  .type = AVMEDIA_TYPE_AUDIO,
339  .config_props = config_input,
340  .filter_frame = filter_frame,
341  },
342  { NULL }
343 };
344 
346  {
347  .name = "default",
348  .type = AVMEDIA_TYPE_AUDIO,
349  },
350  { NULL }
351 };
352 
354  .name = "acrusher",
355  .description = NULL_IF_CONFIG_SMALL("Reduce audio bit resolution."),
356  .priv_size = sizeof(ACrusherContext),
357  .priv_class = &acrusher_class,
358  .uninit = uninit,
360  .inputs = avfilter_af_acrusher_inputs,
361  .outputs = avfilter_af_acrusher_outputs,
362 };
static double factor(double y, double k, double aa1, double aa)
Definition: af_acrusher.c:118
#define NULL
Definition: coverity.c:32
int ff_set_common_channel_layouts(AVFilterContext *ctx, AVFilterChannelLayouts *layouts)
A helper for query_formats() which sets all links to the same list of channel layouts/sample rates...
Definition: formats.c:549
const char const char void * val
Definition: avisynth_c.h:771
const char * s
Definition: avisynth_c.h:768
static int query_formats(AVFilterContext *ctx)
Definition: af_acrusher.c:266
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
AVOption.
Definition: opt.h:246
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_acrusher.c:216
double samples
Definition: af_acrusher.c:38
Main libavfilter public API header.
double amount
Definition: af_acrusher.c:30
static double samplereduction(ACrusherContext *s, SRContext *sr, double in)
Definition: af_acrusher.c:92
double level_out
Definition: af_acrusher.c:46
#define src
Definition: vp8dsp.c:254
#define sample
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:230
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
static void lfo_advance(LFOContext *lfo, unsigned count)
Definition: af_acrusher.c:209
static double add_dc(double s, double dc, double idc)
Definition: af_acrusher.c:108
const char * name
Pad name.
Definition: internal.h:60
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1125
double phase
Definition: af_acrusher.c:32
uint8_t bits
Definition: crc.c:296
double freq
Definition: af_acrusher.c:27
#define av_cold
Definition: attributes.h:82
AVOptions.
LFOContext lfo
Definition: af_acrusher.c:66
static const AVFilterPad avfilter_af_acrusher_inputs[]
Definition: af_acrusher.c:335
AVFilter ff_af_acrusher
Definition: af_acrusher.c:353
A filter pad used for either input or output.
Definition: internal.h:54
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition: audio.c:86
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
void * priv
private data for use by the filter
Definition: avfilter.h:338
static av_always_inline av_const double round(double x)
Definition: libm.h:444
GLsizei count
Definition: opengl_enc.c:109
#define FFMAX(a, b)
Definition: common.h:94
int8_t exp
Definition: eval.c:65
#define FFMIN(a, b)
Definition: common.h:96
#define FFSIGN(a)
Definition: common.h:73
#define OFFSET(x)
Definition: af_acrusher.c:70
#define M_PI_2
Definition: mathematics.h:55
AVFormatContext * ctx
Definition: movenc.c:48
double offset
Definition: af_acrusher.c:28
int n
Definition: avisynth_c.h:684
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
A list of supported channel layouts.
Definition: formats.h:85
static int mix(int c0, int c1)
Definition: 4xm.c:707
static double bitreduction(ACrusherContext *s, double in)
Definition: af_acrusher.c:123
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:536
static double remove_dc(double s, double dc, double idc)
Definition: af_acrusher.c:113
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
static const AVFilterPad avfilter_af_acrusher_outputs[]
Definition: af_acrusher.c:345
double last
Definition: af_acrusher.c:39
static const AVOption acrusher_options[]
Definition: af_acrusher.c:73
const char * name
Filter name.
Definition: avfilter.h:148
double real
Definition: af_acrusher.c:37
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_acrusher.c:296
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:335
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
static av_always_inline av_const float roundf(float x)
Definition: libm.h:451
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
static int config_input(AVFilterLink *inlink)
Definition: af_acrusher.c:303
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
SRContext * sr
Definition: af_acrusher.c:67
if(ret< 0)
Definition: vf_mcdeint.c:282
#define exp2(x)
Definition: libm.h:288
static double c[64]
static double lfo_get(LFOContext *lfo)
Definition: af_acrusher.c:196
double target
Definition: af_acrusher.c:36
AVFILTER_DEFINE_CLASS(acrusher)
A list of supported formats for one end of a filter link.
Definition: formats.h:64
static const double coeff[2][5]
Definition: vf_owdenoise.c:72
An instance of a filter.
Definition: avfilter.h:323
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> dc
#define A
Definition: af_acrusher.c:71
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
FILE * out
Definition: movenc.c:54
#define av_freep(p)
#define M_PI
Definition: mathematics.h:52
formats
Definition: signature.h:48
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:410
double pwidth
Definition: af_acrusher.c:31
mode
Use these values in ebur128_init (or'ed).
Definition: ebur128.h:83
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:244
for(j=16;j >0;--j)
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:596