diff libfaad2/tns.c @ 12527:4a370c80fe5c

update to the 2.0 release of faad, patch by adland
author diego
date Wed, 02 Jun 2004 22:59:04 +0000
parents 3185f64f6350
children d81145997036
line wrap: on
line diff
--- a/libfaad2/tns.c	Wed Jun 02 22:52:00 2004 +0000
+++ b/libfaad2/tns.c	Wed Jun 02 22:59:04 2004 +0000
@@ -1,6 +1,6 @@
 /*
 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
 **  
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
 **
-** $Id: tns.c,v 1.22 2003/09/09 18:09:52 menno Exp $
+** $Id: tns.c,v 1.2 2003/10/03 22:22:27 alex Exp $
 **/
 
 #include "common.h"
@@ -31,6 +31,16 @@
 #include "syntax.h"
 #include "tns.h"
 
+
+/* static function declarations */
+static void tns_decode_coef(uint8_t order, uint8_t coef_res_bits, uint8_t coef_compress,
+                            uint8_t *coef, real_t *a);
+static void tns_ar_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
+                          uint8_t order);
+static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
+                          uint8_t order);
+
+
 #ifdef _MSC_VER
 #pragma warning(disable:4305)
 #pragma warning(disable:4244)
@@ -71,7 +81,8 @@
 {
     uint8_t w, f, tns_order;
     int8_t inc;
-    uint16_t bottom, top, start, end, size;
+    int16_t size;
+    uint16_t bottom, top, start, end;
     uint16_t nshort = frame_len/8;
     real_t lpc[TNS_MAX_ORDER+1];
 
@@ -93,10 +104,16 @@
             tns_decode_coef(tns_order, tns->coef_res[w]+3,
                 tns->coef_compress[w][f], tns->coef[w][f], lpc);
 
-            start = ics->swb_offset[min(bottom, ics->max_sfb)];
-            end = ics->swb_offset[min(top, ics->max_sfb)];
+            start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
+            start = min(start, ics->max_sfb);
+            start = ics->swb_offset[start];
 
-            if ((size = end - start) <= 0)
+            end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
+            end = min(end, ics->max_sfb);
+            end = ics->swb_offset[end];
+
+            size = end - start;
+            if (size <= 0)
                 continue;
 
             if (tns->direction[w][f])
@@ -118,7 +135,8 @@
 {
     uint8_t w, f, tns_order;
     int8_t inc;
-    uint16_t bottom, top, start, end, size;
+    int16_t size;
+    uint16_t bottom, top, start, end;
     uint16_t nshort = frame_len/8;
     real_t lpc[TNS_MAX_ORDER+1];
 
@@ -140,10 +158,16 @@
             tns_decode_coef(tns_order, tns->coef_res[w]+3,
                 tns->coef_compress[w][f], tns->coef[w][f], lpc);
 
-            start = ics->swb_offset[min(bottom, ics->max_sfb)];
-            end = ics->swb_offset[min(top, ics->max_sfb)];
+            start = min(bottom, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
+            start = min(start, ics->max_sfb);
+            start = ics->swb_offset[start];
 
-            if ((size = end - start) <= 0)
+            end = min(top, max_tns_sfb(sr_index, object_type, (ics->window_sequence == EIGHT_SHORT_SEQUENCE)));
+            end = min(end, ics->max_sfb);
+            end = ics->swb_offset[end];
+
+            size = end - start;
+            if (size <= 0)
                 continue;
 
             if (tns->direction[w][f])
@@ -192,7 +216,7 @@
     for (m = 1; m <= order; m++)
     {
         for (i = 1; i < m; i++) /* loop only while i<m */
-            b[i] = a[i] + MUL_C_C(tmp2[m-1], a[m-i]);
+            b[i] = a[i] + MUL_C(tmp2[m-1], a[m-i]);
 
         for (i = 1; i < m; i++) /* loop only while i<m */
             a[i] = b[i];
@@ -225,7 +249,7 @@
         y = *spectrum;
 
         for (j = 0; j < order; j++)
-            y -= MUL_R_C(state[j], lpc[j+1]);
+            y -= MUL_C(state[j], lpc[j+1]);
 
         for (j = order-1; j > 0; j--)
             state[j] = state[j-1];
@@ -260,7 +284,7 @@
         y = *spectrum;
 
         for (j = 0; j < order; j++)
-            y += MUL_R_C(state[j], lpc[j+1]);
+            y += MUL_C(state[j], lpc[j+1]);
 
         for (j = order-1; j > 0; j--)
             state[j] = state[j-1];