summaryrefslogtreecommitdiff
path: root/src/libfaad/sbr_hfadj.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libfaad/sbr_hfadj.c')
-rw-r--r--src/libfaad/sbr_hfadj.c54
1 files changed, 41 insertions, 13 deletions
diff --git a/src/libfaad/sbr_hfadj.c b/src/libfaad/sbr_hfadj.c
index 081f731e9..efac06502 100644
--- a/src/libfaad/sbr_hfadj.c
+++ b/src/libfaad/sbr_hfadj.c
@@ -1,6 +1,6 @@
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
-** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
+** Copyright (C) 2003-2005 M. Bakker, Nero 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
@@ -19,10 +19,13 @@
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
+** The "appropriate copyright message" mentioned in section 2c of the GPLv2
+** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
+**
** Commercial non-GPL licensing of this software is possible.
-** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
+** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
**
-** $Id: sbr_hfadj.c,v 1.5 2005/10/29 23:57:07 tmmm Exp $
+** $Id: sbr_hfadj.c,v 1.22 2007/11/01 12:33:35 menno Exp $
**/
/* High Frequency adjustment */
@@ -39,8 +42,8 @@
/* static function declarations */
-static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
- qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
+static uint8_t estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
+ qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
static void calculate_gain(sbr_info *sbr, sbr_hfadj_info *adj, uint8_t ch);
#ifdef SBR_LOW_POWER
static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, uint8_t ch);
@@ -49,13 +52,14 @@ static void aliasing_reduction(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg,
static void hf_assembly(sbr_info *sbr, sbr_hfadj_info *adj, qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch);
-void hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
+uint8_t hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
#ifdef SBR_LOW_POWER
- ,real_t *deg /* aliasing degree */
+ ,real_t *deg /* aliasing degree */
#endif
- ,uint8_t ch)
+ ,uint8_t ch)
{
ALIGN sbr_hfadj_info adj = {{{0}}};
+ uint8_t ret = 0;
if (sbr->bs_frame_class[ch] == FIXFIX)
{
@@ -72,7 +76,9 @@ void hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
sbr->l_A[ch] = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
}
- estimate_current_envelope(sbr, &adj, Xsbr, ch);
+ ret = estimate_current_envelope(sbr, &adj, Xsbr, ch);
+ if (ret > 0)
+ return 1;
calculate_gain(sbr, &adj, ch);
@@ -82,6 +88,8 @@ void hf_adjustment(sbr_info *sbr, qmf_t Xsbr[MAX_NTSRHFG][64]
#endif
hf_assembly(sbr, &adj, Xsbr, ch);
+
+ return 0;
}
static uint8_t get_S_mapped(sbr_info *sbr, uint8_t ch, uint8_t l, uint8_t current_band)
@@ -125,8 +133,8 @@ static uint8_t get_S_mapped(sbr_info *sbr, uint8_t ch, uint8_t l, uint8_t curren
return 0;
}
-static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
- qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
+static uint8_t estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
+ qmf_t Xsbr[MAX_NTSRHFG][64], uint8_t ch)
{
uint8_t m, l, j, k, k_l, k_h, p;
real_t nrg, div;
@@ -142,6 +150,9 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
div = (real_t)(u_i - l_i);
+ if (div == 0)
+ div = 1;
+
for (m = 0; m < sbr->M; m++)
{
nrg = 0;
@@ -192,6 +203,9 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
div = (real_t)((u_i - l_i)*(k_h - k_l));
+ if (div == 0)
+ div = 1;
+
for (i = l_i + sbr->tHFAdj; i < u_i + sbr->tHFAdj; i++)
{
for (j = k_l; j < k_h; j++)
@@ -225,6 +239,8 @@ static void estimate_current_envelope(sbr_info *sbr, sbr_hfadj_info *adj,
}
}
}
+
+ return 0;
}
#ifdef FIXED_POINT
@@ -1342,15 +1358,27 @@ static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, ui
{
uint8_t l, k, i;
uint8_t grouping;
+ uint8_t S_mapped;
for (l = 0; l < sbr->L_E[ch]; l++)
{
+ uint8_t current_res_band = 0;
i = 0;
grouping = 0;
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band);
+
for (k = sbr->kx; k < sbr->kx + sbr->M - 1; k++)
{
- if (deg[k + 1] && adj->S_mapped[l][k-sbr->kx] == 0)
+ if (k == sbr->f_table_res[sbr->f[ch][l]][current_res_band+1])
+ {
+ /* step to next resolution band */
+ current_res_band++;
+
+ S_mapped = get_S_mapped(sbr, ch, l, current_res_band);
+ }
+
+ if (deg[k + 1] && S_mapped == 0)
{
if (grouping == 0)
{
@@ -1361,7 +1389,7 @@ static void calc_gain_groups(sbr_info *sbr, sbr_hfadj_info *adj, real_t *deg, ui
} else {
if (grouping)
{
- if (adj->S_mapped[l][k-sbr->kx])
+ if (S_mapped)
{
sbr->f_group[l][i] = k;
} else {