From 7aa8d8d6282f10ab18d088d6d70306f4103611c0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 9 Dec 2025 13:55:37 +0100 Subject: [PATCH] spa-resample: enable clipping in sndfile We can actually use a command to enable clipping in sndfile instead of doing it ourselves. --- spa/plugins/audioconvert/spa-resample.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spa/plugins/audioconvert/spa-resample.c b/spa/plugins/audioconvert/spa-resample.c index ec2c7b3cf..4d31c8392 100644 --- a/spa/plugins/audioconvert/spa-resample.c +++ b/spa/plugins/audioconvert/spa-resample.c @@ -187,6 +187,8 @@ static int open_files(struct data *d) d->oname, sf_strerror(NULL)); return -EIO; } + sf_command(d->ofile, SFC_SET_CLIPPING, NULL, 1); + if (d->verbose) { fprintf(stdout, "input '%s': channels:%d rate:%d format:%s\n", d->iname, d->iinfo.channels, d->iinfo.samplerate, @@ -296,9 +298,8 @@ static int do_conversion(struct data *d) if (pout_len > 0) { for (k = 0, i = 0; i < pout_len; i++) { - for (j = 0; j < channels; j++) { - obuf[k++] = SPA_CLAMP(out[MAX_SAMPLES * j + i], -1.0f, 1.0f); - } + for (j = 0; j < channels; j++) + obuf[k++] = out[MAX_SAMPLES * j + i]; } pout_len = sf_writef_float(d->ofile, obuf, pout_len);