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

📄 reconst.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ******************************************************************************** * *  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: reconst * *  Written by: Jim Elliott * *  Collection of subroutines to reconstruct quantization indices and frame *  parameters in augmented FEA_ANA file. * ******************************************************************************** *//* *  SCCS program and date keywords. */#ifndef lintstatic char *sccs_id = "@(#)reconst.c	1.2	11/25/87 ESI";#endif/* *  System include files. */#include <stdio.h>/* *  ESPS include files. */#include <esps/esps.h>#include <esps/anafea.h>#include <esps/encode.h>#include <esps/fea.h>#include <esps/fea2kb.h>#include <esps/feaqhist.h>#include <esps/feaquant.h>/* *  External functions and variables. */struct tbl_entry    huff_tbl[];			/* Concatenated Huffman tables */struct key    key_tbl[];			/* Table of offsets in big table *//* ******************************************************************************** *  Subroutine to decode frame sync. ******************************************************************************** */get_sync( sync_len, debug, dfp, bs, fea2kb_rec, ih, ifp )FILE *dfp, *ifp;int debug, sync_len;struct bit_stats *bs;struct fea2kb *fea2kb_rec;struct header *ih;{    int	cnt = 0,		/* Bit count */	i,			/* Loop variable */	stuff = 0,		/* Bits unstuffed by get_bits() */	value;			/* State value */    static int	sync_code = 0;		/* Sync code word */    if ( sync_code == 0 )    {	sync_code = 2;	for ( i = 1; i <= sync_len - 3; i++ )	    sync_code = sync_code << 1 | 2;    }    get_bits( fea2kb_rec, ih, ifp, sync_len, debug, dfp, &value, &cnt, YES, &stuff );    if ( debug >= 2 )	debug_print( "SYNC", value, value, sync_len, "RAW", dfp );    if ( stuff )	Fprintf( stderr, "**WARNING: %d bits unstuffed during sync reading\n", stuff );    if ( value != sync_code )	Fprintf( stderr, "**ERROR: sync not found where expected\n" );    bs->sync += sync_len;    bs->stuff += stuff;}/* ******************************************************************************** *  Subroutine to decode TYPE and EXT fields, and reconstruct frame_type and *  num_pulses fields of the FEA_ANA data record. ******************************************************************************** */reconst_type_ext( prev_type, fea2kb_rec, ih, ifp, debug, dfp,    anafea_rec, type, ext, bs )FILE *dfp, *ifp;int debug, *ext, *type;short prev_type;struct anafea **anafea_rec;struct bit_stats *bs;struct fea2kb *fea2kb_rec;struct header *ih;{    int	ext_cnt = 0,		/* Extension bits */	stuff = 0,		/* Accumulated number of stuffed bits */	type_cnt;		/* Type field bits */    static long	prev_pulses;		/* Previous number of pulses */    get_state_val( fea2kb_rec, ih, ifp, TYPE, MAX_TYPE, 0, debug, dfp, type, &type_cnt,        &stuff );    if ( *type == -1 )    {	if ( debug >= 2 )	    Fprintf( dfp, "\n*** EOF detected: TYPE = -1\n" );        return( EOF );    }    if ( *type == 0 )    {        *(*anafea_rec)->frame_type = prev_type;        if ( *(*anafea_rec)->frame_type == UNVOICED )	    *(*anafea_rec)->num_pulses = 0;        else            *(*anafea_rec)->num_pulses = prev_pulses;    }    else if ( *type == 1 )    {	get_state_val( fea2kb_rec, ih, ifp, EXT, MAX_EXT, 0, debug, dfp, ext, &ext_cnt,	    &stuff );	if ( *ext == VCD )	{	    *(*anafea_rec)->frame_type = VOICED;	    *(*anafea_rec)->num_pulses = 1;	}	else	{	    *(*anafea_rec)->frame_type = UNVOICED;	    *(*anafea_rec)->num_pulses = 0;	}    }    else    {        *(*anafea_rec)->frame_type = VOICED;        *(*anafea_rec)->num_pulses = *type;    }    if ( *(*anafea_rec)->frame_type == VOICED )    {	*(*anafea_rec)->voiced_fraction = 1.0;	bs->vcd_frm++;    }    else    {        *(*anafea_rec)->voiced_fraction = 0.0;	bs->unv_frm++;    }    prev_pulses = *(*anafea_rec)->num_pulses;    bs->frm_bits += type_cnt + ext_cnt + stuff;    bs->ftype += type_cnt;    bs->ext += ext_cnt;    bs->stuff += stuff;    return( 0 );}/* ******************************************************************************** *  Subroutine to decode POWER field, and reconstruct raw_power_idx field of *  the FEA_ANA data record. ******************************************************************************** */reconst_pwr( cont_pwr, prev_type, fea2kb_rec, ih, ifp, re_sync, debug,    dfp, anafea_rec, auxana_rec, bs )FILE *dfp, *ifp;int debug, re_sync;short cont_pwr, prev_type;struct auxana **auxana_rec;struct anafea **anafea_rec;struct bit_stats *bs;struct fea2kb *fea2kb_rec;struct header *ih;{    int	cnt,			/* Bit count */	i,			/* Loop variable */	np,			/* Number of voiced pulses */	stuff = 0,		/* Accumulated number of stuffed bits */	temp,			/* Temporary variable */	value;			/* State value */    static short	last;			/* Last index coded */    for ( i = 0; i < *(long *) get_genhd( "maxraw", ih ); i++ )        (*auxana_rec)->raw_power_idx[i] = 0;    if ( *(*anafea_rec)->frame_type == UNVOICED )    {	if ( !re_sync && ( cont_pwr == YES || prev_type == UNVOICED ) )	{	    get_state_val( fea2kb_rec, ih, ifp, POWER, MAX_PWR, RAW_PWR, debug, dfp,	        &value, &cnt, &stuff );	    (*auxana_rec)->raw_power_idx[0] = last + value;	}	else	{	    get_bits( fea2kb_rec, ih, ifp, RAW_PWR, debug, dfp, &value, &cnt, NO, &stuff );	    (*auxana_rec)->raw_power_idx[0] = value;	    if ( debug >= 2 )	        debug_print( "POWER", (*auxana_rec)->raw_power_idx[0], value, cnt, "RAW",		    dfp );	}	last = (*auxana_rec)->raw_power_idx[0];	bs->frm_pwr = cnt;	bs->frm_bits += cnt + stuff;	bs->u_pwr += cnt;	bs->stuff += stuff;	return;    }    np = *(*anafea_rec)->num_pulses;    bs->pulses += np;    if ( !re_sync && ( cont_pwr == YES || prev_type == VOICED ) )    {	get_state_val( fea2kb_rec, ih, ifp, POWER, MAX_PWR, RAW_PWR, debug, dfp, &value,	    &cnt, &stuff );	(*auxana_rec)->raw_power_idx[0] = last + value;    }    else    {	get_bits( fea2kb_rec, ih, ifp, RAW_PWR, debug, dfp, &value, &cnt, NO, &stuff );	(*auxana_rec)->raw_power_idx[0] = value;	if ( debug >= 2 )	    debug_print( "POWER", (*auxana_rec)->raw_power_idx[0], value, cnt, "RAW", dfp );    }    for ( i = 1; i < np; i++ )    {	get_state_val( fea2kb_rec, ih, ifp, POWER, MAX_PWR, RAW_PWR, debug, dfp, &value,	    &temp, &stuff );	(*auxana_rec)->raw_power_idx[i] = (*auxana_rec)->raw_power_idx[i-1] + value;	cnt += temp;    }    last = (*auxana_rec)->raw_power_idx[np-1];    bs->frm_pwr = cnt;    bs->frm_bits += cnt + stuff;    bs->v_pwr += cnt;    bs->stuff += stuff;}/* ******************************************************************************** *  Subroutine to decode LENGTH field, and reconstruct pulse_len_idx field of *  the FEA_ANA data record. ******************************************************************************** */reconst_len( prev_type, uvced_frmlen, fea2kb_rec, ih, ifp, re_sync, debug,    dfp, type, ext, anafea_rec, auxana_rec, bs )FILE *dfp, *ifp;int debug, ext, re_sync, type, uvced_frmlen;short prev_type;struct auxana **auxana_rec;struct anafea **anafea_rec;struct bit_stats *bs;struct fea2kb *fea2kb_rec;struct header *ih;{    int	cnt = 0,		/* Bit count */	i,			/* Loop variable */	np,			/* Number of voiced pulses */	stuff = 0,		/* Accumulated number of stuffed bits */	temp,			/* Temporary variable */	value;			/* State value */    static long	last_u;			/* Last unvoiced frame length coded */    static short	last_v;			/* Last voiced pulse length coded */    for ( i = 0; i < *(long *) get_genhd( "maxpulses", ih ); i++ )        (*auxana_rec)->pulse_len_idx[i] = 0;    if ( *(*anafea_rec)->frame_type == UNVOICED )

⌨️ 快捷键说明

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