From yamagi@yamagi.org  Sun May  5 09:17:37 2013
Return-Path: <yamagi@yamagi.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 767B5F0A
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  5 May 2013 09:17:37 +0000 (UTC)
	(envelope-from yamagi@yamagi.org)
Received: from mail.yamagi.org (mail.yamagi.org [IPv6:2a01:4f8:121:2102:1::7])
	by mx1.freebsd.org (Postfix) with ESMTP id EE5E8792
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  5 May 2013 09:17:36 +0000 (UTC)
Received: from happy.home.yamagi.org (p579A6312.dip0.t-ipconnect.de [87.154.99.18])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mail.yamagi.org (Postfix) with ESMTPSA id BFE751666312
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  5 May 2013 11:17:35 +0200 (CEST)
Received: from happy.home.yamagi.org (localhost [127.0.0.1])
	by happy.home.yamagi.org (8.14.5/8.14.5) with ESMTP id r459HYol079078
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 5 May 2013 11:17:34 +0200 (CEST)
	(envelope-from yamagi@happy.home.yamagi.org)
Received: (from yamagi@localhost)
	by happy.home.yamagi.org (8.14.5/8.14.5/Submit) id r459HYSG079077;
	Sun, 5 May 2013 11:17:34 +0200 (CEST)
	(envelope-from yamagi)
Message-Id: <201305050917.r459HYSG079077@happy.home.yamagi.org>
Date: Sun, 5 May 2013 11:17:34 +0200 (CEST)
From: Yamagi Burmeister <yamagi@yamagi.org>
Reply-To: Yamagi Burmeister <yamagi@yamagi.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] Fix distortions with audio/openal-soft
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         178343
>Category:       ports
>Synopsis:       [PATCH] Fix distortions with audio/openal-soft
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    mva
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 05 09:20:00 UTC 2013
>Closed-Date:    Thu May 23 06:06:12 UTC 2013
>Last-Modified:  Thu May 23 06:10:00 UTC 2013
>Originator:     Yamagi Burmeister
>Release:        FreeBSD 9.1-RELEASE amd64
>Organization:
>Environment:
System: FreeBSD happy.home.yamagi.org 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243792M: Sun Dec 2 17:53:10 CET 2012 root@happy.home.yamagi.org:/usr/obj/usr/src/sys/HAPPY amd64


	
>Description:
Since version 1.15 audio/openal-soft has an integer overflow bug which
results in heavy distortions in conjunction with the OSS backend. It
can be triggered on at least snd_hda and snd_envy24ht with several
applications. The bug was confirmed by Chris Robinson (author of
openal-soft) and he send me the attached patch. It fixes the problem
and I guess that it should be included into the port until a new 
upstream version is released.

The attached patch adds the file files/patch-Alc-ALu.c to
audio/openal-soft.

>How-To-Repeat:
Install audio/openal-soft and start any OpenAL based application. For
example games/ioquake3. The sound will distort if the application volume
is high enough.

>Fix:
Index: files/patch-Alc-ALu.c
===================================================================
--- files/patch-Alc-ALu.c	(Revision 0)
+++ files/patch-Alc-ALu.c	(Arbeitskopie)
@@ -0,0 +1,11 @@
+--- Alc/ALu.c_	2013-05-01 09:31:36.000000000 +0200
++++ Alc/ALu.c	2013-05-01 09:31:52.000000000 +0200
+@@ -920,7 +920,7 @@
+     val = val+1.0f - fabsf(val-1.0f);
+     val = (val-2.0f + fabsf(val+2.0f)) * 0.25f;
+     /* Convert to a signed integer, between -2147483647 and
+2147483647. */
+-    return fastf2i((ALfloat)(val*2147483647.0));
++    return fastf2i(val*16777215.0f)<<7;
+ }
+ static __inline ALuint aluF2UI(ALfloat val)
+ { return aluF2I(val)+2147483648u; }


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->mva 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Sun May 5 09:20:07 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=178343 

