1
0
mirror of https://git.FreeBSD.org/ports.git synced 2025-02-08 12:01:56 +00:00

www/palemoon: sndio: improve and clamp float->s16 conversion

This fixes sound glitches/crackling when playing audio or video clips
with float samples with SNDIO=on.

PR:		224034
Submitted by:	lichray@gmail.com (maintainer)
Obtained from:	cubeb
This commit is contained in:
Tobias Kortkamp 2017-12-03 07:17:18 +00:00
parent 04624414b9
commit 574e3bddf9
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=455391
2 changed files with 42 additions and 0 deletions

View File

@ -4,6 +4,7 @@
PORTNAME= palemoon
DISTVERSION= 27.6.2
DISTVERSIONSUFFIX=_Release
PORTREVISION= 1
CATEGORIES= www ipv6
MAINTAINER= lichray@gmail.com

View File

@ -0,0 +1,41 @@
From 5ffce9e91b2fde70ba532ea215e3e9e7eed3d41a Mon Sep 17 00:00:00 2001
From: Alexandre Ratchov <alex@caoua.org>
Date: Thu, 2 Apr 2015 13:09:22 +1300
Subject: [PATCH] sndio: improve and clamp float->s16 conversion.
---
src/cubeb_sndio.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/cubeb_sndio.c b/src/cubeb_sndio.c
index 01f96346..e6d531a4 100644
--- media/libcubeb/src/cubeb_sndio.c.orig
+++ media/libcubeb/src/cubeb_sndio.c
@@ -4,6 +4,7 @@
* This program is made available under an ISC-style license. See the
* accompanying file LICENSE for details.
*/
+#include <math.h>
#include <poll.h>
#include <pthread.h>
#include <sndio.h>
@@ -49,9 +50,16 @@ float_to_s16(void *ptr, long nsamp)
{
int16_t *dst = ptr;
float *src = ptr;
-
- while (nsamp-- > 0)
- *(dst++) = *(src++) * 32767;
+ int s;
+
+ while (nsamp-- > 0) {
+ s = lrintf(*(src++) * 32768);
+ if (s < -32768)
+ s = -32768;
+ else if (s > 32767)
+ s = 32767;
+ *(dst++) = s;
+ }
}
static void