1 /*
2 * Copyright (c) 2013 Paul B Mahol
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 * phaser audio filter
24 */
25
32
39
41
44
47
49
52 int nb_samples, int channels);
54
55 #define OFFSET(x) offsetof(AudioPhaserContext, x)
56 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
57
69 { NULL }
70 };
71
73
75 {
77
82
83 return 0;
84 }
85
87 {
96 };
97
99 if (!layouts)
102
104 if (!formats)
107
109 if (!formats)
112
113 return 0;
114 }
115
116 #define MOD(a, b) (((a) >= (b)) ? (a) - (b) : (a))
117
118 #define PHASER_PLANAR(name, type) \
119 static void phaser_## name ##p(AudioPhaserContext *p, \
120 uint8_t * const *src, uint8_t **dst, \
121 int nb_samples, int channels) \
122 { \
123 int i, c, delay_pos, modulation_pos; \
124 \
125 av_assert0(channels > 0); \
126 for (c = 0; c < channels; c++) { \
127 type *s = (type *)src[c]; \
128 type *d = (type *)dst[c]; \
129 double *buffer = p->delay_buffer + \
130 c * p->delay_buffer_length; \
131 \
132 delay_pos = p->delay_pos; \
133 modulation_pos = p->modulation_pos; \
134 \
135 for (i = 0; i < nb_samples; i++, s++, d++) { \
136 double v = *s * p->in_gain + buffer[ \
137 MOD(delay_pos + p->modulation_buffer[ \
138 modulation_pos], \
139 p->delay_buffer_length)] * p->decay; \
140 \
141 modulation_pos = MOD(modulation_pos + 1, \
142 p->modulation_buffer_length); \
143 delay_pos = MOD(delay_pos + 1, p->delay_buffer_length); \
144 buffer[delay_pos] = v; \
145 \
146 *d = v * p->out_gain; \
147 } \
148 } \
149 \
150 p->delay_pos = delay_pos; \
151 p->modulation_pos = modulation_pos; \
152 }
153
154 #define PHASER(name, type) \
155 static void phaser_## name (AudioPhaserContext *p, \
156 uint8_t * const *src, uint8_t **dst, \
157 int nb_samples, int channels) \
158 { \
159 int i, c, delay_pos, modulation_pos; \
160 type *s = (type *)src[0]; \
161 type *d = (type *)dst[0]; \
162 double *buffer = p->delay_buffer; \
163 \
164 delay_pos = p->delay_pos; \
165 modulation_pos = p->modulation_pos; \
166 \
167 for (i = 0; i < nb_samples; i++) { \
168 int pos = MOD(delay_pos + p->modulation_buffer[modulation_pos], \
169 p->delay_buffer_length) * channels; \
170 int npos; \
171 \
172 delay_pos = MOD(delay_pos + 1, p->delay_buffer_length); \
173 npos = delay_pos * channels; \
174 for (c = 0; c < channels; c++, s++, d++) { \
175 double v = *s * p->in_gain + buffer[pos + c] * p->decay; \
176 \
177 buffer[npos + c] = v; \
178 \
179 *d = v * p->out_gain; \
180 } \
181 \
182 modulation_pos = MOD(modulation_pos + 1, \
183 p->modulation_buffer_length); \
184 } \
185 \
186 p->delay_pos = delay_pos; \
187 p->modulation_pos = modulation_pos; \
188 }
189
194
199
201 {
204
209
212
216
218
229 }
230
231 return 0;
232 }
233
235 {
239
241 outbuf = inbuf;
242 } else {
244 if (!outbuf)
247 }
248
251
252 if (inbuf != outbuf)
254
256 }
257
259 {
261
264 }
265
267 {
271 },
272 { NULL }
273 };
274
276 {
280 },
281 { NULL }
282 };
283
293 .priv_class = &aphaser_class,
294 };