From: Marcus von Appen <mva@FreeBSD.org>
To: bug-followup@FreeBSD.org, yamagi@yamagi.org
Cc:  
Subject: Re: ports/178343: [PATCH] Fix distortions with audio/openal-soft
Date: Mon, 13 May 2013 20:09:43 +0200

 --LTeJQqWS0MN7I/qa
 Content-Type: multipart/mixed; boundary="rQ2U398070+RC21q"
 Content-Disposition: inline
 
 
 --rQ2U398070+RC21q
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Hi Yamagi,
 
 thanks for your patch. The openal-soft upstream repo has a slightly
 different change. Do you mind to give that one a try and see, if it
 fixes your issue?
 
 Fixd a patch to the FreeBSD port attached.
 
 Thanks
 Marcus
 
 --rQ2U398070+RC21q
 Content-Type: text/x-diff; charset=us-ascii
 Content-Disposition: attachment; filename="upstream.patch"
 
 Index: files/patch-Alc-ALu.c
 ===================================================================
 --- files/patch-Alc-ALu.c	(revision 0)
 +++ files/patch-Alc-ALu.c	(working copy)
 @@ -0,0 +1,15 @@
 +--- Alc/ALu.c.orig	2013-05-13 18:54:52.000000000 +0200
 ++++ Alc/ALu.c	2013-05-13 18:56:23.000000000 +0200
 +@@ -916,9 +916,9 @@
 + { return val; }
 + static __inline ALint aluF2I(ALfloat val)
 + {
 +-    /* Clamp the value between -1 and +1. This handles that without branching. */
 +-    val = val+1.0f - fabsf(val-1.0f);
 +-    val = (val-2.0f + fabsf(val+2.0f)) * 0.25f;
 ++    /* Clamp the value between -1 and +1. This handles that with only a single branch. */
 ++    if(fabsf(val) > 1.0f)
 ++        val = (0.0f < val) - (val < 0.0f);
 +     /* Convert to a signed integer, between -2147483647 and +2147483647. */
 +     return fastf2i((ALfloat)(val*2147483647.0));
 + }
 
 
 --rQ2U398070+RC21q--
 
 --LTeJQqWS0MN7I/qa
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.20 (FreeBSD)
 
 iEYEARECAAYFAlGRLGcACgkQi68/ErJnpkfNvQCfY/kS4R2DOMfdA5BfS272TO3A
 X7gAn2tJhwZgbFE45W8/x4MqM0TPHzFU
 =qYZk
 -----END PGP SIGNATURE-----
 
 --LTeJQqWS0MN7I/qa--

From: Yamagi Burmeister <yamagi@yamagi.org>
To: mva@FreeBSD.org
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/178343: [PATCH] Fix distortions with audio/openal-soft
Date: Mon, 13 May 2013 22:25:55 +0200

 --Signature=_Mon__13_May_2013_22_25_55_+0200_Sureh22UPP3L7xYf
 Content-Type: multipart/mixed;
  boundary="Multipart=_Mon__13_May_2013_22_25_55_+0200_rh0iHv/6ndQ/p+uv"
 
 
 --Multipart=_Mon__13_May_2013_22_25_55_+0200_rh0iHv/6ndQ/p+uv
 Content-Type: text/plain; charset=US-ASCII
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Good evening,
 I gave it a try but as expected it doesn't help. In fact I tried the
 git HEAD before I even started debugging this issue. The issue is that
 both the old code before revision bf54de4 and the new code after that
 revision gives a val slightly bigger than 1.0. Therefor fastf2i -
 which is just a call to lrintf() - returns a value of 2147483648
 which overflows the integer returned by aluF2I().=20
 
 The patch provided by Chris Robinson solves this issue but the precision
 loss is quite large. I'm still convinced that the only correct solution
 is the version of aluF2I() implemented by revisions before f02a993 but
 it's not up to me to decide that. I told Chris that his patch works for
 me but haven't heard back, neither the patch was committed upstream.
 
 Attached is the test program that I send Chris. old() is the old code
 before f02a993, new() is the current git HEAD. The integer overflow
 is quite easy to see:
 
 old: 2147483647, new: -2147483648
 old: 1073741824, new: 1073741824
 old: -1073741824, new: -1073741824
 old: -2147483648, new: -2147483648
 
 Ciao,
 Yamagi
 
 On Mon, 13 May 2013 20:09:43 +0200
 Marcus von Appen <mva@FreeBSD.org> wrote:
 
 > Hi Yamagi,
 >=20
 > thanks for your patch. The openal-soft upstream repo has a slightly
 > different change. Do you mind to give that one a try and see, if it
 > fixes your issue?
 >=20
 > Fixd a patch to the FreeBSD port attached.
 >=20
 > Thanks
 > Marcus
 
 
 --=20
 Homepage:  www.yamagi.org
 XMPP:      yamagi@yamagi.org
 GnuPG/GPG: 0xEFBCCBCB
 
 --Multipart=_Mon__13_May_2013_22_25_55_+0200_rh0iHv/6ndQ/p+uv
 Content-Type: text/x-csrc;
  name="test.c"
 Content-Disposition: attachment;
  filename="test.c"
 Content-Transfer-Encoding: quoted-printable
 
 #include <math.h>
 #include <stdio.h>
 
 int
 old(float val)
 {
 	if(val > 1.0f) return 2147483647;
 	if(val < -1.0f) return -2147483647-1;
 	return lrintf(val*2147483647.0);
 }
 
 int
 new(float val)
 {
 	if(fabsf(val) > 1.0f)
 		val =3D (0.0f < val) - (val < 0.0f);
     return lrintf(val*2147483647.0);
 }
 
 int
 main(void)
 {
 	float a =3D 1.5f;
 	float b =3D 0.5f;
 	float c =3D -0.5f;
 	float d =3D -1.5f;
 
 	printf("old: %i, new: %i\n", old(a), new(a));
 	printf("old: %i, new: %i\n", old(b), new(b));
 	printf("old: %i, new: %i\n", old(c), new(c));
 	printf("old: %i, new: %i\n", old(d), new(d));
 
 	return 0;
 }
 
 
 --Multipart=_Mon__13_May_2013_22_25_55_+0200_rh0iHv/6ndQ/p+uv--
 
 --Signature=_Mon__13_May_2013_22_25_55_+0200_Sureh22UPP3L7xYf
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.20 (FreeBSD)
 
 iEYEARECAAYFAlGRTF8ACgkQWTjlg++8y8vdzgCff2G1wOonRabvVYgNET2NwZps
 cVIAoLYeRPczlGTh62+Gz2z5XVZynSfd
 =GV46
 -----END PGP SIGNATURE-----
 
 --Signature=_Mon__13_May_2013_22_25_55_+0200_Sureh22UPP3L7xYf--

