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

📄 cntbits.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: cntbits * *  Written by: Jim Elliott * *  Collection of subroutines to accumulate bit coding statistics for *  encode program. * ******************************************************************************** *//* *  SCCS program and date keywords. */#ifndef lintstatic char *sccs_id = "@(#)cntbits.c	1.1	10/6/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. */extern struct tbl_entry    huff_tbl[];			/* Concatenated Huffman tables */extern struct key    key_tbl[];			/* Table of offsets in big table *//* ******************************************************************************** *  Subroutine to encode frame sync. ******************************************************************************** */cnt_sync( sync_len, debug, dfp, eof, bs, fea2kb_rec, oh, ofp )FILE *dfp, *ofp;int debug, eof, sync_len;struct bit_stats *bs;struct fea2kb *fea2kb_rec;struct header *oh;{    int	i,			/* Loop variable */	stuff = 0;		/* Bits stuffed by pack_bits() */    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;    }    if ( debug >= 2 )	debug_print( "SYNC", sync_code, sync_code, sync_len, "RAW", dfp );    pack_bits( sync_code, sync_len, debug, dfp, fea2kb_rec, oh, ofp, YES, &stuff );    if ( stuff )	Fprintf( stderr, "**WARNING: %d bits stuffed during sync packing\n", stuff );    if ( eof )	return;    bs->sync += sync_len;    bs->stuff += stuff;}/* ******************************************************************************** *  Subroutine to encode type and extension fields. The type field is sent *  every frame, the extension field only for frames having a single pulse. ******************************************************************************** */cnt_type_ext( anafea_rec, prev_type, uvced_frmlen, re_sync, debug, dfp, bs,    fea2kb_rec, oh, ofp )FILE *dfp, *ofp;int debug, re_sync, uvced_frmlen;short prev_type;struct anafea *anafea_rec;struct bit_stats *bs;struct fea2kb *fea2kb_rec;struct header *oh;{    int	ext_code,		/* Huffman code (extension) */	ext_cnt = 0,		/* Extension bits */	stuff = 0,		/* Accumulated number of stuffed bits */	type_code,		/* Huffman code (type) */	type_cnt;		/* Type field bits */    long	fl,			/* Frame length */	np;			/* Number of pulses */    short	ft;			/* Frame type */    static long	prev_length,		/* Previous frame length */	prev_pulses;		/* Previous number of pulses */    np = *anafea_rec->num_pulses;    fl = *anafea_rec->frame_len;    ft = *anafea_rec->frame_type;    if ( ft == VOICED )	bs->vcd_frm++;    else	bs->unv_frm++;    if ( !re_sync && ft == prev_type )    {	if ( ft == VOICED )	{	    if ( np == prev_pulses )		huff( 0, TYPE, MAX_TYPE, 0, debug, dfp, &type_code, &type_cnt );	    else		huff( (int) np, TYPE, MAX_TYPE, 0, debug, dfp, &type_code, &type_cnt );	    if ( np == 1 )		huff( VCD, EXT, MAX_EXT, 0, debug, dfp, &ext_code, &ext_cnt );	}	else	{	    if ( fl == prev_length )		huff( 0, TYPE, MAX_TYPE, 0, debug, dfp, &type_code, &type_cnt );	    else	    {		huff( 1, TYPE, MAX_TYPE, 0, debug, dfp, &type_code, &type_cnt );		if ( fl == uvced_frmlen )		    huff( UNVCD_STD, EXT, MAX_EXT, 0, debug, dfp, &ext_code, &ext_cnt );		else		    huff( UNVCD_NONSTD, EXT, MAX_EXT, 0, debug, dfp, &ext_code,		        &ext_cnt );	    }	}    }    else    {	if ( ft == VOICED )	{	    huff( (int) np, TYPE, MAX_TYPE, 0, debug, dfp, &type_code, &type_cnt );	    if ( np == 1 )		huff( VCD, EXT, MAX_EXT, 0, debug, dfp, &ext_code, &ext_cnt );	}	else	{	    huff( 1, TYPE, MAX_TYPE, 0, debug, dfp, &type_code, &type_cnt );	    if ( fl == uvced_frmlen )		huff( UNVCD_STD, EXT, MAX_EXT, 0, debug, dfp, &ext_code, &ext_cnt );	    else		huff( UNVCD_NONSTD, EXT, MAX_EXT, 0, debug, dfp, &ext_code, &ext_cnt );	}    }        pack_bits( type_code, type_cnt, debug, dfp, fea2kb_rec, oh, ofp, NO, &stuff );    if ( ext_cnt )	pack_bits( ext_code, ext_cnt, debug, dfp, fea2kb_rec, oh, ofp, NO, &stuff );    prev_pulses = np;    prev_length = fl;    bs->frm_bits += type_cnt + ext_cnt + stuff;    bs->ftype += type_cnt;    bs->ext += ext_cnt;    bs->stuff += stuff;}/* ******************************************************************************** *  Subroutine to encode power. The coding method is specified by the *  cont_pwr option flag. ******************************************************************************** */cnt_pwr( anafea_rec, auxana_rec, cont_pwr, prev_type, re_sync, debug, dfp, bs,    fea2kb_rec, oh, ofp )FILE *dfp, *ofp;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 *oh;{    int	cnt,			/* Bit count */	code,			/* Huffman code */	i,			/* Loop variable */	np,			/* Number of voiced pulses */	stuff = 0,		/* Accumulated number of stuffed bits */	temp;			/* Temporary variable */    static short	last;			/* Last index coded */    if ( *anafea_rec->frame_type == UNVOICED )    {	if ( !re_sync && ( cont_pwr == YES || prev_type == UNVOICED ) )	    huff( auxana_rec->raw_power_idx[0] - last, POWER, MAX_PWR, RAW_PWR, debug,	        dfp, &code, &cnt );	else	{	    code = auxana_rec->raw_power_idx[0];	    cnt = RAW_PWR;	    if ( debug >= 2 )	        debug_print( "POWER", auxana_rec->raw_power_idx[0], code, cnt, "RAW",		    dfp );	}	pack_bits( code, cnt, debug, dfp, fea2kb_rec, oh, ofp, NO, &stuff );	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 ) )	huff( auxana_rec->raw_power_idx[0] - last, POWER, MAX_PWR, RAW_PWR, debug,	    dfp, &code, &cnt );    else    {	code = auxana_rec->raw_power_idx[0];	cnt = RAW_PWR;	if ( debug >= 2 )	    debug_print( "POWER", auxana_rec->raw_power_idx[0], code, cnt, "RAW", dfp );    }    pack_bits( code, cnt, debug, dfp, fea2kb_rec, oh, ofp, NO, &stuff );    for ( i = 1; i < np; i++ )    {	huff( auxana_rec->raw_power_idx[i] - auxana_rec->raw_power_idx[i-1], POWER,	    MAX_PWR, RAW_PWR, debug, dfp, &code, &temp );	pack_bits( code, temp, debug, dfp, fea2kb_rec, oh, ofp, NO, &stuff );	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 encode frame or pulse length.  ******************************************************************************** */cnt_len( anafea_rec, auxana_rec, prev_type, uvced_frmlen, re_sync, debug, dfp, bs,    fea2kb_rec, oh, ofp )FILE *dfp, *ofp;int debug, re_sync, uvced_frmlen;short prev_type;struct auxana *auxana_rec;struct anafea *anafea_rec;struct bit_stats *bs;struct fea2kb *fea2kb_rec;struct header *oh;{    int	cnt,			/* Bit count */

⌨️ 快捷键说明

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