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
37
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
47 { "volume", "set volume adjustment",
49 { "precision", "select mathematical precision",
54 { NULL }
55 };
56
58
60 {
62
68 } else {
72 }
73
74 return 0;
75 }
76
78 {
91 },
96 },
101 }
102 };
103
105 if (!layouts)
108
110 if (!formats)
113
115 if (!formats)
118
119 return 0;
120 }
121
123 int nb_samples, int volume)
124 {
125 int i;
126 for (i = 0; i < nb_samples; i++)
127 dst[i] = av_clip_uint8(((((int64_t)src[i] - 128) * volume + 128) >> 8) + 128);
128 }
129
131 int nb_samples, int volume)
132 {
133 int i;
134 for (i = 0; i < nb_samples; i++)
135 dst[i] = av_clip_uint8((((src[i] - 128) * volume + 128) >> 8) + 128);
136 }
137
139 int nb_samples, int volume)
140 {
141 int i;
142 int16_t *smp_dst = (int16_t *)dst;
143 const int16_t *smp_src = (const int16_t *)src;
144 for (i = 0; i < nb_samples; i++)
145 smp_dst[i] = av_clip_int16(((int64_t)smp_src[i] * volume + 128) >> 8);
146 }
147
149 int nb_samples, int volume)
150 {
151 int i;
152 int16_t *smp_dst = (int16_t *)dst;
153 const int16_t *smp_src = (const int16_t *)src;
154 for (i = 0; i < nb_samples; i++)
155 smp_dst[i] = av_clip_int16((smp_src[i] * volume + 128) >> 8);
156 }
157
159 int nb_samples, int volume)
160 {
161 int i;
164 for (i = 0; i < nb_samples; i++)
165 smp_dst[i] = av_clipl_int32((((int64_t)smp_src[i] * volume + 128) >> 8));
166 }
167
169 {
171
176 else
178 break;
182 else
184 break;
187 break;
191 break;
195 break;
196 }
197
198 if (ARCH_X86)
200 }
201
203 {
207
211
213
214 return 0;
215 }
216
218 {
223
226
227 /* do volume scaling in-place if input buffer is writable */
230 } else {
232 if (!out_buf)
235 }
236
238 int p, plane_samples;
239
242 else
244
246 for (p = 0; p < vol->
planes; p++) {
250 }
252 for (p = 0; p < vol->
planes; p++) {
255 vol->
volume, plane_samples);
256 }
257 } else {
258 for (p = 0; p < vol->
planes; p++) {
261 vol->
volume, plane_samples);
262 }
263 }
264 }
265
266 if (buf != out_buf)
268
270 }
271
273 {
277 },
278 { NULL }
279 };
280
282 {
286 },
287 { NULL }
288 };
289
295 .priv_class = &volume_class,
297 .
inputs = avfilter_af_volume_inputs,
298 .
outputs = avfilter_af_volume_outputs,
300 };