From 4b37f3db3dc172f4fcab917a09d625106d2c4046 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 17 Jul 2025 12:01:14 +0200 Subject: [PATCH] filter-graph: move loop out of the NULL check --- spa/plugins/filter-graph/plugin_builtin.c | 79 ++++++++++++----------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/spa/plugins/filter-graph/plugin_builtin.c b/spa/plugins/filter-graph/plugin_builtin.c index 0d39bbe70..ffef8adfe 100644 --- a/spa/plugins/filter-graph/plugin_builtin.c +++ b/spa/plugins/filter-graph/plugin_builtin.c @@ -2821,48 +2821,49 @@ static void zeroramp_run(void * Instance, unsigned long SampleCount) if (out == NULL) return; - if (in != NULL) { - for (n = 0; n < SampleCount; n++) { - if (impl->mode == 0) { - /* normal mode, finding gaps */ - out[n] = in[n]; - if (in[n] == 0.0f) { - if (++impl->count == gap) { - /* we found gap zeroes, fade out last - * sample and go into zero mode */ - for (c = 1, i = n; c < duration && i > 0; i--, c++) - out[i-1] = impl->last * - (0.5f + 0.5f * cosf(M_PIf + M_PIf * c / duration)); - impl->mode = 1; - } - } else { - /* keep last sample to fade out when needed */ - impl->count = 0; - impl->last = in[n]; - } - } - if (impl->mode == 1) { - /* zero mode */ - if (in[n] != 0.0f) { - /* gap ended, move to fade-in mode */ - impl->mode = 2; - impl->count = 0; - } else { - out[n] = 0.0f; - } - } - if (impl->mode == 2) { - /* fade-in mode */ - out[n] = in[n] * (0.5f + 0.5f * cosf(M_PIf + (M_PIf * ++impl->count / duration))); - if (impl->count == duration) { - /* fade in complete, back to normal mode */ - impl->count = 0; - impl->mode = 0; + if (in == NULL) { + memset(out, 0, SampleCount * sizeof(float)); + return; + } + + for (n = 0; n < SampleCount; n++) { + if (impl->mode == 0) { + /* normal mode, finding gaps */ + out[n] = in[n]; + if (in[n] == 0.0f) { + if (++impl->count == gap) { + /* we found gap zeroes, fade out last + * sample and go into zero mode */ + for (c = 1, i = n; c < duration && i > 0; i--, c++) + out[i-1] = impl->last * + (0.5f + 0.5f * cosf(M_PIf + M_PIf * c / duration)); + impl->mode = 1; } + } else { + /* keep last sample to fade out when needed */ + impl->count = 0; + impl->last = in[n]; + } + } + if (impl->mode == 1) { + /* zero mode */ + if (in[n] != 0.0f) { + /* gap ended, move to fade-in mode */ + impl->mode = 2; + impl->count = 0; + } else { + out[n] = 0.0f; + } + } + if (impl->mode == 2) { + /* fade-in mode */ + out[n] = in[n] * (0.5f + 0.5f * cosf(M_PIf + (M_PIf * ++impl->count / duration))); + if (impl->count == duration) { + /* fade in complete, back to normal mode */ + impl->count = 0; + impl->mode = 0; } } - } else { - memset(out, 0, SampleCount * sizeof(float)); } }