ref: c44c0332357abb38513127baeb4303c2c4663e44
parent: 584e5f7e8212f70af2d8480f580ce7005a6579c5
author: menno <menno>
date: Fri Feb 14 09:54:25 EST 2003
Made TNS more non-conformant-encoder safe
--- a/libfaad/tns.c
+++ b/libfaad/tns.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: tns.c,v 1.18 2002/11/28 18:48:30 menno Exp $
+** $Id: tns.c,v 1.19 2003/02/14 14:54:24 menno Exp $
**/
#include "common.h"
@@ -111,8 +111,7 @@
{
top = bottom;
bottom = max(top - tns->length[w][f], 0);
- tns_order = min(tns->order[w][f], tns_max_order(ics, sr_index,
- object_type));
+ tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
if (!tns_order)
continue;
@@ -119,12 +118,8 @@
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,
- min(tns_max_bands(ics, sr_index, object_type, frame_len),
- ics->max_sfb))];
- end = ics->swb_offset[min(top,
- min(tns_max_bands(ics, sr_index, object_type, frame_len),
- ics->max_sfb))];
+ start = ics->swb_offset[min(bottom, ics->max_sfb)];
+ end = ics->swb_offset[min(top, ics->max_sfb)];
if ((size = end - start) <= 0)
continue;
@@ -163,8 +158,7 @@
{
top = bottom;
bottom = max(top - tns->length[w][f], 0);
- tns_order = min(tns->order[w][f], tns_max_order(ics, sr_index,
- object_type));
+ tns_order = min(tns->order[w][f], TNS_MAX_ORDER);
if (!tns_order)
continue;
@@ -171,12 +165,8 @@
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,
- min(tns_max_bands(ics, sr_index, object_type, frame_len),
- ics->max_sfb))];
- end = ics->swb_offset[min(top,
- min(tns_max_bands(ics, sr_index, object_type, frame_len),
- ics->max_sfb))];
+ start = ics->swb_offset[min(bottom, ics->max_sfb)];
+ end = ics->swb_offset[min(top, ics->max_sfb)];
if ((size = end - start) <= 0)
continue;
@@ -304,84 +294,4 @@
*spectrum = y;
spectrum += inc;
}
-}
-
-static uint8_t tns_max_bands_table[12][6] =
-{
- /* entry for each sampling rate
- * 1 Main/LC long window
- * 2 Main/LC short window
- * 3 SSR long window
- * 4 SSR short window
- * 5 LD 512 window
- * 6 LD 480 window
- */
- { 31, 9, 28, 7, 0, 0 }, /* 96000 */
- { 31, 9, 28, 7, 0, 0 }, /* 88200 */
- { 34, 10, 27, 7, 0, 0 }, /* 64000 */
- { 40, 14, 26, 6, 31, 31 }, /* 48000 */
- { 42, 14, 26, 6, 32, 32 }, /* 44100 */
- { 51, 14, 26, 6, 37, 37 }, /* 32000 */
- { 46, 14, 29, 7, 31, 30 }, /* 24000 */
- { 46, 14, 29, 7, 31, 30 }, /* 22050 */
- { 42, 14, 23, 8, 0, 0 }, /* 16000 */
- { 42, 14, 23, 8, 0, 0 }, /* 12000 */
- { 42, 14, 23, 8, 0, 0 }, /* 11025 */
- { 39, 14, 19, 7, 0, 0 }, /* 8000 */
-};
-
-static uint8_t tns_max_bands(ic_stream *ics, uint8_t sr_index,
- uint8_t object_type, uint16_t frame_len)
-{
- uint8_t i;
-
- i = (ics->window_sequence == EIGHT_SHORT_SEQUENCE) ? 1 : 0;
-#ifdef LD_DEC
- if (object_type == LD)
- {
- if (frame_len == 512)
- i = 4;
- else
- i = 5;
- }
-#endif
-
- return tns_max_bands_table[sr_index][i];
-}
-
-static uint8_t tns_max_order(ic_stream *ics, uint8_t sr_index,
- uint8_t object_type)
-{
- /* Correction in 14496-3 Cor. 1
- Works like MPEG2-AAC (13818-7) now
-
- For other object types (scalable) the following goes for tns max order
- for long windows:
- if (sr_index <= 5)
- return 12;
- else
- return 20;
- */
- if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
- {
- switch (object_type)
- {
- case MAIN:
- case LTP:
- case ER_LTP:
-#ifdef LD_DEC
- case LD:
-#endif
- return 20;
- case LC:
- case ER_LC:
- case DRM_ER_LC:
- case SSR:
- return 12;
- }
- } else {
- return 7;
- }
-
- return 0;
}
--- a/libfaad/tns.h
+++ b/libfaad/tns.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: tns.h,v 1.5 2002/09/15 22:02:30 menno Exp $
+** $Id: tns.h,v 1.6 2003/02/14 14:54:25 menno Exp $
**/
#ifndef __TNS_H__
@@ -41,10 +41,6 @@
uint8_t order);
static void tns_ma_filter(real_t *spectrum, uint16_t size, int8_t inc, real_t *lpc,
uint8_t order);
-static uint8_t tns_max_bands(ic_stream *ics, uint8_t sr_index, uint8_t object_type,
- uint16_t frame_len);
-static uint8_t tns_max_order(ic_stream *ics, uint8_t sr_index,
- uint8_t object_type);
#ifdef __cplusplus