Browse code

lavfi: drop af_volume_stefano.c in favor of af_volume_justin.c

Justin's version has more features but is otherwise equivalent from the
point of view of the syntax.

Stefano Sabatini authored on 2012/12/08 20:07:03
Showing 7 changed files
... ...
@@ -829,56 +829,6 @@ out
829 829
 Convert the audio sample format, sample rate and channel layout. This filter is
830 830
 not meant to be used directly.
831 831
 
832
-@section volume
833
-
834
-Adjust the input audio volume.
835
-
836
-The filter accepts exactly one parameter @var{vol}, which expresses
837
-how the audio volume will be increased or decreased.
838
-
839
-Output values are clipped to the maximum value.
840
-
841
-If @var{vol} is expressed as a decimal number, the output audio
842
-volume is given by the relation:
843
-@example
844
-@var{output_volume} = @var{vol} * @var{input_volume}
845
-@end example
846
-
847
-If @var{vol} is expressed as a decimal number followed by the string
848
-"dB", the value represents the requested change in decibels of the
849
-input audio power, and the output audio volume is given by the
850
-relation:
851
-@example
852
-@var{output_volume} = 10^(@var{vol}/20) * @var{input_volume}
853
-@end example
854
-
855
-Otherwise @var{vol} is considered an expression and its evaluated
856
-value is used for computing the output audio volume according to the
857
-first relation.
858
-
859
-Default value for @var{vol} is 1.0.
860
-
861
-@subsection Examples
862
-
863
-@itemize
864
-@item
865
-Half the input audio volume:
866
-@example
867
-volume=0.5
868
-@end example
869
-
870
-The above example is equivalent to:
871
-@example
872
-volume=1/2
873
-@end example
874
-
875
-@item
876
-Decrease input audio power by 12 decibels:
877
-@example
878
-volume=-12dB
879
-@end example
880
-@end itemize
881
-
882 832
 @section volumedetect
883 833
 
884 834
 Detect the volume of the input video.
... ...
@@ -919,7 +869,7 @@ There are 6 samples at -4 dB, 62 at -5 dB, 286 at -6 dB, etc.
919 919
 In other words, raising the volume by +4 dB does not cause any clipping,
920 920
 raising it by +5 dB causes clipping for 6 samples, etc.
921 921
 
922
-@section volume_justin
922
+@section volume
923 923
 
924 924
 Adjust the input audio volume.
925 925
 
... ...
@@ -966,15 +916,21 @@ precision of the volume scaling.
966 966
 @item
967 967
 Halve the input audio volume:
968 968
 @example
969
-volume_justin=volume=0.5
970
-volume_justin=volume=1/2
971
-volume_justin=volume=-6.0206dB
969
+volume=volume=0.5
970
+volume=volume=1/2
971
+volume=volume=-6.0206dB
972
+@end example
973
+
974
+In all the above example the named key for @option{volume} can be
975
+omitted, for example like in:
976
+@example
977
+volume=0.5
972 978
 @end example
973 979
 
974 980
 @item
975 981
 Increase input audio power by 6 decibels using fixed-point precision:
976 982
 @example
977
-volume_justin=volume=6dB:precision=fixed
983
+volume=volume=6dB:precision=fixed
978 984
 @end example
979 985
 @end itemize
980 986
 
... ...
@@ -71,8 +71,7 @@ OBJS-$(CONFIG_JOIN_FILTER)                   += af_join.o
71 71
 OBJS-$(CONFIG_PAN_FILTER)                    += af_pan.o
72 72
 OBJS-$(CONFIG_RESAMPLE_FILTER)               += af_resample.o
73 73
 OBJS-$(CONFIG_SILENCEDETECT_FILTER)          += af_silencedetect.o
74
-OBJS-$(CONFIG_VOLUME_FILTER)                 += af_volume_stefano.o
75
-OBJS-$(CONFIG_VOLUME_JUSTIN_FILTER)          += af_volume_justin.o
74
+OBJS-$(CONFIG_VOLUME_FILTER)                 += af_volume.o
76 75
 OBJS-$(CONFIG_VOLUMEDETECT_FILTER)           += af_volumedetect.o
77 76
 
78 77
 OBJS-$(CONFIG_AEVALSRC_FILTER)               += asrc_aevalsrc.o
