shithub: aacdec

Download patch

ref: 2e8547789313ae2b0a99a724177805b51c642b55
parent: 529d431ad29d8382c55ea24259298b4d4a7112d2
author: menno <menno>
date: Tue Apr 1 11:34:35 EST 2003

stability fixes and ARM fixed point optimisations

--- a/libfaad/bits.h
+++ b/libfaad/bits.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: bits.h,v 1.16 2003/02/16 18:17:10 menno Exp $
+** $Id: bits.h,v 1.17 2003/04/01 16:34:30 menno Exp $
 **/
 
 #ifndef __BITS_H__
@@ -106,6 +106,10 @@
 
 static INLINE void faad_flushbits(bitfile *ld, uint32_t bits)
 {
+    /* do nothing if error */
+    if (ld->error != 0)
+        return;
+
     if (bits < ld->bits_left)
     {
         ld->bits_left -= bits;
@@ -194,6 +198,10 @@
 
 static INLINE void faad_flushbits_rev(bitfile *ld, uint32_t bits)
 {
+    /* do nothing if error */
+    if (ld->error != 0)
+        return;
+
     if (bits < ld->bits_left)
     {
         ld->bits_left -= bits;
--- a/libfaad/fixed.h
+++ b/libfaad/fixed.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: fixed.h,v 1.4 2002/11/07 18:24:53 menno Exp $
+** $Id: fixed.h,v 1.5 2003/04/01 16:34:33 menno Exp $
 **/
 
 #ifndef __FIXED_H__
@@ -69,6 +69,38 @@
         imul B
         shrd eax,edx,COEF_BITS
     }
+}
+
+#elif defined(__GNUC__) && defined (__arm__)
+
+/* taken from MAD */
+#define arm_mul(x, y, SCALEBITS) \
+       ({      uint32_t __hi; \
+               uint32_t __lo; \
+               uint32_t __result; \
+               asm ("smull  %0, %1, %3, %4\n\t" \
+                    "movs   %0, %0, lsr %5\n\t" \
+                    "adc    %2, %0, %1, lsl %6" \
+                    : "=&r" (__lo), "=&r" (__hi), "=r" (__result) \
+                    : "%r" (x), "r" (y), \
+                      "M" (SCALEBITS), "M" (32 - (SCALEBITS)) \
+                    : "cc"); \
+               __result; \
+       })
+
+static INLINE real_t MUL(real_t A, real_t B)
+{
+       return arm_mul( A, B, REAL_BITS);
+}
+
+static INLINE real_t MUL_C_C(real_t A, real_t B)
+{
+       return arm_mul( A, B, COEF_BITS);
+}
+
+static INLINE real_t MUL_R_C(real_t A, real_t B)
+{
+       return arm_mul( A, B, COEF_BITS);
 }
 
 #else
--- a/libfaad/hcr.c
+++ b/libfaad/hcr.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: hcr.c,v 1.2 2002/12/05 19:28:22 menno Exp $
+** $Id: hcr.c,v 1.3 2003/04/01 16:34:34 menno Exp $
 **/
 
 #include "common.h"
@@ -547,6 +547,10 @@
              } /* of w */
          } /* of sfb */
     } /* of presort */
+
+    /* Avoid divide by zero */
+    if (numberOfSegments == 0)
+        return 10; /* this is not good... */
 
     numberOfSets = NrCodeWords / numberOfSegments;     
 
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.c,v 1.39 2003/02/09 20:42:49 menno Exp $
+** $Id: syntax.c,v 1.40 2003/04/01 16:34:34 menno Exp $
 **/
 
 /*
@@ -637,6 +637,8 @@
 static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
                         uint8_t common_window)
 {
+    uint8_t retval = 0;
+
     /* ics->ics_reserved_bit = */ faad_get1bit(ld
         DEBUGVAR(1,43,"ics_info(): ics_reserved_bit"));
     ics->window_sequence = (uint8_t)faad_getbits(ld, 2
@@ -653,7 +655,18 @@
     } else {
         ics->max_sfb = (uint8_t)faad_getbits(ld, 6
             DEBUGVAR(1,48,"ics_info(): max_sfb (long)"));
+    }
 
+    /* get the grouping information */
+    retval = window_grouping_info(hDecoder, ics);
+
+    /* should be an error */
+    /* check the range of max_sfb */
+    if (ics->max_sfb > ics->num_swb)
+        ics->max_sfb = ics->num_swb;
+
+    if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
+    {
         if ((ics->predictor_data_present = faad_get1bit(ld
             DEBUGVAR(1,49,"ics_info(): predictor_data_present"))) & 1)
         {
@@ -709,12 +722,11 @@
         }
     }
 
-    /* get the grouping information */
-    return window_grouping_info(hDecoder, ics);
+    return retval;
 }
 
 /* Table 4.4.7 */
-static void pulse_data(pulse_info *pul, bitfile *ld)
+static void pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld)
 {
     uint8_t i;
 
@@ -723,6 +735,10 @@
     pul->pulse_start_sfb = (uint8_t)faad_getbits(ld, 6
         DEBUGVAR(1,57,"pulse_data(): pulse_start_sfb"));
 
+    /* check the range of pulse_start_sfb */
+    if (pul->pulse_start_sfb > ics->num_swb)
+        pul->pulse_start_sfb = ics->num_swb;
+
     for (i = 0; i < pul->number_pulse+1; i++)
     {
         pul->pulse_offset[i] = (uint8_t)faad_getbits(ld, 5
@@ -908,7 +924,7 @@
         if ((ics->pulse_data_present = faad_get1bit(ld
             DEBUGVAR(1,68,"individual_channel_stream(): pulse_data_present"))) & 1)
         {
-            pulse_data(&(ics->pul), ld);
+            pulse_data(ics, &(ics->pul), ld);
         }
 
         /* get tns data */
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.h,v 1.25 2003/02/09 20:42:49 menno Exp $
+** $Id: syntax.h,v 1.26 2003/04/01 16:34:35 menno Exp $
 **/
 
 #ifndef __SYNTAX_H__
@@ -112,7 +112,7 @@
 uint8_t reordered_spectral_data(faacDecHandle hDecoder, ic_stream *ics,
                                 bitfile *ld, int16_t *spectral_data);
 #endif
-static void pulse_data(pulse_info *pul, bitfile *ld);
+static void pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld);
 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld);
 static void ltp_data(faacDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld);
 static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld);