FFmpeg
Loading...
Searching...
No Matches
af_extrastereo.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 The FFmpeg Project
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 "filters.h"
26#include "formats.h"
27
28typedef struct ExtraStereoContext {
29 const AVClass *class;
30 float mult;
31 int clip;
33
34#define OFFSET(x) offsetof(ExtraStereoContext, x)
35#define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
36
37static const AVOption extrastereo_options[] = {
38 { "m", "set the difference coefficient", OFFSET(mult), AV_OPT_TYPE_FLOAT, {.dbl=2.5}, -10, 10, A },
39 { "c", "enable clipping", OFFSET(clip), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, A },
40 { NULL }
41};
42
44
46 AVFilterFormatsConfig **cfg_in,
47 AVFilterFormatsConfig **cfg_out)
48{
49 static const enum AVSampleFormat formats[] = {
52 };
53 static const AVChannelLayout layouts[] = {
55 { .nb_channels = 0 },
56 };
57
58 int ret;
59
60 ret = ff_set_sample_formats_from_list2(ctx, cfg_in, cfg_out, formats);
61 if (ret < 0)
62 return ret;
63
65 if (ret < 0)
66 return ret;
67
68 return 0;
69}
70
71static int filter_frame(AVFilterLink *inlink, AVFrame *in)
72{
73 AVFilterContext *ctx = inlink->dst;
74 AVFilterLink *outlink = ctx->outputs[0];
75 ExtraStereoContext *s = ctx->priv;
76 const float *src = (const float *)in->data[0];
77 const float mult = s->mult;
78 AVFrame *out;
79 float *dst;
80 int n;
81
82 if (av_frame_is_writable(in)) {
83 out = in;
84 } else {
85 out = ff_get_audio_buffer(outlink, in->nb_samples);
86 if (!out) {
87 av_frame_free(&in);
88 return AVERROR(ENOMEM);
89 }
91 }
92 dst = (float *)out->data[0];
93
94 for (n = 0; n < in->nb_samples; n++) {
95 float average, left, right;
96
97 left = src[n * 2 ];
98 right = src[n * 2 + 1];
99 average = (left + right) / 2.;
100 left = average + mult * (left - average);
101 right = average + mult * (right - average);
102
103 if (s->clip) {
104 left = av_clipf(left, -1, 1);
105 right = av_clipf(right, -1, 1);
106 }
107
108 dst[n * 2 ] = left;
109 dst[n * 2 + 1] = right;
110 }
111
112 if (out != in)
113 av_frame_free(&in);
114 return ff_filter_frame(outlink, out);
115}
116
117static const AVFilterPad inputs[] = {
118 {
119 .name = "default",
120 .type = AVMEDIA_TYPE_AUDIO,
121 .filter_frame = filter_frame,
122 },
123};
124
126 .p.name = "extrastereo",
127 .p.description = NULL_IF_CONFIG_SMALL("Increase difference between stereo audio channels."),
128 .p.priv_class = &extrastereo_class,
130 .priv_size = sizeof(ExtraStereoContext),
134 .process_command = ff_filter_process_command,
135};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
Definition aeval.c:246
static const AVFilterPad inputs[]
Definition af_aap.c:299
static const AVOption extrastereo_options[]
const FFFilter ff_af_extrastereo
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
#define OFFSET(x)
static FILE * out
static AVFormatContext * ctx
#define A(x)
Definition vpx_arith.h:28
const AVFilterPad ff_audio_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_AUDIO.
Definition audio.c:34
AVFrame * ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
Request an audio samples buffer with a specific set of permissions.
Definition audio.c:74
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition avfilter.c:906
Main libavfilter public API header.
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
#define av_clipf
Definition common.h:145
#define NULL
Definition coverity.c:32
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
int ff_set_common_channel_layouts_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const AVChannelLayout *fmts)
Definition formats.c:1026
int ff_set_sample_formats_from_list2(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out, const enum AVSampleFormat *fmts)
Definition formats.c:1154
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition avfilter.h:196
#define AV_CHANNEL_LAYOUT_STEREO
#define AVERROR(e)
Definition error.h:45
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition frame.c:535
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_FLT
float
Definition samplefmt.h:60
@ AV_SAMPLE_FMT_NONE
Definition samplefmt.h:56
static int16_t mult(Float11 *f1, Float11 *f2)
Definition g726.c:60
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define FILTER_QUERY_FUNC2(func)
Definition filters.h:241
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
enum MovChannelLayoutTag * layouts
Definition mov_chan.c:335
AVOptions.
formats
Definition signature.h:47
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
Lists of formats / etc.
Definition avfilter.h:120
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int nb_samples
number of audio samples (per channel) described by this frame
Definition frame.h:552
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
AVOption.
Definition opt.h:428
#define src
Definition vp8dsp.c:248