FFmpeg
af_stereotools.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2010 Krzysztof Foltman, Markus Schmidt, Thor Harald Johansen
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 
22 #include "libavutil/opt.h"
23 #include "avfilter.h"
24 #include "audio.h"
25 #include "formats.h"
26 
27 typedef struct StereoToolsContext {
28  const AVClass *class;
29 
30  int softclip;
31  int mute_l;
32  int mute_r;
33  int phase_l;
34  int phase_r;
35  int mode;
36  int bmode_in;
37  int bmode_out;
38  double slev;
39  double sbal;
40  double mlev;
41  double mpan;
42  double phase;
43  double base;
44  double delay;
45  double balance_in;
46  double balance_out;
49  double sc_level;
51  double level_in;
52  double level_out;
53 
54  double *buffer;
55  int length;
56  int pos;
58 
59 #define OFFSET(x) offsetof(StereoToolsContext, x)
60 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
61 
62 static const AVOption stereotools_options[] = {
63  { "level_in", "set level in", OFFSET(level_in), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
64  { "level_out", "set level out", OFFSET(level_out), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
65  { "balance_in", "set balance in", OFFSET(balance_in), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, A },
66  { "balance_out", "set balance out", OFFSET(balance_out), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, A },
67  { "softclip", "enable softclip", OFFSET(softclip), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A },
68  { "mutel", "mute L", OFFSET(mute_l), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A },
69  { "muter", "mute R", OFFSET(mute_r), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A },
70  { "phasel", "phase L", OFFSET(phase_l), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A },
71  { "phaser", "phase R", OFFSET(phase_r), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, A },
72  { "mode", "set stereo mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 8, A, "mode" },
73  { "lr>lr", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A, "mode" },
74  { "lr>ms", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A, "mode" },
75  { "ms>lr", 0, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, A, "mode" },
76  { "lr>ll", 0, 0, AV_OPT_TYPE_CONST, {.i64=3}, 0, 0, A, "mode" },
77  { "lr>rr", 0, 0, AV_OPT_TYPE_CONST, {.i64=4}, 0, 0, A, "mode" },
78  { "lr>l+r", 0, 0, AV_OPT_TYPE_CONST, {.i64=5}, 0, 0, A, "mode" },
79  { "lr>rl", 0, 0, AV_OPT_TYPE_CONST, {.i64=6}, 0, 0, A, "mode" },
80  { "ms>ll", 0, 0, AV_OPT_TYPE_CONST, {.i64=7}, 0, 0, A, "mode" },
81  { "ms>rr", 0, 0, AV_OPT_TYPE_CONST, {.i64=8}, 0, 0, A, "mode" },
82  { "slev", "set side level", OFFSET(slev), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
83  { "sbal", "set side balance", OFFSET(sbal), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, A },
84  { "mlev", "set middle level", OFFSET(mlev), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.015625, 64, A },
85  { "mpan", "set middle pan", OFFSET(mpan), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, A },
86  { "base", "set stereo base", OFFSET(base), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -1, 1, A },
87  { "delay", "set delay", OFFSET(delay), AV_OPT_TYPE_DOUBLE, {.dbl=0}, -20, 20, A },
88  { "sclevel", "set S/C level", OFFSET(sc_level), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 1, 100, A },
89  { "phase", "set stereo phase", OFFSET(phase), AV_OPT_TYPE_DOUBLE, {.dbl=0}, 0, 360, A },
90  { "bmode_in", "set balance in mode", OFFSET(bmode_in), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, A, "bmode" },
91  { "balance", 0, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, A, "bmode" },
92  { "amplitude", 0, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, A, "bmode" },
93  { "power", 0, 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, A, "bmode" },
94  { "bmode_out", "set balance out mode", OFFSET(bmode_out), AV_OPT_TYPE_INT, {.i64=0}, 0, 2, A, "bmode" },
95  { NULL }
96 };
97 
98 AVFILTER_DEFINE_CLASS(stereotools);
99 
101 {
104  int ret;
105 
106  if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_DBL )) < 0 ||
107  (ret = ff_set_common_formats (ctx , formats )) < 0 ||
110  return ret;
111 
114 }
115 
117 {
118  AVFilterContext *ctx = inlink->dst;
119  StereoToolsContext *s = ctx->priv;
120 
121  s->length = 2 * inlink->sample_rate * 0.05;
122  if (s->length <= 1 || s->length & 1) {
123  av_log(ctx, AV_LOG_ERROR, "sample rate is too small\n");
124  return AVERROR(EINVAL);
125  }
126  s->buffer = av_calloc(s->length, sizeof(*s->buffer));
127  if (!s->buffer)
128  return AVERROR(ENOMEM);
129 
130  s->inv_atan_shape = 1.0 / atan(s->sc_level);
131  s->phase_cos_coef = cos(s->phase / 180 * M_PI);
132  s->phase_sin_coef = sin(s->phase / 180 * M_PI);
133 
134  return 0;
135 }
136 
138 {
139  AVFilterContext *ctx = inlink->dst;
140  AVFilterLink *outlink = ctx->outputs[0];
141  StereoToolsContext *s = ctx->priv;
142  const double *src = (const double *)in->data[0];
143  const double sb = s->base < 0 ? s->base * 0.5 : s->base;
144  const double sbal = 1 + s->sbal;
145  const double mpan = 1 + s->mpan;
146  const double slev = s->slev;
147  const double mlev = s->mlev;
148  const double balance_in = s->balance_in;
149  const double balance_out = s->balance_out;
150  const double level_in = s->level_in;
151  const double level_out = s->level_out;
152  const double sc_level = s->sc_level;
153  const double delay = s->delay;
154  const int length = s->length;
155  const int mute_l = s->mute_l;
156  const int mute_r = s->mute_r;
157  const int phase_l = s->phase_l;
158  const int phase_r = s->phase_r;
159  double *buffer = s->buffer;
160  AVFrame *out;
161  double *dst;
162  int nbuf = inlink->sample_rate * (fabs(delay) / 1000.);
163  int n;
164 
165  nbuf -= nbuf % 2;
166  if (av_frame_is_writable(in)) {
167  out = in;
168  } else {
169  out = ff_get_audio_buffer(outlink, in->nb_samples);
170  if (!out) {
171  av_frame_free(&in);
172  return AVERROR(ENOMEM);
173  }
175  }
176  dst = (double *)out->data[0];
177 
178  for (n = 0; n < in->nb_samples; n++, src += 2, dst += 2) {
179  double L = src[0], R = src[1], l, r, m, S, gl, gr, gd;
180 
181  L *= level_in;
182  R *= level_in;
183 
184  gl = 1. - FFMAX(0., balance_in);
185  gr = 1. + FFMIN(0., balance_in);
186  switch (s->bmode_in) {
187  case 1:
188  gd = gl - gr;
189  gl = 1. + gd;
190  gr = 1. - gd;
191  break;
192  case 2:
193  if (balance_in < 0.) {
194  gr = FFMAX(0.5, gr);
195  gl = 1. / gr;
196  } else if (balance_in > 0.) {
197  gl = FFMAX(0.5, gl);
198  gr = 1. / gl;
199  }
200  break;
201  }
202  L *= gl;
203  R *= gr;
204 
205  if (s->softclip) {
206  R = s->inv_atan_shape * atan(R * sc_level);
207  L = s->inv_atan_shape * atan(L * sc_level);
208  }
209 
210  switch (s->mode) {
211  case 0:
212  m = (L + R) * 0.5;
213  S = (L - R) * 0.5;
214  l = m * mlev * FFMIN(1., 2. - mpan) + S * slev * FFMIN(1., 2. - sbal);
215  r = m * mlev * FFMIN(1., mpan) - S * slev * FFMIN(1., sbal);
216  L = l;
217  R = r;
218  break;
219  case 1:
220  l = L * FFMIN(1., 2. - sbal);
221  r = R * FFMIN(1., sbal);
222  L = 0.5 * (l + r) * mlev;
223  R = 0.5 * (l - r) * slev;
224  break;
225  case 2:
226  l = L * mlev * FFMIN(1., 2. - mpan) + R * slev * FFMIN(1., 2. - sbal);
227  r = L * mlev * FFMIN(1., mpan) - R * slev * FFMIN(1., sbal);
228  L = l;
229  R = r;
230  break;
231  case 3:
232  R = L;
233  break;
234  case 4:
235  L = R;
236  break;
237  case 5:
238  L = (L + R) / 2;
239  R = L;
240  break;
241  case 6:
242  l = L;
243  L = R;
244  R = l;
245  m = (L + R) * 0.5;
246  S = (L - R) * 0.5;
247  l = m * mlev * FFMIN(1., 2. - mpan) + S * slev * FFMIN(1., 2. - sbal);
248  r = m * mlev * FFMIN(1., mpan) - S * slev * FFMIN(1., sbal);
249  L = l;
250  R = r;
251  break;
252  case 7:
253  l = L * mlev * FFMIN(1., 2. - mpan) + R * slev * FFMIN(1., 2. - sbal);
254  L = l;
255  R = l;
256  break;
257  case 8:
258  r = L * mlev * FFMIN(1., mpan) - R * slev * FFMIN(1., sbal);
259  L = r;
260  R = r;
261  break;
262  }
263 
264  L *= 1. - mute_l;
265  R *= 1. - mute_r;
266 
267  L *= (2. * (1. - phase_l)) - 1.;
268  R *= (2. * (1. - phase_r)) - 1.;
269 
270  buffer[s->pos ] = L;
271  buffer[s->pos+1] = R;
272 
273  if (delay > 0.) {
274  R = buffer[(s->pos - (int)nbuf + 1 + length) % length];
275  } else if (delay < 0.) {
276  L = buffer[(s->pos - (int)nbuf + length) % length];
277  }
278 
279  l = L + sb * L - sb * R;
280  r = R + sb * R - sb * L;
281 
282  L = l;
283  R = r;
284 
285  l = L * s->phase_cos_coef - R * s->phase_sin_coef;
286  r = L * s->phase_sin_coef + R * s->phase_cos_coef;
287 
288  L = l;
289  R = r;
290 
291  s->pos = (s->pos + 2) % s->length;
292 
293  gl = 1. - FFMAX(0., balance_out);
294  gr = 1. + FFMIN(0., balance_out);
295  switch (s->bmode_out) {
296  case 1:
297  gd = gl - gr;
298  gl = 1. + gd;
299  gr = 1. - gd;
300  break;
301  case 2:
302  if (balance_out < 0.) {
303  gr = FFMAX(0.5, gr);
304  gl = 1. / gr;
305  } else if (balance_out > 0.) {
306  gl = FFMAX(0.5, gl);
307  gr = 1. / gl;
308  }
309  break;
310  }
311  L *= gl;
312  R *= gr;
313 
314 
315  L *= level_out;
316  R *= level_out;
317 
318  dst[0] = L;
319  dst[1] = R;
320  }
321 
322  if (out != in)
323  av_frame_free(&in);
324  return ff_filter_frame(outlink, out);
325 }
326 
328 {
329  StereoToolsContext *s = ctx->priv;
330 
331  av_freep(&s->buffer);
332 }
333 
334 static const AVFilterPad inputs[] = {
335  {
336  .name = "default",
337  .type = AVMEDIA_TYPE_AUDIO,
338  .filter_frame = filter_frame,
339  .config_props = config_input,
340  },
341  { NULL }
342 };
343 
344 static const AVFilterPad outputs[] = {
345  {
346  .name = "default",
347  .type = AVMEDIA_TYPE_AUDIO,
348  },
349  { NULL }
350 };
351 
353  .name = "stereotools",
354  .description = NULL_IF_CONFIG_SMALL("Apply various stereo tools."),
355  .query_formats = query_formats,
356  .priv_size = sizeof(StereoToolsContext),
357  .priv_class = &stereotools_class,
358  .uninit = uninit,
359  .inputs = inputs,
360  .outputs = outputs,
361 };
ff_af_stereotools
AVFilter ff_af_stereotools
Definition: af_stereotools.c:352
formats
formats
Definition: signature.h:48
ff_get_audio_buffer
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
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
StereoToolsContext::mlev
double mlev
Definition: af_stereotools.c:40
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: af_stereotools.c:100
r
const char * r
Definition: vf_curves.c:114
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
A
#define A
Definition: af_stereotools.c:60
out
FILE * out
Definition: movenc.c:54
n
int n
Definition: avisynth_c.h:760
ff_set_common_channel_layouts
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
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
inputs
static const AVFilterPad inputs[]
Definition: af_stereotools.c:334
StereoToolsContext::delay
double delay
Definition: af_stereotools.c:44
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
R
#define R
Definition: huffyuvdsp.h:34
StereoToolsContext::buffer
double * buffer
Definition: af_stereotools.c:54
StereoToolsContext::inv_atan_shape
double inv_atan_shape
Definition: af_stereotools.c:50
AVOption
AVOption.
Definition: opt.h:246
StereoToolsContext::mute_l
int mute_l
Definition: af_stereotools.c:31
base
uint8_t base
Definition: vp3data.h:202
StereoToolsContext::sbal
double sbal
Definition: af_stereotools.c:39
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_stereotools.c:327
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
S
#define S(s, c, i)
Definition: flacdsp_template.c:46
StereoToolsContext::mpan
double mpan
Definition: af_stereotools.c:41
outputs
static const AVFilterPad outputs[]
Definition: af_stereotools.c:344
config_input
static int config_input(AVFilterLink *inlink)
Definition: af_stereotools.c:116
src
#define src
Definition: vp8dsp.c:254
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:86
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:84
ff_set_common_formats
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
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:343
StereoToolsContext::softclip
int softclip
Definition: af_stereotools.c:30
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:225
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
StereoToolsContext::phase_l
int phase_l
Definition: af_stereotools.c:33
StereoToolsContext::base
double base
Definition: af_stereotools.c:43
ctx
AVFormatContext * ctx
Definition: movenc.c:48
StereoToolsContext::phase_cos_coef
double phase_cos_coef
Definition: af_stereotools.c:48
StereoToolsContext::balance_out
double balance_out
Definition: af_stereotools.c:46
StereoToolsContext::pos
int pos
Definition: af_stereotools.c:56
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
ff_add_format
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:337
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
StereoToolsContext::phase
double phase
Definition: af_stereotools.c:42
StereoToolsContext::bmode_out
int bmode_out
Definition: af_stereotools.c:37
StereoToolsContext::phase_r
int phase_r
Definition: af_stereotools.c:34
StereoToolsContext::mode
int mode
Definition: af_stereotools.c:35
OFFSET
#define OFFSET(x)
Definition: af_stereotools.c:59
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
StereoToolsContext::level_out
double level_out
Definition: af_stereotools.c:52
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
StereoToolsContext
Definition: af_stereotools.c:27
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_stereotools.c:137
M_PI
#define M_PI
Definition: mathematics.h:52
StereoToolsContext::balance_in
double balance_in
Definition: af_stereotools.c:45
layout
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
Definition: filter_design.txt:18
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
stereotools_options
static const AVOption stereotools_options[]
Definition: af_stereotools.c:62
StereoToolsContext::phase_sin_coef
double phase_sin_coef
Definition: af_stereotools.c:47
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AVFilter
Filter definition.
Definition: avfilter.h:144
ret
ret
Definition: filter_design.txt:187
L
#define L(x)
Definition: vp56_arith.h:36
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
channel_layout.h
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
mode
mode
Definition: ebur128.h:83
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(stereotools)
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
audio.h
StereoToolsContext::length
int length
Definition: af_stereotools.c:55
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
StereoToolsContext::sc_level
double sc_level
Definition: af_stereotools.c:49
length
const char int length
Definition: avisynth_c.h:860
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
AV_SAMPLE_FMT_DBL
@ AV_SAMPLE_FMT_DBL
double
Definition: samplefmt.h:64
StereoToolsContext::slev
double slev
Definition: af_stereotools.c:38
int
int
Definition: ffmpeg_filter.c:191
StereoToolsContext::level_in
double level_in
Definition: af_stereotools.c:51
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
StereoToolsContext::mute_r
int mute_r
Definition: af_stereotools.c:32
StereoToolsContext::bmode_in
int bmode_in
Definition: af_stereotools.c:36