summaryrefslogtreecommitdiffstats
path: root/libfaad2/specrec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libfaad2/specrec.c')
-rw-r--r--libfaad2/specrec.c129
1 files changed, 61 insertions, 68 deletions
diff --git a/libfaad2/specrec.c b/libfaad2/specrec.c
index 8f3b8e6d9f..177050bc9b 100644
--- a/libfaad2/specrec.c
+++ b/libfaad2/specrec.c
@@ -22,7 +22,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
**
-** $Id: specrec.c,v 1.23 2003/07/29 08:20:13 menno Exp $
+** $Id: specrec.c,v 1.27 2003/09/30 12:43:05 menno Exp $
**/
/*
@@ -413,59 +413,43 @@ uint8_t window_grouping_info(faacDecHandle hDecoder, ic_stream *ics)
void quant_to_spec(ic_stream *ics, real_t *spec_data, uint16_t frame_len)
{
uint8_t g, sfb, win;
- uint16_t width, bin;
- real_t *start_inptr, *start_win_ptr, *win_ptr;
+ uint16_t width, bin, k, gindex;
real_t tmp_spec[1024];
- real_t *tmp_spec_ptr, *spec_ptr;
- tmp_spec_ptr = tmp_spec;
- memset(tmp_spec_ptr, 0, frame_len*sizeof(real_t));
+ memset(tmp_spec, 0, frame_len*sizeof(real_t));
- spec_ptr = spec_data;
- tmp_spec_ptr = tmp_spec;
- start_win_ptr = tmp_spec_ptr;
+ k = 0;
+ gindex = 0;
for (g = 0; g < ics->num_window_groups; g++)
{
uint16_t j = 0;
- uint16_t win_inc = 0;
-
- start_inptr = spec_ptr;
-
- win_inc = ics->swb_offset[ics->num_swb];
+ uint16_t gincrease = 0;
+ uint16_t win_inc = ics->swb_offset[ics->num_swb];
for (sfb = 0; sfb < ics->num_swb; sfb++)
{
width = ics->swb_offset[sfb+1] - ics->swb_offset[sfb];
- win_ptr = start_win_ptr;
-
for (win = 0; win < ics->window_group_length[g]; win++)
{
- tmp_spec_ptr = win_ptr + j;
-
for (bin = 0; bin < width; bin += 4)
{
- tmp_spec_ptr[0] = spec_ptr[0];
- tmp_spec_ptr[1] = spec_ptr[1];
- tmp_spec_ptr[2] = spec_ptr[2];
- tmp_spec_ptr[3] = spec_ptr[3];
- tmp_spec_ptr += 4;
- spec_ptr += 4;
+ tmp_spec[gindex+(win*win_inc)+j+bin+0] = spec_data[k+0];
+ tmp_spec[gindex+(win*win_inc)+j+bin+1] = spec_data[k+1];
+ tmp_spec[gindex+(win*win_inc)+j+bin+2] = spec_data[k+2];
+ tmp_spec[gindex+(win*win_inc)+j+bin+3] = spec_data[k+3];
+ gincrease += 4;
+ k += 4;
}
-
- win_ptr += win_inc;
}
j += width;
}
- start_win_ptr += (spec_ptr - start_inptr);
+ gindex += gincrease;
}
- spec_ptr = spec_data;
- tmp_spec_ptr = tmp_spec;
-
- memcpy(spec_ptr, tmp_spec_ptr, frame_len*sizeof(real_t));
+ memcpy(spec_data, tmp_spec, frame_len*sizeof(real_t));
}
#ifndef FIXED_POINT
@@ -483,6 +467,7 @@ void build_tables(real_t *pow2_table)
static INLINE real_t iquant(int16_t q, real_t *tab)
{
+#ifdef FIXED_POINT
int16_t sgn = 1;
if (q == 0) return 0;
@@ -494,26 +479,38 @@ static INLINE real_t iquant(int16_t q, real_t *tab)
}
if (q >= IQ_TABLE_SIZE)
- return sgn * tab[q>>3] * 16;
+ return 0; /* sgn * tab[q>>3] * 16; */
return sgn * tab[q];
+#else
+ int16_t sgn = 1;
+
+ if (q == 0) return 0;
+
+ if (q < 0)
+ {
+ q = -q;
+ sgn = -1;
+ }
+
+ if (q < IQ_TABLE_SIZE)
+ return sgn * tab[q];
+
+ return sgn * pow(q, 4./3.);
+#endif
}
void inverse_quantization(real_t *x_invquant, int16_t *x_quant, uint16_t frame_len)
{
int16_t i;
- int16_t *in_ptr = x_quant;
- real_t *out_ptr = x_invquant;
real_t *tab = iq_table;
- for(i = frame_len/4-1; i >= 0; --i)
+ for(i = 0; i < frame_len; i+=4)
{
- out_ptr[0] = iquant(in_ptr[0], tab);
- out_ptr[1] = iquant(in_ptr[1], tab);
- out_ptr[2] = iquant(in_ptr[2], tab);
- out_ptr[3] = iquant(in_ptr[3], tab);
- out_ptr += 4;
- in_ptr += 4;
+ x_invquant[i] = iquant(x_quant[i], tab);
+ x_invquant[i+1] = iquant(x_quant[i+1], tab);
+ x_invquant[i+2] = iquant(x_quant[i+2], tab);
+ x_invquant[i+3] = iquant(x_quant[i+3], tab);
}
}
@@ -538,17 +535,11 @@ static real_t pow2_table[] =
};
#endif
-#ifdef FIXED_POINT
void apply_scalefactors(faacDecHandle hDecoder, ic_stream *ics, real_t *x_invquant,
uint16_t frame_len)
-#else
-void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table,
- uint16_t frame_len)
-#endif
{
uint8_t g, sfb;
uint16_t top;
- real_t *fp;
#ifndef FIXED_POINT
real_t scale;
#else
@@ -557,26 +548,29 @@ void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table,
uint8_t groups = 0;
uint16_t nshort = frame_len/8;
+ static real_t max_fp = 0;
+ static real_t max_exp = 0;
+ static real_t max_frac = 0;
+
for (g = 0; g < ics->num_window_groups; g++)
{
uint16_t k = 0;
- /* using this 128*groups doesn't hurt long blocks, because
+ /* using this nshort*groups doesn't hurt long blocks, because
long blocks only have 1 group, so that means 'groups' is
always 0 for long blocks
*/
- fp = x_invquant + (groups*nshort);
-
for (sfb = 0; sfb < ics->max_sfb; sfb++)
{
top = ics->sect_sfb_offset[g][sfb+1];
#ifndef FIXED_POINT
- scale = get_scale_factor_gain(ics->scale_factors[g][sfb], pow2_table);
+ scale = get_scale_factor_gain(ics->scale_factors[g][sfb], hDecoder->pow2_table);
#else
exp = (ics->scale_factors[g][sfb] - 100) / 4;
frac = (ics->scale_factors[g][sfb] - 100) % 4;
+ /* IMDCT pre-scaling */
if (hDecoder->object_type == LD)
{
exp -= 6 /*9*/;
@@ -592,33 +586,32 @@ void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table,
for ( ; k < top; k += 4)
{
#ifndef FIXED_POINT
- fp[0] = fp[0] * scale;
- fp[1] = fp[1] * scale;
- fp[2] = fp[2] * scale;
- fp[3] = fp[3] * scale;
+ x_invquant[k+(groups*nshort)] = x_invquant[k+(groups*nshort)] * scale;
+ x_invquant[k+(groups*nshort)+1] = x_invquant[k+(groups*nshort)+1] * scale;
+ x_invquant[k+(groups*nshort)+2] = x_invquant[k+(groups*nshort)+2] * scale;
+ x_invquant[k+(groups*nshort)+3] = x_invquant[k+(groups*nshort)+3] * scale;
#else
if (exp < 0)
{
- fp[0] >>= -exp;
- fp[1] >>= -exp;
- fp[2] >>= -exp;
- fp[3] >>= -exp;
+ x_invquant[k+(groups*nshort)] >>= -exp;
+ x_invquant[k+(groups*nshort)+1] >>= -exp;
+ x_invquant[k+(groups*nshort)+2] >>= -exp;
+ x_invquant[k+(groups*nshort)+3] >>= -exp;
} else {
- fp[0] <<= exp;
- fp[1] <<= exp;
- fp[2] <<= exp;
- fp[3] <<= exp;
+ x_invquant[k+(groups*nshort)] <<= exp;
+ x_invquant[k+(groups*nshort)+1] <<= exp;
+ x_invquant[k+(groups*nshort)+2] <<= exp;
+ x_invquant[k+(groups*nshort)+3] <<= exp;
}
if (frac)
{
- fp[0] = MUL_R_C(fp[0],pow2_table[frac + 3]);
- fp[1] = MUL_R_C(fp[1],pow2_table[frac + 3]);
- fp[2] = MUL_R_C(fp[2],pow2_table[frac + 3]);
- fp[3] = MUL_R_C(fp[3],pow2_table[frac + 3]);
+ x_invquant[k+(groups*nshort)] = MUL_R_C(x_invquant[k+(groups*nshort)],pow2_table[frac + 3]);
+ x_invquant[k+(groups*nshort)+1] = MUL_R_C(x_invquant[k+(groups*nshort)+1],pow2_table[frac + 3]);
+ x_invquant[k+(groups*nshort)+2] = MUL_R_C(x_invquant[k+(groups*nshort)+2],pow2_table[frac + 3]);
+ x_invquant[k+(groups*nshort)+3] = MUL_R_C(x_invquant[k+(groups*nshort)+3],pow2_table[frac + 3]);
}
#endif
- fp += 4;
}
}
groups += ics->window_group_length[g];