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

Showing the changes to libavfilter (1 of 1 file). Show all

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
128128 start = 0;
129129 if (pi[start].type == 0)
130130 break;
131− av_assert0(pi[start].size > 0);
131+ av_assert1(pi[start].size > 0);
132132 sum += pi[start].size;
133133 }
134134
@@ -156,7 +156,7 @@ static void consume_pi(ChannelContext *cc, int nb_samples) · 21 unmodified lines
156156 if (cc->pi_size >= nb_samples) {
157157 cc->pi_size -= nb_samples;
158158 } else {
159− av_assert0(0);
159+ av_assert1(0);
160160 }
161161 }
162162
@@ -178,16 +178,16 @@ static double next_gain(AVFilterContext *ctx, double pi_max_peak, int bypass, do · 15 unmodified lines
178178
179179 static void next_pi(AVFilterContext *ctx, ChannelContext *cc, int bypass)
180180 {
181− av_assert0(cc->pi_size >= 0);
181+ av_assert1(cc->pi_size >= 0);
182182 if (cc->pi_size == 0) {
183183 SpeechNormalizerContext *s = ctx->priv;
184184 int start = cc->pi_start;
185185
186− av_assert0(cc->pi[start].size > 0);
186+ av_assert1(cc->pi[start].size > 0);
187187 av_assert0(cc->pi[start].type > 0 || s->eof);
188188 cc->pi_size = cc->pi[start].size;
189189 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);
191191 start++;
192192 if (start >= MAX_ITEMS)
193193 start = 0;
@@ -219,58 +219,71 @@ static double min_gain(AVFilterContext *ctx, ChannelContext *cc, int max_size) · 25 unmodified lines
219219 return min_gain;
220220 }
221221
222−#define ANALYZE_CHANNEL(name, ptype, zero, min_peak) \
223−static void analyze_channel_## name (AVFilterContext *ctx, ChannelContext *cc, \
224− const uint8_t *srcp, int nb_samples) \
225−{ \
226− SpeechNormalizerContext *s = ctx->priv; \
227− const ptype *src = (const ptype *)srcp; \
228− int n = 0; \
229− \
230− if (cc->state < 0) \
231− cc->state = src[0] >= zero; \
232− \
233− while (n < nb_samples) { \
234− if ((cc->state != (src[n] >= zero)) || \
235− (cc->pi[cc->pi_end].size > s->max_period)) { \
236− ptype max_peak = cc->pi[cc->pi_end].max_peak; \
237− int state = cc->state; \
238− cc->state = src[n] >= zero; \
239− av_assert0(cc->pi[cc->pi_end].size > 0); \
240− if (max_peak >= min_peak || \
241− cc->pi[cc->pi_end].size > s->max_period) { \
242− cc->pi[cc->pi_end].type = 1; \
243− cc->pi_end++; \
244− if (cc->pi_end >= MAX_ITEMS) \
245− cc->pi_end = 0; \
246− if (cc->state != state) \
247− cc->pi[cc->pi_end].max_peak = DBL_MIN; \
248− else \
249− cc->pi[cc->pi_end].max_peak = max_peak; \
250− cc->pi[cc->pi_end].type = 0; \
251− cc->pi[cc->pi_end].size = 0; \
252− av_assert0(cc->pi_end != cc->pi_start); \
253− } \
254− } \
255− \
256− if (cc->state) { \
257− while (src[n] >= zero) { \
258− cc->pi[cc->pi_end].max_peak = FFMAX(cc->pi[cc->pi_end].max_peak, src[n]); \
259− cc->pi[cc->pi_end].size++; \
260− n++; \
261− if (n >= nb_samples) \
262− break; \
263− } \
264− } else { \
265− while (src[n] < zero) { \
266− cc->pi[cc->pi_end].max_peak = FFMAX(cc->pi[cc->pi_end].max_peak, -src[n]); \
267− cc->pi[cc->pi_end].size++; \
268− n++; \
269− if (n >= nb_samples) \
270− break; \
271− } \
272− } \
273− } \
222+#define ANALYZE_CHANNEL(name, ptype, zero, min_peak) \
223+static void analyze_channel_## name (AVFilterContext *ctx, ChannelContext *cc, \
224+ const uint8_t *srcp, int nb_samples) \
225+{ \
226+ SpeechNormalizerContext *s = ctx->priv; \
227+ const ptype *src = (const ptype *)srcp; \
228+ const int max_period = s->max_period; \
229+ PeriodItem *pi = (PeriodItem *)&cc->pi; \
230+ int pi_end = cc->pi_end; \
231+ int n = 0; \
232+ \
233+ if (cc->state < 0) \
234+ cc->state = src[0] >= zero; \
235+ \
236+ while (n < nb_samples) { \
237+ ptype new_max_peak; \
238+ int new_size; \
239+ \
240+ if ((cc->state != (src[n] >= zero)) || \
241+ (pi[pi_end].size > max_period)) { \
242+ ptype max_peak = pi[pi_end].max_peak; \
243+ int state = cc->state; \
244+ \
245+ cc->state = src[n] >= zero; \
246+ av_assert1(pi[pi_end].size > 0); \
247+ if (max_peak >= min_peak || \
248+ pi[pi_end].size > max_period) { \
249+ pi[pi_end].type = 1; \
250+ pi_end++; \
251+ if (pi_end >= MAX_ITEMS) \
252+ pi_end = 0; \
253+ if (cc->state != state) \
254+ pi[pi_end].max_peak = DBL_MIN; \
255+ else \
256+ pi[pi_end].max_peak = max_peak; \
257+ pi[pi_end].type = 0; \
258+ pi[pi_end].size = 0; \
259+ av_assert1(pi_end != cc->pi_start); \
260+ } \
261+ } \
262+ \
263+ new_max_peak = pi[pi_end].max_peak; \
264+ new_size = pi[pi_end].size; \
265+ if (cc->state) { \
266+ while (src[n] >= zero) { \
267+ new_max_peak = FFMAX(new_max_peak, src[n]); \
268+ new_size++; \
269+ n++; \
270+ if (n >= nb_samples) \
271+ break; \
272+ } \
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; \
274287 }
275288
276289 ANALYZE_CHANNEL(dbl, double, 0.0, MIN_PEAK)
@@ -296,7 +309,7 @@ static void filter_channels_## name (AVFilterContext *ctx, · 19 unmodified lines
296309 \
297310 next_pi(ctx, cc, bypass); \
298311 size = FFMIN(nb_samples - n, cc->pi_size); \
299− av_assert0(size > 0); \
312+ av_assert1(size > 0); \
300313 gain = cc->gain_state; \
301314 consume_pi(cc, size); \
302315 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
343356 max_size = FFMAX(max_size, cc->pi_size); \
344357 } \
345358 \
346− av_assert0(min_size > 0); \
359+ av_assert1(min_size > 0); \
347360 for (int ch = 0; ch < inlink->channels; ch++) { \
348361 ChannelContext *cc = &s->cc[ch]; \
349362 \
@@ -509,7 +522,7 @@ static int config_input(AVFilterLink *inlink) · 159 unmodified lines
509522 s->filter_channels[1] = filter_link_channels_dbl;
510523 break;
511524 default:
512− av_assert0(0);
525+ av_assert1(0);
513526 }
514527
515528 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