avfilter/aderivative: saturate integer differences

full-scale transitions overflow or wrap integer sample formats. use saturating subtraction for the integer paths.

Signed-off-by: Ayoub Nabil Boubagrat <237098474+ayoubnabil@users.noreply.github.com>
This commit is contained in:
Ayoub Nabil Boubagrat authored and michaelni committed 2026-08-31 13:42:52 +00:00
1 parent 25c2c23387
commit 7f9b5b057c
1 file changed
+6 -6
+6 -6
View File
@@ -28,7 +28,7 @@ typedef struct ADerivativeContext {
int nb_samples, int channels);
} ADerivativeContext;
#define DERIVATIVE(name, type) \
#define DERIVATIVE(name, type, difference) \
static void aderivative_## name ##p(void **d, void **p, const void **s, \
int nb_samples, int channels) \
{ \
@@ -42,16 +42,16 @@ static void aderivative_## name ##p(void **d, void **p, const void **s, \
for (n = 0; n < nb_samples; n++) { \
const type current = src[n]; \
\
dst[n] = current - prv[0]; \
dst[n] = difference; \
prv[0] = current; \
} \
} \
}
DERIVATIVE(flt, float)
DERIVATIVE(dbl, double)
DERIVATIVE(s16, int16_t)
DERIVATIVE(s32, int32_t)
DERIVATIVE(flt, float, current - prv[0])
DERIVATIVE(dbl, double, current - prv[0])
DERIVATIVE(s16, int16_t, av_clip_int16(current - prv[0]))
DERIVATIVE(s32, int32_t, av_sat_sub32(current, prv[0]))
#define INTEGRAL(name, type) \
static void aintegral_## name ##p(void **d, void **p, const void **s, \