[MPlayer-dev-eng] [PATCH] patch for af_hrtf to relieve noises

Xidorn Quan quanxunzhen at gmail.com
Sat Oct 20 17:21:32 CEST 2012


Hi,

A simple patch is attached which is intend to relieve noises for
af_hrtf by using clamp instead of casting directly.

Regards,
Xidorn Quan
-------------- next part --------------
Index: libaf/af_hrtf.c
===================================================================
--- libaf/af_hrtf.c	(revision 35254)
+++ libaf/af_hrtf.c	(working copy)
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
+#include <limits.h>
 
 #include <math.h>
 
@@ -542,16 +543,16 @@
 	      perception.  Note: Too much will destroy the acoustic space
 	      and may even result in headaches. */
 	   diff = STEXPAND2 * (left - right);
-	   out[0] = (int16_t)(left  + diff);
-	   out[1] = (int16_t)(right - diff);
+	   out[0] = clamp(left  + diff, SHRT_MIN, SHRT_MAX);
+	   out[1] = clamp(right - diff, SHRT_MIN, SHRT_MAX);
 	   break;
 	case HRTF_MIX_MATRIX2CH:
 	   /* Do attempt any stereo expansion with matrix encoded
 	      sources.  The L, R channels are already stereo expanded
 	      by the steering, any further stereo expansion will sound
 	      very unnatural. */
-	   out[0] = (int16_t)left;
-	   out[1] = (int16_t)right;
+	   out[0] = clamp(left , SHRT_MIN, SHRT_MAX);
+	   out[1] = clamp(right, SHRT_MIN, SHRT_MAX);
 	   break;
 	}
 


More information about the MPlayer-dev-eng mailing list