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

📄 pkbits.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: pkbits * *  Written by: Jim Elliott * *  Produces serial bitstream file for encode program. * ******************************************************************************** *//* *  SCCS program and date keywords. */#ifndef lintstatic char *sccs_id = "@(#)pkbits.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 pack a bit field of a specified length into the output *  bitstream. ******************************************************************************** */pack_bits( code, length, debug, dfp, fea2kb_rec, oh, ofp, stuff_inhib, stf )FILE *dfp, *ofp;int code, debug, length, *stf, stuff_inhib;struct fea2kb *fea2kb_rec;struct header *oh;{    int	i,			/* Loop variable */	temp;			/* Temporary variable */    unsigned long	bit,			/* On/off bit indicator */	c,			/* Unsigned copy of code word */	mask;			/* Mask for 1's stuffing */    static int	bit_ptr =	    8*sizeof(long),	/* Pointer to first available bit (1-relative) */	init = YES,		/* Flag for initial entry */	ones_cnt,		/* Consecutive one's counter */	state,			/* State of bitsream (1 or 0) */	sync_ones;		/* Number of ones in sync code */    static unsigned long	buf;			/* Bitstream buffer */    if ( init )    {	init = NO;	if ( stuff_inhib )	    sync_ones = length - 2;    }    if ( debug >= 3 )	Fprintf( dfp, "\t\tCode = 0x%x; Length = %d\n", code, length );    if ( length == 0 )    {	flush_buffer( &buf, &bit_ptr, debug, dfp, fea2kb_rec, oh, ofp );	return;    }    c = code;    if ( !stuff_inhib )    {	i = 1;	mask = 1;	while ( i < length )	{	    mask <<= 1;	    i++;	}	while ( mask )	{	    bit = c & mask;	    if ( state == 0 )	    {	        if ( bit )		{		    state = 1;		    ones_cnt = 1;		}	    }	    else	    {		if ( bit )		{		    ones_cnt++;		    if ( ones_cnt == sync_ones )		    {		        stuff_1( mask, &c );			(*stf)++;			ones_cnt++;			length++;			if ( debug >= 3 )			{			    Fprintf( dfp, "\t\t>>Stuffed bit @ 0x%lx:", mask );			    Fprintf( dfp, " Code => 0x%lx; Length => %d\n", c, length );			}		    }		}		else		    state = 0;	    }	    mask >>= 1;	}    }    else	state = 0;    if ( length <= bit_ptr )    {	buf |= c << bit_ptr - length;	bit_ptr -= length;	if ( bit_ptr == 0 )	    flush_buffer( &buf, &bit_ptr, debug, dfp, fea2kb_rec, oh, ofp );    }    else    {	temp = length - bit_ptr;	buf |= c >> length - bit_ptr;	bit_ptr = 0;	flush_buffer( &buf, &bit_ptr, debug, dfp, fea2kb_rec, oh, ofp );	buf |= c << bit_ptr - temp;	bit_ptr -= temp;    }}/* ******************************************************************************** *  Subroutine to stuff a 1 into the code word prior to packing it in the *  bitstream buffer. ******************************************************************************** */stuff_1( mask, c )unsigned long *c, mask;{    unsigned long	high,			/* MS bits (preceding stuff) of code */	low,			/* LS bits (following stuff) of code */	low_mask = 0,		/* Mask for LS bits */	z;			/* Scratch variable */    z = mask >> 1;    while ( z )    {	low_mask |= z;	z >>= 1;    }    low = *c & low_mask;    high = *c & ~low_mask;    *c = high << 1 | mask | low;}/* ******************************************************************************** *  Subroutine to flush the bitstream buffer to output file. ******************************************************************************** */flush_buffer( buf, bit_ptr, debug, dfp, fea2kb_rec, oh, ofp )FILE *dfp, *ofp;int *bit_ptr, debug;struct fea2kb *fea2kb_rec;struct header *oh;unsigned long *buf;{    static int tot;		/* Total bits output to bitstream */    *fea2kb_rec->bitstream = (long) *buf;    *fea2kb_rec->error_mask = 0;    put_fea2kb_rec( fea2kb_rec, oh, ofp );    tot += 8*sizeof(long) - *bit_ptr;    if ( debug >= 4 )	Fprintf( dfp, "\t\t\tBuffer output = 0x%x; Cumulative total = %d\n", *buf, tot );    *buf = 0;    *bit_ptr = 8*sizeof(long);}

⌨️ 快捷键说明

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