From: Marcus von Appen <mva@FreeBSD.org>
To: Yamagi Burmeister <yamagi@yamagi.org>
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/178343: [PATCH] Fix distortions with audio/openal-soft
Date: Sat, 18 May 2013 10:56:12 +0200

 --9dgjiU4MmWPVapMU
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 
 Hi Yamagi,
 
 [...]
 
 thanks for the explanation. I catched up with Chris Robinson and he just
 committed the patch, you both talked about:
 http://repo.or.cz/w/openal-soft.git/commitdiff/563f16dc2a52de3217c90313ca6bddbbc20f20a0
 
 Do you mind to give that one a try and check,if it fixes the distortion issue
 for you?
 
 Thanks
 Marcus
 
 --9dgjiU4MmWPVapMU
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.20 (FreeBSD)
 
 iEYEARECAAYFAlGXQiwACgkQi68/ErJnpkfNhQCgwSDXj9CIZTib1iD+vi7ebPLi
 JcsAn1iHTuE2e/SD+8lJ00CZRwXkZIyc
 =6HWv
 -----END PGP SIGNATURE-----
 
 --9dgjiU4MmWPVapMU--

From: Yamagi Burmeister <yamagi@yamagi.org>
To: mva@FreeBSD.org
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/178343: [PATCH] Fix distortions with audio/openal-soft
Date: Mon, 20 May 2013 20:05:35 +0200

 --Signature=_Mon__20_May_2013_20_05_35_+0200_I6wRmLKmkXTbdhD5
 Content-Type: text/plain; charset=US-ASCII
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Hello :)
 
 On Sat, 18 May 2013 10:56:12 +0200
 Marcus von Appen <mva@FreeBSD.org> wrote:
 
 > thanks for the explanation. I catched up with Chris Robinson and he just
 > committed the patch, you both talked about:
 > http://repo.or.cz/w/openal-soft.git/commitdiff/563f16dc2a52de3217c90313ca=
 6bddbbc20f20a0
 >=20
 > Do you mind to give that one a try and check,if it fixes the distortion i=
 ssue
 > for you?
 
 YI've just tested the change. Both openal-softs git head and the
 revision 563f16d backported to the FreeBSD port work just fine. The
 patch solves the problem.
 
 Thank you,
 Yamagi
 
 
 --=20
 Homepage:  www.yamagi.org
 XMPP:      yamagi@yamagi.org
 GnuPG/GPG: 0xEFBCCBCB
 
 --Signature=_Mon__20_May_2013_20_05_35_+0200_I6wRmLKmkXTbdhD5
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.20 (FreeBSD)
 
 iEYEARECAAYFAlGaZfMACgkQWTjlg++8y8vPJACg1ef/WyGZ9MjXYJFIl7ajqT9A
 YZMAn0qZd3WSBoBzv6x+Cm+4Y8Pv8Af9
 =CiPL
 -----END PGP SIGNATURE-----
 
 --Signature=_Mon__20_May_2013_20_05_35_+0200_I6wRmLKmkXTbdhD5--