79 78
new file mode 100644
... ...
@@ -0,0 +1,311 @@
0
+/*
1
+ * Copyright (c) 2011 Stefano Sabatini
2
+ * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
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
+/**
22
+ * @file
23
+ * audio volume filter
24
+ */
25
+
26
+#include "libavutil/audioconvert.h"
27
+#include "libavutil/common.h"
28
+#include "libavutil/eval.h"
29
+#include "libavutil/float_dsp.h"
30
+#include "libavutil/opt.h"
31
+#include "audio.h"
32
+#include "avfilter.h"
33
+#include "formats.h"
34
+#include "internal.h"
35
+#include "af_volume.h"
36
+
37
+static const char *precision_str[] = {
38
+    "fixed", "float", "double"
39
+};
40
+
41
+#define OFFSET(x) offsetof(VolumeContext, x)
42
+#define A AV_OPT_FLAG_AUDIO_PARAM
43
+#define F AV_OPT_FLAG_FILTERING_PARAM
44
+
45
+static const AVOption volume_options[] = {
46
+    { "volume", "set volume adjustment",
47
+            OFFSET(volume), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, 0, 0x7fffff, A|F },
48
+    { "precision", "select mathematical precision",
49
+            OFFSET(precision), AV_OPT_TYPE_INT, { .i64 = PRECISION_FLOAT }, PRECISION_FIXED, PRECISION_DOUBLE, A|F, "precision" },
50
+        { "fixed",  "select 8-bit fixed-point",     0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FIXED  }, INT_MIN, INT_MAX, A|F, "precision" },
51
+        { "float",  "select 32-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FLOAT  }, INT_MIN, INT_MAX, A|F, "precision" },
52
+        { "double", "select 64-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_DOUBLE }, INT_MIN, INT_MAX, A|F, "precision" },
53
+    { NULL },
54
+};
55
+
56
+AVFILTER_DEFINE_CLASS(volume);
57
+
58
+static av_cold int init(AVFilterContext *ctx, const char *args)
59
+{
60
+    VolumeContext *vol = ctx->priv;
61
+    static const char *shorthand[] = { "volume", "precision", NULL };
62
+    int ret;
63
+
64
+    vol->class = &volume_class;
65
+    av_opt_set_defaults(vol);
66
+
67
+    if ((ret = av_opt_set_from_string(vol, args, shorthand, "=", ":")) < 0)
68
+        return ret;
69
+
70
+    if (vol->precision == PRECISION_FIXED) {
71
+        vol->volume_i = (int)(vol->volume * 256 + 0.5);
72
+        vol->volume   = vol->volume_i / 256.0;
73
+        av_log(ctx, AV_LOG_VERBOSE, "volume:(%d/256)(%f)(%1.2fdB) precision:fixed\n",
74
+               vol->volume_i, vol->volume, 20.0*log(vol->volume)/M_LN10);
75
+    } else {
76
+        av_log(ctx, AV_LOG_VERBOSE, "volume:(%f)(%1.2fdB) precision:%s\n",
77
+               vol->volume, 20.0*log(vol->volume)/M_LN10,
78
+               precision_str[vol->precision]);
79
+    }
80
+
81
+    av_opt_free(vol);
82
+    return ret;
83
+}
84
+
85
+static int query_formats(AVFilterContext *ctx)
86
+{
87
+    VolumeContext *vol = ctx->priv;
88
+    AVFilterFormats *formats = NULL;
89
+    AVFilterChannelLayouts *layouts;
90
+    static const enum AVSampleFormat sample_fmts[][7] = {
91
+        /* PRECISION_FIXED */
92
+        {
93
+            AV_SAMPLE_FMT_U8,
94
+            AV_SAMPLE_FMT_U8P,
95
+            AV_SAMPLE_FMT_S16,
96
+            AV_SAMPLE_FMT_S16P,
97
+            AV_SAMPLE_FMT_S32,
98
+            AV_SAMPLE_FMT_S32P,
99
+            AV_SAMPLE_FMT_NONE
100
+        },
101
+        /* PRECISION_FLOAT */
102
+        {
103
+            AV_SAMPLE_FMT_FLT,
104
+            AV_SAMPLE_FMT_FLTP,
105
+            AV_SAMPLE_FMT_NONE
106
+        },
107
+        /* PRECISION_DOUBLE */
108
+        {
109
+            AV_SAMPLE_FMT_DBL,
110
+            AV_SAMPLE_FMT_DBLP,
111
+            AV_SAMPLE_FMT_NONE
112
+        }
113
+    };
114
+
115
+    layouts = ff_all_channel_layouts();
116
+    if (!layouts)
117
+        return AVERROR(ENOMEM);
118
+    ff_set_common_channel_layouts(ctx, layouts);
119
+
120
+    formats = ff_make_format_list(sample_fmts[vol->precision]);
121
+    if (!formats)
122
+        return AVERROR(ENOMEM);
123
+    ff_set_common_formats(ctx, formats);
124
+
125
+    formats = ff_all_samplerates();
126
+    if (!formats)
127
+        return AVERROR(ENOMEM);
128
+    ff_set_common_samplerates(ctx, formats);
129
+
130
+    return 0;
131
+}
132
+
133
+static inline void scale_samples_u8(uint8_t *dst, const uint8_t *src,
134
+                                    int nb_samples, int volume)
135
+{
136
+    int i;
137
+    for (i = 0; i < nb_samples; i++)
138
+        dst[i] = av_clip_uint8(((((int64_t)src[i] - 128) * volume + 128) >> 8) + 128);
139
+}
140
+
141
+static inline void scale_samples_u8_small(uint8_t *dst, const uint8_t *src,
142
+                                          int nb_samples, int volume)
143
+{
144
+    int i;
145
+    for (i = 0; i < nb_samples; i++)
146
+        dst[i] = av_clip_uint8((((src[i] - 128) * volume + 128) >> 8) + 128);
147
+}
148
+
149
+static inline void scale_samples_s16(uint8_t *dst, const uint8_t *src,
150
+                                     int nb_samples, int volume)
151
+{
152
+    int i;
153
+    int16_t *smp_dst       = (int16_t *)dst;
154
+    const int16_t *smp_src = (const int16_t *)src;
155
+    for (i = 0; i < nb_samples; i++)
156
+        smp_dst[i] = av_clip_int16(((int64_t)smp_src[i] * volume + 128) >> 8);
157
+}
158
+
159
+static inline void scale_samples_s16_small(uint8_t *dst, const uint8_t *src,
160
+                                           int nb_samples, int volume)
161
+{
162
+    int i;
163
+    int16_t *smp_dst       = (int16_t *)dst;
164
+    const int16_t *smp_src = (const int16_t *)src;
165
+    for (i = 0; i < nb_samples; i++)
166
+        smp_dst[i] = av_clip_int16((smp_src[i] * volume + 128) >> 8);
167
+}
168
+
169
+static inline void scale_samples_s32(uint8_t *dst, const uint8_t *src,
170
+                                     int nb_samples, int volume)
171
+{
172
+    int i;
173
+    int32_t *smp_dst       = (int32_t *)dst;
174
+    const int32_t *smp_src = (const int32_t *)src;
175
+    for (i = 0; i < nb_samples; i++)
176
+        smp_dst[i] = av_clipl_int32((((int64_t)smp_src[i] * volume + 128) >> 8));
177
+}
178
+
179
+static void volume_init(VolumeContext *vol)
180
+{
181
+    vol->samples_align = 1;
182
+
183
+    switch (av_get_packed_sample_fmt(vol->sample_fmt)) {
184
+    case AV_SAMPLE_FMT_U8:
185
+        if (vol->volume_i < 0x1000000)
186
+            vol->scale_samples = scale_samples_u8_small;
187
+        else
188
+            vol->scale_samples = scale_samples_u8;
189
+        break;
190
+    case AV_SAMPLE_FMT_S16:
191
+        if (vol->volume_i < 0x10000)
192
+            vol->scale_samples = scale_samples_s16_small;
193
+        else
194
+            vol->scale_samples = scale_samples_s16;
195
+        break;
196
+    case AV_SAMPLE_FMT_S32:
197
+        vol->scale_samples = scale_samples_s32;
198
+        break;
199
+    case AV_SAMPLE_FMT_FLT:
200
+        avpriv_float_dsp_init(&vol->fdsp, 0);
201
+        vol->samples_align = 4;
202
+        break;
203
+    case AV_SAMPLE_FMT_DBL:
204
+        avpriv_float_dsp_init(&vol->fdsp, 0);
205
+        vol->samples_align = 8;
206
+        break;
207
+    }
208
+
209
+    if (ARCH_X86)
210
+        ff_volume_init_x86(vol);
211
+}
212
+
213
+static int config_output(AVFilterLink *outlink)
214
+{
215
+    AVFilterContext *ctx = outlink->src;
216
+    VolumeContext *vol   = ctx->priv;
217
+    AVFilterLink *inlink = ctx->inputs[0];
218
+
219
+    vol->sample_fmt = inlink->format;
220
+    vol->channels   = av_get_channel_layout_nb_channels(inlink->channel_layout);
221
+    vol->planes     = av_sample_fmt_is_planar(inlink->format) ? vol->channels : 1;
222
+
223
+    volume_init(vol);
224
+
225
+    return 0;
226
+}
227
+
228
+static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
229
+{
230
+    VolumeContext *vol    = inlink->dst->priv;
231
+    AVFilterLink *outlink = inlink->dst->outputs[0];
232
+    int nb_samples        = buf->audio->nb_samples;
233
+    AVFilterBufferRef *out_buf;
234
+
235
+    if (vol->volume == 1.0 || vol->volume_i == 256)
236
+        return ff_filter_frame(outlink, buf);
237
+
238
+    /* do volume scaling in-place if input buffer is writable */
239
+    if (buf->perms & AV_PERM_WRITE) {
240
+        out_buf = buf;
241
+    } else {
242
+        out_buf = ff_get_audio_buffer(inlink, AV_PERM_WRITE, nb_samples);
243
+        if (!out_buf)
244
+            return AVERROR(ENOMEM);
245
+        out_buf->pts = buf->pts;
246
+    }
247
+
248
+    if (vol->precision != PRECISION_FIXED || vol->volume_i > 0) {
249
+        int p, plane_samples;
250
+
251
+        if (av_sample_fmt_is_planar(buf->format))
252
+            plane_samples = FFALIGN(nb_samples, vol->samples_align);
253
+        else
254
+            plane_samples = FFALIGN(nb_samples * vol->channels, vol->samples_align);
255
+
256
+        if (vol->precision == PRECISION_FIXED) {
257
+            for (p = 0; p < vol->planes; p++) {
258
+                vol->scale_samples(out_buf->extended_data[p],
259
+                                   buf->extended_data[p], plane_samples,
260
+                                   vol->volume_i);
261
+            }
262
+        } else if (av_get_packed_sample_fmt(vol->sample_fmt) == AV_SAMPLE_FMT_FLT) {
263
+            for (p = 0; p < vol->planes; p++) {
264
+                vol->fdsp.vector_fmul_scalar((float *)out_buf->extended_data[p],
265
+                                             (const float *)buf->extended_data[p],
266
+                                             vol->volume, plane_samples);
267
+            }
268
+        } else {
269
+            for (p = 0; p < vol->planes; p++) {
270
+                vol->fdsp.vector_dmul_scalar((double *)out_buf->extended_data[p],
271
+                                             (const double *)buf->extended_data[p],
272
+                                             vol->volume, plane_samples);
273
+            }
274
+        }
275
+    }
276
+
277
+    if (buf != out_buf)
278
+        avfilter_unref_buffer(buf);
279
+
280
+    return ff_filter_frame(outlink, out_buf);
281
+}
282
+
283
+static const AVFilterPad avfilter_af_volume_inputs[] = {
284
+    {
285
+        .name           = "default",
286
+        .type           = AVMEDIA_TYPE_AUDIO,
287
+        .filter_frame   = filter_frame,
288
+    },
289
+    { NULL }
290
+};
291
+
292
+static const AVFilterPad avfilter_af_volume_outputs[] = {
293
+    {
294
+        .name         = "default",
295
+        .type         = AVMEDIA_TYPE_AUDIO,
296
+        .config_props = config_output,
297
+    },
298
+    { NULL }
299
+};
300
+
301
+AVFilter avfilter_af_volume = {
302
+    .name           = "volume",
303
+    .description    = NULL_IF_CONFIG_SMALL("Change input volume."),
304
+    .query_formats  = query_formats,
305
+    .priv_size      = sizeof(VolumeContext),
306
+    .init           = init,
307
+    .inputs         = avfilter_af_volume_inputs,
308
+    .outputs        = avfilter_af_volume_outputs,
309
+    .priv_class     = &volume_class,
310
+};
0 311
deleted file mode 100644
... ...
@@ -1,311 +0,0 @@
1
-/*
2
- * Copyright (c) 2011 Stefano Sabatini
3
- * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
4
- *
5
- * This file is part of FFmpeg.
6
- *
7
- * FFmpeg is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * FFmpeg is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with FFmpeg; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- */
21
-
22
-/**
23
- * @file
24
- * audio volume filter
25
- */
26
-
27
-#include "libavutil/audioconvert.h"
28
-#include "libavutil/common.h"
29
-#include "libavutil/eval.h"
30
-#include "libavutil/float_dsp.h"
31
-#include "libavutil/opt.h"
32
-#include "audio.h"
33
-#include "avfilter.h"
34
-#include "formats.h"
35
-#include "internal.h"
36
-#include "af_volume.h"
37
-
38
-static const char *precision_str[] = {
39
-    "fixed", "float", "double"
40
-};
41
-
42
-#define OFFSET(x) offsetof(VolumeContext, x)
43
-#define A AV_OPT_FLAG_AUDIO_PARAM
44
-#define F AV_OPT_FLAG_FILTERING_PARAM
45
-
46
-static const AVOption volume_options[] = {
47
-    { "volume", "set volume adjustment",
48
-            OFFSET(volume), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, 0, 0x7fffff, A|F },
49
-    { "precision", "select mathematical precision",
50
-            OFFSET(precision), AV_OPT_TYPE_INT, { .i64 = PRECISION_FLOAT }, PRECISION_FIXED, PRECISION_DOUBLE, A|F, "precision" },
51
-        { "fixed",  "select 8-bit fixed-point",     0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FIXED  }, INT_MIN, INT_MAX, A|F, "precision" },
52
-        { "float",  "select 32-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FLOAT  }, INT_MIN, INT_MAX, A|F, "precision" },
53
-        { "double", "select 64-bit floating-point", 0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_DOUBLE }, INT_MIN, INT_MAX, A|F, "precision" },
54
-    { NULL },
55
-};
56
-
57
-AVFILTER_DEFINE_CLASS(volume);
58
-
59
-static av_cold int init(AVFilterContext *ctx, const char *args)
60
-{
61
-    VolumeContext *vol = ctx->priv;
62
-    static const char *shorthand[] = { "volume", "precision", NULL };
63
-    int ret;
64
-
65
-    vol->class = &volume_class;
66
-    av_opt_set_defaults(vol);
67
-
68
-    if ((ret = av_opt_set_from_string(vol, args, shorthand, "=", ":")) < 0)
69
-        return ret;
70
-
71
-    if (vol->precision == PRECISION_FIXED) {
72
-        vol->volume_i = (int)(vol->volume * 256 + 0.5);
73
-        vol->volume   = vol->volume_i / 256.0;
74
-        av_log(ctx, AV_LOG_VERBOSE, "volume:(%d/256)(%f)(%1.2fdB) precision:fixed\n",
75
-               vol->volume_i, vol->volume, 20.0*log(vol->volume)/M_LN10);
76
-    } else {
77
-        av_log(ctx, AV_LOG_VERBOSE, "volume:(%f)(%1.2fdB) precision:%s\n",
78
-               vol->volume, 20.0*log(vol->volume)/M_LN10,
79
-               precision_str[vol->precision]);
80
-    }
81
-
82
-    av_opt_free(vol);
83
-    return ret;
84
-}
85
-
86
-static int query_formats(AVFilterContext *ctx)
87
-{
88
-    VolumeContext *vol = ctx->priv;
89
-    AVFilterFormats *formats = NULL;
90
-    AVFilterChannelLayouts *layouts;
91
-    static const enum AVSampleFormat sample_fmts[][7] = {
92
-        /* PRECISION_FIXED */
93
-        {
94
-            AV_SAMPLE_FMT_U8,
95
-            AV_SAMPLE_FMT_U8P,
96
-            AV_SAMPLE_FMT_S16,
97
-            AV_SAMPLE_FMT_S16P,
98
-            AV_SAMPLE_FMT_S32,
99
-            AV_SAMPLE_FMT_S32P,
100
-            AV_SAMPLE_FMT_NONE
101
-        },
102
-        /* PRECISION_FLOAT */
103
-        {
104
-            AV_SAMPLE_FMT_FLT,
105
-            AV_SAMPLE_FMT_FLTP,
106
-            AV_SAMPLE_FMT_NONE
107
-        },
108
-        /* PRECISION_DOUBLE */
109
-        {
110
-            AV_SAMPLE_FMT_DBL,
111
-            AV_SAMPLE_FMT_DBLP,
112
-            AV_SAMPLE_FMT_NONE
113
-        }
114
-    };
115
-
116
-    layouts = ff_all_channel_layouts();
117
-    if (!layouts)
118
-        return AVERROR(ENOMEM);
119
-    ff_set_common_channel_layouts(ctx, layouts);
120
-
121
-    formats = ff_make_format_list(sample_fmts[vol->precision]);
122
-    if (!formats)
123
-        return AVERROR(ENOMEM);
124
-    ff_set_common_formats(ctx, formats);
125
-
126
-    formats = ff_all_samplerates();
127
-    if (!formats)
128
-        return AVERROR(ENOMEM);
129
-    ff_set_common_samplerates(ctx, formats);
130
-
131
-    return 0;
132
-}
133
-
134
-static inline void scale_samples_u8(uint8_t *dst, const uint8_t *src,
135
-                                    int nb_samples, int volume)
136
-{
137
-    int i;
138
-    for (i = 0; i < nb_samples; i++)
139
-        dst[i] = av_clip_uint8(((((int64_t)src[i] - 128) * volume + 128) >> 8) + 128);
140
-}
141
-
142
-static inline void scale_samples_u8_small(uint8_t *dst, const uint8_t *src,
143
-                                          int nb_samples, int volume)
144
-{
145
-    int i;
146
-    for (i = 0; i < nb_samples; i++)
147
-        dst[i] = av_clip_uint8((((src[i] - 128) * volume + 128) >> 8) + 128);
148
-}
149
-
150
-static inline void scale_samples_s16(uint8_t *dst, const uint8_t *src,
151
-                                     int nb_samples, int volume)
152
-{
153
-    int i;
154
-    int16_t *smp_dst       = (int16_t *)dst;
155
-    const int16_t *smp_src = (const int16_t *)src;
156
-    for (i = 0; i < nb_samples; i++)
157
-        smp_dst[i] = av_clip_int16(((int64_t)smp_src[i] * volume + 128) >> 8);
158
-}
159
-
160
-static inline void scale_samples_s16_small(uint8_t *dst, const uint8_t *src,
161
-                                           int nb_samples, int volume)
162
-{
163
-    int i;
164
-    int16_t *smp_dst       = (int16_t *)dst;
165
-    const int16_t *smp_src = (const int16_t *)src;
166
-    for (i = 0; i < nb_samples; i++)
167
-        smp_dst[i] = av_clip_int16((smp_src[i] * volume + 128) >> 8);
168
-}
169
-
170
-static inline void scale_samples_s32(uint8_t *dst, const uint8_t *src,
171
-                                     int nb_samples, int volume)
172
-{
173
-    int i;
174
-    int32_t *smp_dst       = (int32_t *)dst;
175
-    const int32_t *smp_src = (const int32_t *)src;
176
-    for (i = 0; i < nb_samples; i++)
177
-        smp_dst[i] = av_clipl_int32((((int64_t)smp_src[i] * volume + 128) >> 8));
178
-}
179
-
180
-static void volume_init(VolumeContext *vol)
181
-{
182
-    vol->samples_align = 1;
183
-
184
-    switch (av_get_packed_sample_fmt(vol->sample_fmt)) {
185
-    case AV_SAMPLE_FMT_U8:
186
-        if (vol->volume_i < 0x1000000)
187
-            vol->scale_samples = scale_samples_u8_small;
188
-        else
189
-            vol->scale_samples = scale_samples_u8;
190
-        break;
191
-    case AV_SAMPLE_FMT_S16:
192
-        if (vol->volume_i < 0x10000)
193
-            vol->scale_samples = scale_samples_s16_small;
194
-        else
195
-            vol->scale_samples = scale_samples_s16;
196
-        break;
197
-    case AV_SAMPLE_FMT_S32:
198
-        vol->scale_samples = scale_samples_s32;
199
-        break;
200
-    case AV_SAMPLE_FMT_FLT:
201
-        avpriv_float_dsp_init(&vol->fdsp, 0);
202
-        vol->samples_align = 4;
203
-        break;
204
-    case AV_SAMPLE_FMT_DBL:
205
-        avpriv_float_dsp_init(&vol->fdsp, 0);
206
-        vol->samples_align = 8;
207
-        break;
208
-    }
209
-
210
-    if (ARCH_X86)
211
-        ff_volume_init_x86(vol);
212
-}
213
-
214
-static int config_output(AVFilterLink *outlink)
215
-{
216
-    AVFilterContext *ctx = outlink->src;
217
-    VolumeContext *vol   = ctx->priv;
218
-    AVFilterLink *inlink = ctx->inputs[0];
219
-
220
-    vol->sample_fmt = inlink->format;
221
-    vol->channels   = av_get_channel_layout_nb_channels(inlink->channel_layout);
222
-    vol->planes     = av_sample_fmt_is_planar(inlink->format) ? vol->channels : 1;
223
-
224
-    volume_init(vol);
225
-
226
-    return 0;
227
-}
228
-
229
-static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
230
-{
231
-    VolumeContext *vol    = inlink->dst->priv;
232
-    AVFilterLink *outlink = inlink->dst->outputs[0];
233
-    int nb_samples        = buf->audio->nb_samples;
234
-    AVFilterBufferRef *out_buf;
235
-
236
-    if (vol->volume == 1.0 || vol->volume_i == 256)
237
-        return ff_filter_frame(outlink, buf);
238
-
239
-    /* do volume scaling in-place if input buffer is writable */
240
-    if (buf->perms & AV_PERM_WRITE) {
241
-        out_buf = buf;
242
-    } else {
243
-        out_buf = ff_get_audio_buffer(inlink, AV_PERM_WRITE, nb_samples);
244
-        if (!out_buf)
245
-            return AVERROR(ENOMEM);
246
-        out_buf->pts = buf->pts;
247
-    }
248
-
249
-    if (vol->precision != PRECISION_FIXED || vol->volume_i > 0) {
250
-        int p, plane_samples;
251
-
252
-        if (av_sample_fmt_is_planar(buf->format))
253
-            plane_samples = FFALIGN(nb_samples, vol->samples_align);
254
-        else
255
-            plane_samples = FFALIGN(nb_samples * vol->channels, vol->samples_align);
256
-
257
-        if (vol->precision == PRECISION_FIXED) {
258
-            for (p = 0; p < vol->planes; p++) {
259
-                vol->scale_samples(out_buf->extended_data[p],
260
-                                   buf->extended_data[p], plane_samples,
261
-                                   vol->volume_i);
262
-            }
263
-        } else if (av_get_packed_sample_fmt(vol->sample_fmt) == AV_SAMPLE_FMT_FLT) {
264
-            for (p = 0; p < vol->planes; p++) {
265
-                vol->fdsp.vector_fmul_scalar((float *)out_buf->extended_data[p],
266
-                                             (const float *)buf->extended_data[p],
267
-                                             vol->volume, plane_samples);
268
-            }
269
-        } else {
270
-            for (p = 0; p < vol->planes; p++) {
271
-                vol->fdsp.vector_dmul_scalar((double *)out_buf->extended_data[p],
272
-                                             (const double *)buf->extended_data[p],
273
-                                             vol->volume, plane_samples);
274
-            }
275
-        }
276
-    }
277
-
278
-    if (buf != out_buf)
279
-        avfilter_unref_buffer(buf);
280
-
281
-    return ff_filter_frame(outlink, out_buf);
282
-}
283
-
284
-static const AVFilterPad avfilter_af_volume_inputs[] = {
285
-    {
286
-        .name           = "default",
287
-        .type           = AVMEDIA_TYPE_AUDIO,
288
-        .filter_frame   = filter_frame,
289
-    },
290
-    { NULL }
291
-};
292
-
293
-static const AVFilterPad avfilter_af_volume_outputs[] = {
294
-    {
295
-        .name         = "default",
296
-        .type         = AVMEDIA_TYPE_AUDIO,
297
-        .config_props = config_output,
298
-    },
299
-    { NULL }
300
-};
301
-
302
-AVFilter avfilter_af_volume_justin = {
303
-    .name           = "volume_justin",
304
-    .description    = NULL_IF_CONFIG_SMALL("Change input volume."),
305
-    .query_formats  = query_formats,
306
-    .priv_size      = sizeof(VolumeContext),
307
-    .init           = init,
308
-    .inputs         = avfilter_af_volume_inputs,
309
-    .outputs        = avfilter_af_volume_outputs,
310
-    .priv_class     = &volume_class,
311
-};
312 1
deleted file mode 100644
... ...
@@ -1,201 +0,0 @@
1
-/*
2
- * Copyright (c) 2011 Stefano Sabatini
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
-/**
22
- * @file
23
- * audio volume filter
24
- * based on ffmpeg.c code
25
- */
26
-
27
-#include "libavutil/channel_layout.h"
28
-#include "libavutil/eval.h"
29
-#include "audio.h"
30
-#include "avfilter.h"
31
-#include "formats.h"
32
-
33
-typedef struct {
34
-    double volume;
35
-    int    volume_i;
36
-} VolumeContext;
37
-
38
-static av_cold int init(AVFilterContext *ctx, const char *args)
39
-{
40
-    VolumeContext *vol = ctx->priv;
41
-    char *tail;
42
-    int ret = 0;
43
-
44
-    vol->volume = 1.0;
45
-
46
-    if (args) {
47
-        /* parse the number as a decimal number */
48
-        double d = strtod(args, &tail);
49
-
50
-        if (*tail) {
51
-            if (!strcmp(tail, "dB")) {
52
-                /* consider the argument an adjustement in decibels */
53
-                d = pow(10, d/20);
54
-            } else {
55
-                /* parse the argument as an expression */
56
-                ret = av_expr_parse_and_eval(&d, args, NULL, NULL,
57
-                                             NULL, NULL, NULL, NULL,
58
-                                             NULL, 0, ctx);
59
-            }
60
-        }
61
-
62
-        if (ret < 0) {
63
-            av_log(ctx, AV_LOG_ERROR,
64
-                   "Invalid volume argument '%s'\n", args);
65
-            return AVERROR(EINVAL);
66
-        }
67
-
68
-        if (d < 0 || d > 65536) { /* 65536 = INT_MIN / (128 * 256) */
69
-            av_log(ctx, AV_LOG_ERROR,
70
-                   "Negative or too big volume value %f\n", d);
71
-            return AVERROR(EINVAL);
72
-        }
73
-
74
-        vol->volume = d;
75
-    }
76
-
77
-    vol->volume_i = (int)(vol->volume * 256 + 0.5);
78
-    av_log(ctx, AV_LOG_VERBOSE, "volume=%f\n", vol->volume);
79
-    return 0;
80
-}
81
-
82
-static int query_formats(AVFilterContext *ctx)
83
-{
84
-    AVFilterFormats *formats = NULL;
85
-    AVFilterChannelLayouts *layouts;
86
-    enum AVSampleFormat sample_fmts[] = {
87
-        AV_SAMPLE_FMT_U8,
88
-        AV_SAMPLE_FMT_S16,
89
-        AV_SAMPLE_FMT_S32,
90
-        AV_SAMPLE_FMT_FLT,
91
-        AV_SAMPLE_FMT_DBL,
92
-        AV_SAMPLE_FMT_NONE
93
-    };
94
-
95
-    layouts = ff_all_channel_layouts();
96
-    if (!layouts)
97
-        return AVERROR(ENOMEM);
98
-    ff_set_common_channel_layouts(ctx, layouts);
99
-
100
-    formats = ff_make_format_list(sample_fmts);
101
-    if (!formats)
102
-        return AVERROR(ENOMEM);
103
-    ff_set_common_formats(ctx, formats);
104
-
105
-    formats = ff_all_samplerates();
106
-    if (!formats)
107
-        return AVERROR(ENOMEM);
108
-    ff_set_common_samplerates(ctx, formats);
109
-
110
-    return 0;
111
-}
112
-
113
-static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples)
114
-{
115
-    VolumeContext *vol = inlink->dst->priv;
116
-    AVFilterLink *outlink = inlink->dst->outputs[0];
117
-    const int nb_samples = insamples->audio->nb_samples *
118
-        av_get_channel_layout_nb_channels(insamples->audio->channel_layout);
119
-    const double volume   = vol->volume;
120
-    const int    volume_i = vol->volume_i;
121
-    int i;
122
-
123
-    if (volume_i != 256) {
124
-        switch (insamples->format) {
125
-        case AV_SAMPLE_FMT_U8:
126
-        {
127
-            uint8_t *p = (void *)insamples->data[0];
128
-            for (i = 0; i < nb_samples; i++) {
129
-                int v = (((*p - 128) * volume_i + 128) >> 8) + 128;
130
-                *p++ = av_clip_uint8(v);
131
-            }
132
-            break;
133
-        }
134
-        case AV_SAMPLE_FMT_S16:
135
-        {
136
-            int16_t *p = (void *)insamples->data[0];
137
-            for (i = 0; i < nb_samples; i++) {
138
-                int v = ((int64_t)*p * volume_i + 128) >> 8;
139
-                *p++ = av_clip_int16(v);
140
-            }
141
-            break;
142
-        }
143
-        case AV_SAMPLE_FMT_S32:
144
-        {
145
-            int32_t *p = (void *)insamples->data[0];
146
-            for (i = 0; i < nb_samples; i++) {
147
-                int64_t v = (((int64_t)*p * volume_i + 128) >> 8);
148
-                *p++ = av_clipl_int32(v);
149
-            }
150
-            break;
151
-        }
152
-        case AV_SAMPLE_FMT_FLT:
153
-        {
154
-            float *p = (void *)insamples->data[0];
155
-            float scale = (float)volume;
156
-            for (i = 0; i < nb_samples; i++) {
157
-                *p++ *= scale;
158
-            }
159
-            break;
160
-        }
161
-        case AV_SAMPLE_FMT_DBL:
162
-        {
163
-            double *p = (void *)insamples->data[0];
164
-            for (i = 0; i < nb_samples; i++) {
165
-                *p *= volume;
166
-                p++;
167
-            }
168
-            break;
169
-        }
170
-        }
171
-    }
172
-    return ff_filter_frame(outlink, insamples);
173
-}
174
-
175
-static const AVFilterPad volume_inputs[] = {
176
-    {
177
-        .name         = "default",
178
-        .type         = AVMEDIA_TYPE_AUDIO,
179
-        .filter_frame = filter_frame,
180
-        .min_perms    = AV_PERM_READ | AV_PERM_WRITE,
181
-    },
182
-    { NULL },
183
-};
184
-
185
-static const AVFilterPad volume_outputs[] = {
186
-    {
187
-        .name = "default",
188
-        .type = AVMEDIA_TYPE_AUDIO,
189
-    },
190
-    { NULL },
191
-};
192
-
193
-AVFilter avfilter_af_volume = {
194
-    .name           = "volume",
195
-    .description    = NULL_IF_CONFIG_SMALL("Change input volume."),
196
-    .query_formats  = query_formats,
197
-    .priv_size      = sizeof(VolumeContext),
198
-    .init           = init,
199
-    .inputs         = volume_inputs,
200
-    .outputs        = volume_outputs,
201
-};
... ...
@@ -64,7 +64,6 @@ void avfilter_register_all(void)
64 64
     REGISTER_FILTER (RESAMPLE,    resample,    af);
65 65
     REGISTER_FILTER (SILENCEDETECT, silencedetect, af);
66 66
     REGISTER_FILTER (VOLUME,      volume,      af);
67
-    REGISTER_FILTER (VOLUME_JUSTIN, volume_justin, af);
68 67
     REGISTER_FILTER (VOLUMEDETECT,volumedetect,af);
69 68
 
70 69
     REGISTER_FILTER (AEVALSRC,    aevalsrc,    asrc);
... ...
@@ -29,8 +29,8 @@
29 29
 #include "libavutil/avutil.h"
30 30
 
31 31
 #define LIBAVFILTER_VERSION_MAJOR  3
32
-#define LIBAVFILTER_VERSION_MINOR  25
33
-#define LIBAVFILTER_VERSION_MICRO 102
32
+#define LIBAVFILTER_VERSION_MINOR  26
33
+#define LIBAVFILTER_VERSION_MICRO 100
34 34
 
35 35
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 36
                                                LIBAVFILTER_VERSION_MINOR, \