1 /*
2 * Copyright (c) 2001-2010 Krzysztof Foltman, Markus Schmidt, Thor Harald Johansen, Vladimir Sadovnikov and others
3 * Copyright (c) 2015 Paul B Mahol
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
27
35
41
42 #define OFFSET(x) offsetof(CompensationDelayContext, x)
43 #define A AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
44
53 };
54
56
57 // The maximum distance for options
58 #define COMP_DELAY_MAX_DISTANCE (100.0 * 100.0 + 100.0 * 1.0 + 1.0)
59 // The actual speed of sound in normal conditions
60 #define COMP_DELAY_SOUND_SPEED_KM_H(temp) 1.85325 * (643.95 * sqrt(((temp + 273.15) / 273.15)))
61 #define COMP_DELAY_SOUND_SPEED_CM_S(temp) (COMP_DELAY_SOUND_SPEED_KM_H(temp) * (1000.0 * 100.0) /* cm/km */ / (60.0 * 60.0) /* s/h */)
62 #define COMP_DELAY_SOUND_FRONT_DELAY(temp) (1.0 / COMP_DELAY_SOUND_SPEED_CM_S(temp))
63 // The maximum delay may be reached by this filter
64 #define COMP_DELAY_MAX_DELAY (COMP_DELAY_MAX_DISTANCE * COMP_DELAY_SOUND_FRONT_DELAY(50))
65
67 {
70 unsigned min_size, new_size = 1;
71
72 s->delay = (
s->distance_m * 100. +
s->distance_cm * 1. +
s->distance_mm * .1) *
75
76 while (new_size < min_size)
77 new_size <<= 1;
78
82
83 s->buf_size = new_size;
84 s->delay_frame->format =
inlink->format;
85 s->delay_frame->nb_samples = new_size;
86 s->delay_frame->channel_layout =
inlink->channel_layout;
87
89 }
90
92 {
95 const unsigned b_mask =
s->buf_size - 1;
96 const unsigned buf_size =
s->buf_size;
97 const unsigned delay =
s->delay;
98 const double dry =
s->dry;
99 const double wet =
s->wet;
100 unsigned r_ptr, w_ptr = 0;
102 int n, ch;
103
108 }
110
111 for (ch = 0; ch <
inlink->channels; ch++) {
113 double *dst = (
double *)
out->extended_data[ch];
114 double *
buffer = (
double *)
s->delay_frame->extended_data[ch];
115
117 r_ptr = (w_ptr + buf_size - delay) & b_mask;
118
121
124 w_ptr = (w_ptr + 1) & b_mask;
125 r_ptr = (r_ptr + 1) & b_mask;
126 }
127 }
129
132 }
133
135 {
137
139 }
140
142 {
147 },
148 };
149
151 {
154 },
155 };
156
158 .
name =
"compensationdelay",
161 .priv_class = &compensationdelay_class,
166 };