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

📄 getbits.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: getbits * *  Written by: Jim Elliott * *  Reads serial bitstream file for decode program. * ******************************************************************************** *//* *  SCCS program and date keywords. */#ifndef lintstatic char *sccs_id = "@(#)getbits.c	1.2	11/25/87 ESI";#endif/* *  System include files. */#include <stdio.h>/* *  ESPS include files. */#include <esps/esps.h>#include <esps/fea.h>#include <esps/fea2kb.h>/* ******************************************************************************** *  Subroutine to read a bit field of a specified length from the input *  bitstream. ******************************************************************************** */get_bits( fea2kb_rec, ih, ifp, nbits, debug, dfp, field, cnt, stuff_inhib, stf )FILE *dfp, *ifp;int *cnt, debug, *field, nbits, *stf, stuff_inhib;struct fea2kb *fea2kb_rec;struct header *ih;{    unsigned long	bit,			/* On/off bit indicator */	c;			/* Unsigned copy of bit field */    static int	init = YES,		/* Flag for initial entry */	ones_cnt,		/* Consecutive one's counter */	state,			/* State of bitstream (1 or 0) */	sync_ones;		/* Number of ones in sync code */    static unsigned long	buf,			/* Bitstream buffer */	mask;			/* Mask for current bit */    if ( init )    {	init = NO;	if ( stuff_inhib )	    sync_ones = nbits - 2;	fill_buffer( fea2kb_rec, ih, ifp, debug, dfp, &buf, &mask );    }    c = 0;    *cnt = nbits;    for ( ; nbits >= 1; nbits-- )    {	c <<= 1;	if ( !stuff_inhib )	{	    bit = buf & mask;	    if ( state == 0 )	    {	        if ( bit )		{		    state = 1;		    ones_cnt = 1;		}	    }	    else	    {		if ( bit )		{		    ones_cnt++;		    if ( ones_cnt == sync_ones )		    {			mask >>= 1;			if ( mask == 0 )			    fill_buffer( fea2kb_rec, ih, ifp, debug, dfp, &buf, &mask );			(*stf)++;			ones_cnt++;			if ( debug >= 3 )			{			    Fprintf( dfp, "\t\t>>Stuffed bit @ 0x%lx:", mask );			    Fprintf( dfp, " Buffer = 0x%lx\n", buf );			}		    }		}		else		    state = 0;	    }	}	else	    state = 0;	if ( buf & mask )	    c |= 1;	if ( debug >= 3 )	    Fprintf( dfp, "\t\tField = 0x%x; Mask = 0x%x\n", c, mask );	mask >>= 1;	if ( mask == 0 )	    fill_buffer( fea2kb_rec, ih, ifp, debug, dfp, &buf, &mask );    }    *field = c;}/* ******************************************************************************** *  Subroutine to fill the bitstream buffer from input file. ******************************************************************************** */fill_buffer( fea2kb_rec, ih, ifp, debug, dfp, buf, mask )FILE *dfp, *ifp;int debug;struct fea2kb *fea2kb_rec;struct header *ih;unsigned long *buf, *mask;{    static int tot;		/* Total bits input from bitstream */    unsigned long err;		/* Error mask */    if ( get_fea2kb_rec( fea2kb_rec, ih, ifp ) == EOF )        Fprintf( stderr, "End of input file\n" );    *buf = *fea2kb_rec->bitstream;    err = *fea2kb_rec->error_mask;    tot += 8*sizeof(long);    if ( debug >= 4 )    {	Fprintf( dfp, "\t\t\tBitstream input = 0x%lx; Cumulative total = %d\n", *buf, tot );	if ( err )	    Fprintf( dfp, "\t\t\tError mask = 0x%lx; Corrupted input = 0x%lx\n",	        err, *buf ^ err );    }    *buf ^= err;    *mask = 0x80000000;}

⌨️ 快捷键说明

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