1 /*
2 * Copyright (c) 2019 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
27
28 #define MAX_OVERSAMPLE 64
29
41 };
42
46
50
53
60
63
65 int nb_samples,
int channels,
int start,
int end);
67
68 #define OFFSET(x) offsetof(ASoftClipContext, x)
69 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
70
87 };
88
90
92 double frequency,
94 {
96 double alpha = sin(w0) / (2 * 0.8);
98
100 s->da1 = -2 * cos(w0);
102 s->db0 = (1 - cos(w0)) / 2;
103 s->db1 = 1 - cos(w0);
104 s->db2 = (1 - cos(w0)) / 2;
105
112
113 factor = (
s->da0 +
s->da1 +
s->da2) / (
s->db0 +
s->db1 +
s->db2);
117
124 }
125
128 {
129 float dst;
130
131 dst =
src *
s->fb0 +
w[0];
132 w[0] =
s->fb1 *
src +
w[1] -
s->fa1 * dst;
133 w[1] =
s->fb2 *
src -
s->fa2 * dst;
134
135 return dst;
136 }
137
139 void **dptr, const void **sptr,
141 int start, int end)
142 {
144 const int nb_osamples = nb_samples *
oversample;
150
151 for (
int c = start;
c < end;
c++) {
152 float *
w = (
float *)(
s->frame[0]->extended_data[
c]) + 2 * (
oversample - 1);
153 const float *
src = sptr[
c];
154 float *dst = dptr[
c];
155
156 for (int n = 0; n < nb_samples; n++) {
158
161 }
162
163 for (int n = 0; n < nb_osamples && oversample > 1; n++)
165
168 for (int n = 0; n < nb_osamples; n++) {
170 dst[n] *= gain;
171 }
172 break;
174 for (int n = 0; n < nb_osamples; n++) {
176 dst[n] *= gain;
177 }
178 break;
180 for (int n = 0; n < nb_osamples; n++) {
182 dst[n] *= gain;
183 }
184 break;
186 for (int n = 0; n < nb_osamples; n++) {
188
191 else
193 dst[n] *= gain;
194 }
195 break;
197 for (int n = 0; n < nb_osamples; n++) {
198 dst[n] = 2.f / (1.f +
expf(-2.
f * dst[n] *
factor)) - 1.;
199 dst[n] *= gain;
200 }
201 break;
203 for (int n = 0; n < nb_osamples; n++) {
205
207 dst[n] *= gain;
208 }
209 break;
211 for (int n = 0; n < nb_osamples; n++) {
213
216 else
218 dst[n] *= gain;
219 }
220 break;
222 for (int n = 0; n < nb_osamples; n++) {
224
227 else
229 dst[n] *= gain;
230 }
231 break;
233 for (int n = 0; n < nb_osamples; n++) {
234 dst[n] = erff(dst[n] *
factor);
235 dst[n] *= gain;
236 }
237 break;
238 default:
240 }
241
242 w = (
float *)(
s->frame[1]->extended_data[
c]) + 2 * (
oversample - 1);
243 for (int n = 0; n < nb_osamples && oversample > 1; n++)
245
246 for (int n = 0; n < nb_samples; n++)
248 }
249 }
250
252 double src,
double *
w)
253 {
254 double dst;
255
256 dst =
src *
s->db0 +
w[0];
257 w[0] =
s->db1 *
src +
w[1] -
s->da1 * dst;
258 w[1] =
s->db2 *
src -
s->da2 * dst;
259
260 return dst;
261 }
262
264 void **dptr, const void **sptr,
266 int start, int end)
267 {
269 const int nb_osamples = nb_samples *
oversample;
275
276 for (
int c = start;
c < end;
c++) {
277 double *
w = (
double *)(
s->frame[0]->extended_data[
c]) + 2 * (
oversample - 1);
278 const double *
src = sptr[
c];
279 double *dst = dptr[
c];
280
281 for (int n = 0; n < nb_samples; n++) {
283
286 }
287
288 for (int n = 0; n < nb_osamples && oversample > 1; n++)
290
293 for (int n = 0; n < nb_osamples; n++) {
295 dst[n] *= gain;
296 }
297 break;
299 for (int n = 0; n < nb_osamples; n++) {
301 dst[n] *= gain;
302 }
303 break;
305 for (int n = 0; n < nb_osamples; n++) {
307 dst[n] *= gain;
308 }
309 break;
311 for (int n = 0; n < nb_osamples; n++) {
313
316 else
318 dst[n] *= gain;
319 }
320 break;
322 for (int n = 0; n < nb_osamples; n++) {
323 dst[n] = 2. / (1. +
exp(-2. * dst[n] *
factor)) - 1.;
324 dst[n] *= gain;
325 }
326 break;
328 for (int n = 0; n < nb_osamples; n++) {
330
332 dst[n] *= gain;
333 }
334 break;
336 for (int n = 0; n < nb_osamples; n++) {
338
341 else
343 dst[n] *= gain;
344 }
345 break;
347 for (int n = 0; n < nb_osamples; n++) {
349
352 else
354 dst[n] *= gain;
355 }
356 break;
358 for (int n = 0; n < nb_osamples; n++) {
360 dst[n] *= gain;
361 }
362 break;
363 default:
365 }
366
367 w = (
double *)(
s->frame[1]->extended_data[
c]) + 2 * (
oversample - 1);
368 for (int n = 0; n < nb_osamples && oversample > 1; n++)
370
371 for (int n = 0; n < nb_samples; n++)
373 }
374 }
375
377 {
380
385 }
386
389 if (!
s->frame[0] || !
s->frame[1])
391
394 }
395
396 return 0;
397 }
398
404
406 {
412 const int nb_samples =
td->nb_samples;
413 const int start = (
channels * jobnr) / nb_jobs;
414 const int end = (
channels * (jobnr+1)) / nb_jobs;
415
418
419 return 0;
420 }
421
423 {
430
433 } else {
438 }
440 }
441
444
447 td.nb_samples = nb_samples;
451
454
455 out->nb_samples /=
s->oversample;
457 }
458
460 {
462
465 }
466
468 {
473 },
474 };
475
477 {
480 },
481 };
482
487 .priv_class = &asoftclip_class,
495 };