[asterisk-commits] murf: branch 1.4 r80166 - in /branches/1.4: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 21 11:36:35 CDT 2007


Author: murf
Date: Tue Aug 21 11:36:34 2007
New Revision: 80166

URL: http://svn.digium.com/view/asterisk?view=rev&rev=80166
Log:
This patch solves problem 1 in 8126; it should not slow down the alaw codec, but should prevent signal degradation via multiple trips thru the codec. Fossil estimates the twice thru this codec will prevent fax from working. 4-6 times thru would result hearable, noticeable, voice degradation.

Modified:
    branches/1.4/include/asterisk/alaw.h
    branches/1.4/include/asterisk/ulaw.h
    branches/1.4/main/alaw.c

Modified: branches/1.4/include/asterisk/alaw.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/alaw.h?view=diff&rev=80166&r1=80165&r2=80166
==============================================================================
--- branches/1.4/include/asterisk/alaw.h (original)
+++ branches/1.4/include/asterisk/alaw.h Tue Aug 21 11:36:34 2007
@@ -23,21 +23,69 @@
 #ifndef _ASTERISK_ALAW_H
 #define _ASTERISK_ALAW_H
 
+#define G711_FAST_AND_DIRTY 1
+/* #define G711_REDUCED_BRANCHING */
+
 /*! Init the ulaw conversion stuff */
 /*!
  * To init the ulaw to slinear conversion stuff, this needs to be run.
  */
 void ast_alaw_init(void);
 
+#define AST_ALAW_BIT_LOSS  4
+#define AST_ALAW_STEP      (1 << AST_ALAW_BIT_LOSS)
+#define AST_ALAW_TAB_SIZE  (32768 / AST_ALAW_STEP + 1)
+#define AST_ALAW_SIGN_BIT  0x80
+#define AST_ALAW_AMI_MASK  0x55
+
+
 /*! converts signed linear to mulaw */
 /*!
-  */
+ */
+#ifdef G711_FAST_AND_DIRTY
 extern unsigned char __ast_lin2a[8192];
+#else
+extern unsigned char __ast_lin2a[AST_ALAW_TAB_SIZE];
+#endif
 
 /*! help */
 extern short __ast_alaw[256];
 
+#ifdef G711_FAST_AND_DIRTY
 #define AST_LIN2A(a) (__ast_lin2a[((unsigned short)(a)) >> 3])
+#else
+#define AST_LIN2A_LOOKUP(mag)							\
+	__ast_lin2a[(mag) >> AST_ALAW_BIT_LOSS]
+
+/*! convert signed linear sample to sign-magnitude pair for a-Law */
+static inline void ast_alaw_get_sign_mag(short sample, unsigned *sign, unsigned *mag)
+{
+	/* It may look illogical to retrive the sign this way in both cases,
+	 * but this helps gcc eliminate the branch below and produces
+	 * faster code */
+	*sign = ((unsigned short)sample >> 8) & AST_ALAW_SIGN_BIT;
+#if defined(G711_REDUCED_BRANCHING)
+	{
+		unsigned dual_mag = (-sample << 16) | (unsigned short)sample;
+		*mag = (dual_mag >> (*sign >> 3)) & 0xffffU;
+	}
+#else
+	if (sample < 0)
+		*mag = -sample;
+	else
+		*mag = sample;
+#endif /* G711_REDUCED_BRANCHING */
+	*sign ^= AST_ALAW_SIGN_BIT;
+}
+
+static inline unsigned char AST_LIN2A(short sample)
+{
+	unsigned mag, sign;
+	ast_alaw_get_sign_mag(sample, &sign, &mag);
+	return (sign | AST_LIN2A_LOOKUP(mag)) ^ AST_ALAW_AMI_MASK;
+}
+#endif
+
 #define AST_ALAW(a) (__ast_alaw[(int)(a)])
 
 #endif /* _ASTERISK_ALAW_H */

Modified: branches/1.4/include/asterisk/ulaw.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/ulaw.h?view=diff&rev=80166&r1=80165&r2=80166
==============================================================================
--- branches/1.4/include/asterisk/ulaw.h (original)
+++ branches/1.4/include/asterisk/ulaw.h Tue Aug 21 11:36:34 2007
@@ -23,21 +23,71 @@
 #ifndef _ASTERISK_ULAW_H
 #define _ASTERISK_ULAW_H
 
+#define G711_FAST_AND_DIRTY 1
+
+/* #define G711_REDUCED_BRANCHING */
+
 /*! Init the ulaw conversion stuff */
 /*!
  * To init the ulaw to slinear conversion stuff, this needs to be run.
  */
 void ast_ulaw_init(void);
 
+#define AST_ULAW_BIT_LOSS  3
+#define AST_ULAW_STEP      (1 << AST_ULAW_BIT_LOSS)
+#define AST_ULAW_TAB_SIZE  (32768 / AST_ULAW_STEP + 1)
+#define AST_ULAW_SIGN_BIT  0x80
+
 /*! converts signed linear to mulaw */
 /*!
   */
+#ifdef G711_FAST_AND_DIRTY
 extern unsigned char __ast_lin2mu[16384];
+#else
+extern unsigned char __ast_lin2mu[AST_ULAW_TAB_SIZE];
+#endif
 
 /*! help */
 extern short __ast_mulaw[256];
 
+#ifdef G711_FAST_AND_DIRTY
+
 #define AST_LIN2MU(a) (__ast_lin2mu[((unsigned short)(a)) >> 2])
+
+#else
+
+#define AST_LIN2MU_LOOKUP(mag)											\
+	__ast_lin2mu[((mag) + AST_ULAW_STEP / 2) >> AST_ULAW_BIT_LOSS]
+
+
+/*! convert signed linear sample to sign-magnitude pair for u-Law */
+static inline void ast_ulaw_get_sign_mag(short sample, unsigned *sign, unsigned *mag)
+{
+       /* It may look illogical to retrive the sign this way in both cases,
+        * but this helps gcc eliminate the branch below and produces
+        * faster code */
+       *sign = ((unsigned short)sample >> 8) & AST_ULAW_SIGN_BIT;
+#if defined(G711_REDUCED_BRANCHING)
+       {
+               unsigned dual_mag = (-sample << 16) | (unsigned short)sample;
+               *mag = (dual_mag >> (*sign >> 3)) & 0xffffU;
+       }
+#else
+       if (sample < 0)
+               *mag = -sample;
+       else
+               *mag = sample;
+#endif /* G711_REDUCED_BRANCHING */
+}
+
+static inline unsigned char AST_LIN2MU(short sample)
+{
+       unsigned mag, sign;
+       ast_ulaw_get_sign_mag(sample, &sign, &mag);
+       return ~(sign | AST_LIN2MU_LOOKUP(mag));
+}
+#endif
+
 #define AST_MULAW(a) (__ast_mulaw[(a)])
 
 #endif /* _ASTERISK_ULAW_H */

Modified: branches/1.4/main/alaw.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/alaw.c?view=diff&rev=80166&r1=80165&r2=80166
==============================================================================
--- branches/1.4/main/alaw.c (original)
+++ branches/1.4/main/alaw.c Tue Aug 21 11:36:34 2007
@@ -71,7 +71,7 @@
     int seg;
 
     alaw ^= AMI_MASK;
-    i = ((alaw & 0x0F) << 4);
+    i = ((alaw & 0x0F) << 4) + 8 /* rounding error */;
     seg = (((int) alaw & 0x70) >> 4);
     if (seg)
         i = (i + 0x100) << (seg - 1);




More information about the asterisk-commits mailing list