www.pudn.com > mp3rar.rar > tns.c
/************************* MPEG-2 NBC Audio Decoder **************************
* *
"This software module was originally developed by
AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS in the course of
development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7,
14496-1,2 and 3. This software module is an implementation of a part of one or more
MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio
standards free license to this software module or modifications thereof for use in
hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4
Audio standards. Those intending to use this software module in hardware or
software products are advised that this use may infringe existing patents.
The original developer of this software module and his/her company, the subsequent
editors and their companies, and ISO/IEC have no liability for use of this software
module or modifications thereof in an implementation. Copyright is not released for
non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developer
retains full right to use the code for his/her own purpose, assign or donate the
code to a third party and to inhibit third party from using the code for non
MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice must
be included in all copies or derivative works."
Copyright(c)1996.
* *
****************************************************************************/
#include "all.h"
#define sfb_offset(x) ( ((x) > 0) ? sfb_top[(x)-1] : 0 )
/* Decoder transmitted coefficients for one TNS filter */
void
tns_decode_coef( int order, int coef_res, short *coef, Float *a )
{
int i, m;
Float iqfac, iqfac_m;
Float tmp[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
/* Inverse quantization */
iqfac = (float)(((1 << (coef_res-1)) - 0.5) / (C_PI/2.0));
iqfac_m = (float)(((1 << (coef_res-1)) + 0.5) / (C_PI/2.0));
for (i=0; i= 0) ? iqfac : iqfac_m) );
}
/* Conversion to LPC coefficients
* Markel and Gray, pg. 95
*/
a[0] = 1;
for (m=1; m<=order; m++) {
b[0] = a[0];
for (i=1; i0; j--)
state[j] = state[j-1];
state[0] = y;
*spec = y;
spec += inc;
}
}
/* TNS decoding for one channel and frame */
void
tns_decode_subblock(Float *spec, int nbands, short *sfb_top, int islong,
TNSinfo *tns_info)
{
int f, m, start, stop, size, inc;
int n_filt, coef_res, order, direction;
short *coef;
Float lpc[TNS_MAX_ORDER+1];
TNSfilt *filt;
n_filt = tns_info->n_filt;
for (f=0; fcoef_res;
filt = &tns_info->filt[f];
order = filt->order;
direction = filt->direction;
coef = filt->coef;
start = filt->start_band;
stop = filt->stop_band;
m = tns_max_order(islong);
if (order > m) {
// CommonWarning("Error in tns max order");
order = m;
}
if (!order) continue;
tns_decode_coef( order, coef_res, coef, lpc );
start = min(start, tns_max_bands(islong));
start = min(start, nbands);
start = sfb_offset( start );
stop = min(stop, tns_max_bands(islong));
stop = min(stop, nbands);
stop = sfb_offset( stop );
if ((size = stop - start) <= 0) continue;
if (direction) {
inc = -1;
} else {
inc = 1;
}
tns_ar_filter( &spec[start], size, inc, lpc, order );
}
}