State-Changed-From-To: open->closed 
State-Changed-By: mva 
State-Changed-When: Thu May 23 06:06:11 UTC 2013 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=178343 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/178343: commit references a PR
Date: Thu, 23 May 2013 06:05:45 +0000 (UTC)

 Author: mva
 Date: Thu May 23 06:05:32 2013
 New Revision: 318843
 URL: http://svnweb.freebsd.org/changeset/ports/318843
 
 Log:
   - Fix a sound distortion issue for the OSS backend
   
   PR:		ports/178343
   Submitted by:	Yamagi Burmeister <yamagi@yamagi.org>
 
 Added:
   head/audio/openal-soft/files/patch-Alc-ALu.c   (contents, props changed)
 Modified:
   head/audio/openal-soft/Makefile
 
 Modified: head/audio/openal-soft/Makefile
 ==============================================================================
 --- head/audio/openal-soft/Makefile	Thu May 23 05:48:41 2013	(r318842)
 +++ head/audio/openal-soft/Makefile	Thu May 23 06:05:32 2013	(r318843)
 @@ -2,6 +2,7 @@
  
  PORTNAME=	openal-soft
  PORTVERSION=	1.15.1
 +PORTREVISION=	1
  CATEGORIES=	audio
  MASTER_SITES=	http://kcat.strangesoft.net/openal-releases/
  
 
 Added: head/audio/openal-soft/files/patch-Alc-ALu.c
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/audio/openal-soft/files/patch-Alc-ALu.c	Thu May 23 06:05:32 2013	(r318843)
 @@ -0,0 +1,37 @@
 +--- Alc/ALu.c.orig	2013-05-23 08:00:01.000000000 +0200
 ++++ Alc/ALu.c	2013-05-23 08:01:20.000000000 +0200
 +@@ -912,24 +912,27 @@
 + }
 + 
 + 
 +-static __inline ALfloat aluF2F(ALfloat val)
 +-{ return val; }
 +-static __inline ALint aluF2I(ALfloat val)
 ++static __inline ALint aluF2I25(ALfloat val)
 + {
 +     /* Clamp the value between -1 and +1. This handles that without branching. */
 +     val = val+1.0f - fabsf(val-1.0f);
 +     val = (val-2.0f + fabsf(val+2.0f)) * 0.25f;
 +-    /* Convert to a signed integer, between -2147483647 and +2147483647. */
 +-    return fastf2i((ALfloat)(val*2147483647.0));
 ++    /* Convert to a signed integer, between -16777215 and +16777215. */
 ++    return fastf2i(val*16777215.0f);
 + }
 ++
 ++static __inline ALfloat aluF2F(ALfloat val)
 ++{ return val; }
 ++static __inline ALint aluF2I(ALfloat val)
 ++{ return aluF2I25(val)<<7; }
 + static __inline ALuint aluF2UI(ALfloat val)
 + { return aluF2I(val)+2147483648u; }
 + static __inline ALshort aluF2S(ALfloat val)
 +-{ return aluF2I(val)>>16; }
 ++{ return aluF2I(val)>>9; }
 + static __inline ALushort aluF2US(ALfloat val)
 + { return aluF2S(val)+32768; }
 + static __inline ALbyte aluF2B(ALfloat val)
 +-{ return aluF2I(val)>>24; }
 ++{ return aluF2I(val)>>17; }
 + static __inline ALubyte aluF2UB(ALfloat val)
 + { return aluF2B(val)+128; }
 + 
 _______________________________________________
 svn-ports-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-ports-all
 To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
 
>Unformatted:
