⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invert.c

📁 speech signal process tools
💻 C
字号:
/* ******************************************************************************** * *  This material contains proprietary software of Entropic Speech, Inc. *  Any reproduction, distribution, or publication without the the prior *  written permission of Entropic Speech, Inc. is strictly prohibited. *  Any public distribution of copies of this work authorized in writing *  by Entropic Speech, Inc. must bear the notice: * *     "Copyright (c) 1987 Entropic Speech, Inc.; all rights reserved" * *  Program: invert * *  Written by: Jim Elliott * *  Collection of subroutines to perform inverse quantization of spectral *  data, pulse length, and power. * ******************************************************************************** *//* *  SCCS program and date keywords. */#ifndef lintstatic char *sccs_id = "@(#)invert.c	1.1	10/6/87 ESI";#endif/* *  System include files. */#include <stdio.h>#include <math.h>/* *  ESPS include files. */#include <esps/esps.h>#include <esps/anafea.h>#include <esps/fea.h>#include <esps/feaquant.h>#include "qlsf.h"/* *  External functions and variables. */double tabdec();extern struct quantable pitqtable[], pwrqtable[];/* ******************************************************************************** *  Subroutine to invert LSFs. ******************************************************************************** */invert_lsf( auxana_rec, order_unvcd, order_vcd, lsf_quant, unvoiced_steps,    voiced_steps, quiet, anafea_rec )char *lsf_quant;int quiet;long order_unvcd, order_vcd;short unvoiced_steps, voiced_steps;struct anafea **anafea_rec;struct auxana *auxana_rec;{    int error, i, j, pass;    float *lsf, of, tmp;    long order;    short *index, nsteps;    static float tbl[67];    static int frame_cnt, N;    static short prev_steps;    frame_cnt++;    index = &auxana_rec->spec_param_idx[0];    lsf = &(*anafea_rec)->spec_param[0];    if ( *(*anafea_rec)->frame_type == VOICED )    {	nsteps = voiced_steps;	order = order_vcd;    }    else    {	nsteps = unvoiced_steps;	order = order_unvcd;    }/* *  If the step size has changed, load the quantized LSF values into the table. */    if ( nsteps != prev_steps )    {	tbl[0] = 300.0;	tbl[1] = 350.0;	i = 0;	j = 1;	while ( tbl[j] <= 4000.0 )	{	    tbl[j+1] = 		exp( log( 400.0 ) + (double) i * log( 2.0 ) / (double) nsteps );	    tbl[j+1] = ROUND( tbl[j+1] );	    i++;	    j++;	}	N = j;    }    prev_steps = nsteps;/* *  Now perform inverse LSF quantization, using the specified method. */    if ( ( strcmp( lsf_quant, "direct" ) ) == 0 )    {	for ( i = 0; i < order; i++ )	{	    lsf[i] = tbl[ index[i] ];	    if ( i > 0 && index[i] == index[i-1] && !quiet )	    {		Fprintf( stderr, "\nWARNING: LSFs equal at frame %d:", frame_cnt );		Fprintf( stderr, "\n\tLSF[%d] = %6.1f; LSF[%d] = %6.1f\n",		    i-1, lsf[i-1], i, lsf[i] );	    }	}	return;    }    else if ( ( strcmp( lsf_quant, "ctr_off" ) ) == 0 )    {	for ( i = 0; i < order/2; i++ )	{	    of = tbl[ index[2*i] + index[2*i+1] ] - tbl[ index[2*i] ];	    lsf[2*i] = tbl[ index[2*i] ] - of;	    if ( lsf[2*i] <= tbl[0] )	        lsf[2*i] = tbl[0];	    else if ( lsf[2*i] >= tbl[N-1] )	        lsf[2*i] = tbl[N-1];	    else	    {	        j = 1;	        while ( lsf[2*i] > tbl[j] )	            j++;	        if ( lsf[2*i] < 0.5 * ( tbl[j-1] + tbl[j] ) )	            lsf[2*i] = tbl[j-1];	        else		    lsf[2*i] = tbl[j];	    }	    lsf[2*i+1] = tbl[ index[2*i] ] + of;	}	pass = 0;	do	{	    pass++;	    error = NO;	    for ( i = 1; i < order; i++ )	    {		if ( lsf[i] < lsf[i-1] )		{		    if ( !quiet )		    {			Fprintf( stderr, "\nLSF reversal on pass %d at frame %d:",			    pass, frame_cnt );			Fprintf( stderr, "\n\tLSF[%d] = %6.1f; LSF[%d] = %6.1f -- ",			    i-1, lsf[i-1], i, lsf[i] );			Fprintf( stderr, "swapping LSF values\n" );		    }		    error = YES;		    tmp = lsf[i-1];		    lsf[i-1] = lsf[i];		    lsf[i] = tmp;		}		if ( lsf[i] == lsf[i-1] )		{		    if ( !quiet )		    {			Fprintf( stderr, "\nLSFs equal on pass %d at frame %d:",			    pass, frame_cnt );			Fprintf( stderr, "\n\tLSF[%d] = %6.1f; LSF[%d] = %6.1f -- ",			    i-1, lsf[i-1], i, lsf[i] );			Fprintf( stderr, "incrementing index of LSF[%d]\n", i );		    }		    error = YES;		    for ( j = 1; j < N; j++ )			if( lsf[i] == tbl[j] )			    break;		    lsf[i] = tbl[j+1];		}	    }	}	while ( error && pass < 3 );	if ( error && pass == 3 )	    Fprintf( stderr, "\nWARNING: LSF error not fixed after 3 passes\n" );	return;    }}/* ******************************************************************************** *  Subroutine to invert power. ******************************************************************************** */invert_power( auxana_rec, maxraw, power_quant, anafea_rec )char *power_quant;long maxraw;struct anafea **anafea_rec;struct auxana *auxana_rec;{    double qpwr;    int i, index, np;    if ( ( strcmp( power_quant, "6_bit" ) ) == 0 )        index = FINE;    else if ( ( strcmp( power_quant, "1.5_dB" ) ) == 0 )        index = COARSE;    if ( *(*anafea_rec)->frame_type == UNVOICED )        np = 1;    else        np = *(*anafea_rec)->num_pulses;    for ( i = 0; i < maxraw; i++ )    {	if ( i >= np )	    (*anafea_rec)->raw_power[i] = -1.0;	else	{	    qpwr = tabdec( auxana_rec->raw_power_idx[i], index, pwrqtable );	    qpwr = qpwr * qpwr;	    (*anafea_rec)->raw_power[i] = qpwr;	}    }}/* ******************************************************************************** *  Subroutine to invert pitch. ******************************************************************************** */invert_pitch( auxana_rec, maxpulses, pitch_quant, anafea_rec )char *pitch_quant;long maxpulses;struct anafea **anafea_rec;struct auxana *auxana_rec;{    double qpit;    int i, np;    if ( *(*anafea_rec)->frame_type == UNVOICED )        return;    np = *(*anafea_rec)->num_pulses;    for ( i = 0; i < maxpulses; i++ )    {	if ( i >= np )	    (*anafea_rec)->p_pulse_len[i] = 0.0;	else	{	    if ( ( strcmp( pitch_quant, "2_sample" ) ) == 0 )	        qpit = tabdec( auxana_rec->pulse_len_idx[i], 0, pitqtable );	    else	        qpit = auxana_rec->pulse_len_idx[i];	    (*anafea_rec)->p_pulse_len[i] = qpit;	    *(*anafea_rec)->frame_len += qpit;	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -