History

avfilter/af_speechnorm: speed up filtering code

Reduce some asserts by default.

Paul B Mahol committed 4 years ago

Commit 698de271 parent 52218c01 file · +73 −60Browse files

Unified · Split

libavfilter/af_speechnorm.c+73−60
@@ -128,7 +128,7 @@ static int get_pi_samples(PeriodItem *pi, int start, int end, int remain) · 127 unmodified lines
128 start = 0;128 start = 0;
129 if (pi[start].type == 0)129 if (pi[start].type == 0)
130 break;130 break;
131 av_assert0(pi[start].size > 0);131 av_assert1(pi[start].size > 0);
132 sum += pi[start].size;132 sum += pi[start].size;
133 }133 }
134 134
@@ -156,7 +156,7 @@ static void consume_pi(ChannelContext *cc, int nb_samples) · 21 unmodified lines
156 if (cc->pi_size >= nb_samples) {156 if (cc->pi_size >= nb_samples) {
157 cc->pi_size -= nb_samples;157 cc->pi_size -= nb_samples;
158 } else {158 } else {
159 av_assert0(0);159 av_assert1(0);
160 }160 }
161}161}
162 162
@@ -178,16 +178,16 @@ static double next_gain(AVFilterContext *ctx, double pi_max_peak, int bypass, do · 15 unmodified lines
178 178
179static void next_pi(AVFilterContext *ctx, ChannelContext *cc, int bypass)179static void next_pi(AVFilterContext *ctx, ChannelContext *cc, int bypass)
180{180{
181 av_assert0(cc->pi_size >= 0);181 av_assert1(cc->pi_size >= 0);
182 if (cc->pi_size == 0) {182 if (cc->pi_size == 0) {
183 SpeechNormalizerContext *s = ctx->priv;183 SpeechNormalizerContext *s = ctx->priv;
184 int start = cc->pi_start;184 int start = cc->pi_start;
185 185
186 av_assert0(cc->pi[start].size > 0);186 av_assert1(cc->pi[start].size > 0);
187 av_assert0(cc->pi[start].type > 0 || s->eof);187 av_assert0(cc->pi[start].type > 0 || s->eof);
188 cc->pi_size = cc->pi[start].size;188 cc->pi_size = cc->pi[start].size;
189 cc->pi_max_peak = cc->pi[start].max_peak;189 cc->pi_max_peak = cc->pi[start].max_peak;
190 av_assert0(cc->pi_start != cc->pi_end || s->eof);190 av_assert1(cc->pi_start != cc->pi_end || s->eof);
191 start++;191 start++;
192 if (start >= MAX_ITEMS)192 if (start >= MAX_ITEMS)
193 start = 0;193 start = 0;
@@ -219,58 +219,71 @@ static double min_gain(AVFilterContext *ctx, ChannelContext *cc, int max_size) · 25 unmodified lines
219 return min_gain;219 return min_gain;
220}220}
221 221
222#define ANALYZE_CHANNEL(name, ptype, zero, min_peak) \222#define ANALYZE_CHANNEL(name, ptype, zero, min_peak) \
223static void analyze_channel_## name (AVFilterContext *ctx, ChannelContext *cc, \223static void analyze_channel_## name (AVFilterContext *ctx, ChannelContext *cc, \
224 const uint8_t *srcp, int nb_samples) \224 const uint8_t *srcp, int nb_samples) \
225{ \225{ \
226 SpeechNormalizerContext *s = ctx->priv; \226 SpeechNormalizerContext *s = ctx->priv; \
227 const ptype *src = (const ptype *)srcp; \227 const ptype *src = (const ptype *)srcp; \
228 int n = 0; \228 const int max_period = s->max_period; \
229 \229 PeriodItem *pi = (PeriodItem *)&cc->pi; \
230 if (cc->state < 0) \230 int pi_end = cc->pi_end; \
231 cc->state = src[0] >= zero; \231 int n = 0; \
232 \232 \
233 while (n < nb_samples) { \233 if (cc->state < 0) \
234 if ((cc->state != (src[n] >= zero)) || \234 cc->state = src[0] >= zero; \
235 (cc->pi[cc->pi_end].size > s->max_period)) { \235 \
236 ptype max_peak = cc->pi[cc->pi_end].max_peak; \236 while (n < nb_samples) { \
237 int state = cc->state; \237 ptype new_max_peak; \
238 cc->state = src[n] >= zero; \238 int new_size; \
239 av_assert0(cc->pi[cc->pi_end].size > 0); \239 \
240 if (max_peak >= min_peak || \240 if ((cc->state != (src[n] >= zero)) || \
241 cc->pi[cc->pi_end].size > s->max_period) { \241 (pi[pi_end].size > max_period)) { \
242 cc->pi[cc->pi_end].type = 1; \242 ptype max_peak = pi[pi_end].max_peak; \
243 cc->pi_end++; \243 int state = cc->state; \
244 if (cc->pi_end >= MAX_ITEMS) \244 \
245 cc->pi_end = 0; \245 cc->state = src[n] >= zero; \
246 if (cc->state != state) \246 av_assert1(pi[pi_end].size > 0); \
247 cc->pi[cc->pi_end].max_peak = DBL_MIN; \247 if (max_peak >= min_peak || \
248 else \248 pi[pi_end].size > max_period) { \
249 cc->pi[cc->pi_end].max_peak = max_peak; \249 pi[pi_end].type = 1; \
250 cc->pi[cc->pi_end].type = 0; \250 pi_end++; \
251 cc->pi[cc->pi_end].size = 0; \251 if (pi_end >= MAX_ITEMS) \
252 av_assert0(cc->pi_end != cc->pi_start); \252 pi_end = 0; \
253 } \253 if (cc->state != state) \
254 } \254 pi[pi_end].max_peak = DBL_MIN; \
255 \255 else \
256 if (cc->state) { \256 pi[pi_end].max_peak = max_peak; \
257 while (src[n] >= zero) { \257 pi[pi_end].type = 0; \
258 cc->pi[cc->pi_end].max_peak = FFMAX(cc->pi[cc->pi_end].max_peak, src[n]); \258 pi[pi_end].size = 0; \
259 cc->pi[cc->pi_end].size++; \259 av_assert1(pi_end != cc->pi_start); \
260 n++; \260 } \
261 if (n >= nb_samples) \261 } \
262 break; \262 \
263 } \263 new_max_peak = pi[pi_end].max_peak; \
264 } else { \264 new_size = pi[pi_end].size; \
265 while (src[n] < zero) { \265 if (cc->state) { \
266 cc->pi[cc->pi_end].max_peak = FFMAX(cc->pi[cc->pi_end].max_peak, -src[n]); \266 while (src[n] >= zero) { \
267 cc->pi[cc->pi_end].size++; \267 new_max_peak = FFMAX(new_max_peak, src[n]); \
268 n++; \268 new_size++; \
269 if (n >= nb_samples) \269 n++; \
270 break; \270 if (n >= nb_samples) \
271 } \271 break; \
272 } \272 } \
273 } \273 } else { \
274 while (src[n] < zero) { \
275 new_max_peak = FFMAX(new_max_peak, -src[n]); \
276 new_size++; \
277 n++; \
278 if (n >= nb_samples) \
279 break; \
280 } \
281 } \
282 \
283 pi[pi_end].max_peak = new_max_peak; \
284 pi[pi_end].size = new_size; \
285 } \
286 cc->pi_end = pi_end; \
274}287}
275 288
276ANALYZE_CHANNEL(dbl, double, 0.0, MIN_PEAK)289ANALYZE_CHANNEL(dbl, double, 0.0, MIN_PEAK)
@@ -296,7 +309,7 @@ static void filter_channels_## name (AVFilterContext *ctx, · 19 unmodified lines
296 \309 \
297 next_pi(ctx, cc, bypass); \310 next_pi(ctx, cc, bypass); \
298 size = FFMIN(nb_samples - n, cc->pi_size); \311 size = FFMIN(nb_samples - n, cc->pi_size); \
299 av_assert0(size > 0); \312 av_assert1(size > 0); \
300 gain = cc->gain_state; \313 gain = cc->gain_state; \
301 consume_pi(cc, size); \314 consume_pi(cc, size); \
302 for (int i = n; !ctx->is_disabled && i < n + size; i++) \315 for (int i = n; !ctx->is_disabled && i < n + size; i++) \
@@ -343,7 +356,7 @@ static void filter_link_channels_## name (AVFilterContext *ctx, · 40 unmodified lines
343 max_size = FFMAX(max_size, cc->pi_size); \356 max_size = FFMAX(max_size, cc->pi_size); \
344 } \357 } \
345 \358 \
346 av_assert0(min_size > 0); \359 av_assert1(min_size > 0); \
347 for (int ch = 0; ch < inlink->channels; ch++) { \360 for (int ch = 0; ch < inlink->channels; ch++) { \
348 ChannelContext *cc = &s->cc[ch]; \361 ChannelContext *cc = &s->cc[ch]; \
349 \362 \
@@ -509,7 +522,7 @@ static int config_input(AVFilterLink *inlink) · 159 unmodified lines
509 s->filter_channels[1] = filter_link_channels_dbl;522 s->filter_channels[1] = filter_link_channels_dbl;
510 break;523 break;
511 default:524 default:
512 av_assert0(0);525 av_assert1(0);
513 }526 }
514 527
515 return 0;528 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t