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

📄 bitbuffer.c

📁 tcpmp.src.0.72RC1 优秀的多媒体播放器TCPMP的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
FLAC__bool FLAC__bitbuffer_write_utf8_uint64(FLAC__BitBuffer *bb, FLAC__uint64 val){	FLAC__bool ok = 1;	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */	if(val < 0x80) {		return FLAC__bitbuffer_write_raw_uint32(bb, (FLAC__uint32)val, 8);	}	else if(val < 0x800) {		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0xC0 | (FLAC__uint32)(val>>6), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)(val&0x3F), 8);	}	else if(val < 0x10000) {		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0xE0 | (FLAC__uint32)(val>>12), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)(val&0x3F), 8);	}	else if(val < 0x200000) {		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0xF0 | (FLAC__uint32)(val>>18), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)(val&0x3F), 8);	}	else if(val < 0x4000000) {		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0xF8 | (FLAC__uint32)(val>>24), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)(val&0x3F), 8);	}	else if(val < 0x80000000) {		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0xFC | (FLAC__uint32)(val>>30), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)(val&0x3F), 8);	}	else {		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0xFE, 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);		ok &= FLAC__bitbuffer_write_raw_uint32(bb, 0x80 | (FLAC__uint32)(val&0x3F), 8);	}	return ok;}FLAC__bool FLAC__bitbuffer_zero_pad_to_byte_boundary(FLAC__BitBuffer *bb){	/* 0-pad to byte boundary */	if(bb->bits & 7u)		return FLAC__bitbuffer_write_zeroes(bb, 8 - (bb->bits & 7u));	else		return true;}FLAC__bool FLAC__bitbuffer_peek_bit(FLAC__BitBuffer *bb, unsigned *val, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data){	/* to avoid a drastic speed penalty we don't:	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bb->bits == 0);	*/	while(1) {		if(bb->total_consumed_bits < bb->total_bits) {			*val = (bb->buffer[bb->consumed_blurbs] & BLURB_BIT_TO_MASK(bb->consumed_bits))? 1 : 0;			return true;		}		else {			if(!bitbuffer_read_from_client_(bb, read_callback, client_data))				return false;		}	}}FLAC__bool FLAC__bitbuffer_read_bit(FLAC__BitBuffer *bb, unsigned *val, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data){	/* to avoid a drastic speed penalty we don't:	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bb->bits == 0);	*/	while(1) {		if(bb->total_consumed_bits < bb->total_bits) {			*val = (bb->buffer[bb->consumed_blurbs] & BLURB_BIT_TO_MASK(bb->consumed_bits))? 1 : 0;			bb->consumed_bits++;			if(bb->consumed_bits == FLAC__BITS_PER_BLURB) {				CRC16_UPDATE_BLURB(bb, bb->buffer[bb->consumed_blurbs], bb->read_crc16);				bb->consumed_blurbs++;				bb->consumed_bits = 0;			}			bb->total_consumed_bits++;			return true;		}		else {			if(!bitbuffer_read_from_client_(bb, read_callback, client_data))				return false;		}	}}FLAC__bool FLAC__bitbuffer_read_bit_to_uint32(FLAC__BitBuffer *bb, FLAC__uint32 *val, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data){	/* to avoid a drastic speed penalty we don't:	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bb->bits == 0);	*/	while(1) {		if(bb->total_consumed_bits < bb->total_bits) {			*val <<= 1;			*val |= (bb->buffer[bb->consumed_blurbs] & BLURB_BIT_TO_MASK(bb->consumed_bits))? 1 : 0;			bb->consumed_bits++;			if(bb->consumed_bits == FLAC__BITS_PER_BLURB) {				CRC16_UPDATE_BLURB(bb, bb->buffer[bb->consumed_blurbs], bb->read_crc16);				bb->consumed_blurbs++;				bb->consumed_bits = 0;			}			bb->total_consumed_bits++;			return true;		}		else {			if(!bitbuffer_read_from_client_(bb, read_callback, client_data))				return false;		}	}}FLAC__bool FLAC__bitbuffer_read_bit_to_uint64(FLAC__BitBuffer *bb, FLAC__uint64 *val, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data){	/* to avoid a drastic speed penalty we don't:	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bb->bits == 0);	*/	while(1) {		if(bb->total_consumed_bits < bb->total_bits) {			*val <<= 1;			*val |= (bb->buffer[bb->consumed_blurbs] & BLURB_BIT_TO_MASK(bb->consumed_bits))? 1 : 0;			bb->consumed_bits++;			if(bb->consumed_bits == FLAC__BITS_PER_BLURB) {				CRC16_UPDATE_BLURB(bb, bb->buffer[bb->consumed_blurbs], bb->read_crc16);				bb->consumed_blurbs++;				bb->consumed_bits = 0;			}			bb->total_consumed_bits++;			return true;		}		else {			if(!bitbuffer_read_from_client_(bb, read_callback, client_data))				return false;		}	}}FLaC__INLINE FLAC__bool FLAC__bitbuffer_read_raw_uint32(FLAC__BitBuffer *bb, FLAC__uint32 *val, const unsigned bits, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data)#ifdef FLAC__NO_MANUAL_INLINING{	unsigned i;	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bits <= 32);	*val = 0;	for(i = 0; i < bits; i++) {		if(!FLAC__bitbuffer_read_bit_to_uint32(bb, val, read_callback, client_data))			return false;	}	return true;}#else{	unsigned i, bits_ = bits;	FLAC__uint32 v = 0;	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bits <= 32);	FLAC__ASSERT((bb->capacity*FLAC__BITS_PER_BLURB) * 2 >= bits);	if(bits == 0) {		*val = 0;		return true;	}	while(bb->total_consumed_bits + bits > bb->total_bits) {		if(!bitbuffer_read_from_client_(bb, read_callback, client_data))			return false;	}#if FLAC__BITS_PER_BLURB > 8	if(bb->bits == 0 || bb->consumed_blurbs < bb->blurbs) { /*@@@ comment on why this is here*/#endif		if(bb->consumed_bits) {			i = FLAC__BITS_PER_BLURB - bb->consumed_bits;			if(i <= bits_) {				v = bb->buffer[bb->consumed_blurbs] & (FLAC__BLURB_ALL_ONES >> bb->consumed_bits);				bits_ -= i;				CRC16_UPDATE_BLURB(bb, bb->buffer[bb->consumed_blurbs], bb->read_crc16);				bb->consumed_blurbs++;				bb->consumed_bits = 0;				/* we hold off updating bb->total_consumed_bits until the end */			}			else {				*val = (bb->buffer[bb->consumed_blurbs] & (FLAC__BLURB_ALL_ONES >> bb->consumed_bits)) >> (i-bits_);				bb->consumed_bits += bits_;				bb->total_consumed_bits += bits_;				return true;			}		}#if FLAC__BITS_PER_BLURB == 32		/* note that we know bits_ cannot be > 32 because of previous assertions */		if(bits_ == FLAC__BITS_PER_BLURB) {			v = bb->buffer[bb->consumed_blurbs];			CRC16_UPDATE_BLURB(bb, v, bb->read_crc16);			bb->consumed_blurbs++;			/* bb->consumed_bits is already 0 */			bb->total_consumed_bits += bits;			*val = v;			return true;		}#else		while(bits_ >= FLAC__BITS_PER_BLURB) {			v <<= FLAC__BITS_PER_BLURB;			v |= bb->buffer[bb->consumed_blurbs];			bits_ -= FLAC__BITS_PER_BLURB;			CRC16_UPDATE_BLURB(bb, bb->buffer[bb->consumed_blurbs], bb->read_crc16);			bb->consumed_blurbs++;			/* bb->consumed_bits is already 0 */			/* we hold off updating bb->total_consumed_bits until the end */		}#endif		if(bits_ > 0) {			v <<= bits_;			v |= (bb->buffer[bb->consumed_blurbs] >> (FLAC__BITS_PER_BLURB-bits_));			bb->consumed_bits = bits_;			/* we hold off updating bb->total_consumed_bits until the end */		}		bb->total_consumed_bits += bits;		*val = v;#if FLAC__BITS_PER_BLURB > 8	}	else {		*val = 0;		for(i = 0; i < bits; i++) {			if(!FLAC__bitbuffer_read_bit_to_uint32(bb, val, read_callback, client_data))				return false;		}	}#endif	return true;}#endifFLAC__bool FLAC__bitbuffer_read_raw_int32(FLAC__BitBuffer *bb, FLAC__int32 *val, const unsigned bits, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data)#ifdef FLAC__NO_MANUAL_INLINING{	unsigned i;	FLAC__uint32 v;	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bits <= 32);	if(bits == 0) {		*val = 0;		return true;	}	v = 0;	for(i = 0; i < bits; i++) {		if(!FLAC__bitbuffer_read_bit_to_uint32(bb, &v, read_callback, client_data))			return false;	}	/* fix the sign */	i = 32 - bits;	if(i) {		v <<= i;		*val = (FLAC__int32)v;		*val >>= i;	}	else		*val = (FLAC__int32)v;	return true;}#else{	unsigned i, bits_ = bits;	FLAC__uint32 v = 0;	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bits <= 32);	FLAC__ASSERT((bb->capacity*FLAC__BITS_PER_BLURB) * 2 >= bits);	if(bits == 0) {		*val = 0;		return true;	}	while(bb->total_consumed_bits + bits > bb->total_bits) {		if(!bitbuffer_read_from_client_(bb, read_callback, client_data))			return false;	}#if FLAC__BITS_PER_BLURB > 8	if(bb->bits == 0 || bb->consumed_blurbs < bb->blurbs) { /*@@@ comment on why this is here*/#endif		if(bb->consumed_bits) {			i = FLAC__BITS_PER_BLURB - bb->consumed_bits;			if(i <= bits_) {				v = bb->buffer[bb->consumed_blurbs] & (FLAC__BLURB_ALL_ONES >> bb->consumed_bits);				bits_ -= i;				CRC16_UPDATE_BLURB(bb, bb->buffer[bb->consumed_blurbs], bb->read_crc16);				bb->consumed_blurbs++;				bb->consumed_bits = 0;				/* we hold off updating bb->total_consumed_bits until the end */			}			else {				/* bits_ must be < FLAC__BITS_PER_BLURB-1 if we get to here */				v = (bb->buffer[bb->consumed_blurbs] & (FLAC__BLURB_ALL_ONES >> bb->consumed_bits));				v <<= (32-i);				*val = (FLAC__int32)v;				*val >>= (32-bits_);				bb->consumed_bits += bits_;				bb->total_consumed_bits += bits_;				return true;			}		}#if FLAC__BITS_PER_BLURB == 32		/* note that we know bits_ cannot be > 32 because of previous assertions */		if(bits_ == FLAC__BITS_PER_BLURB) {			v = bb->buffer[bb->consumed_blurbs];			bits_ = 0;			CRC16_UPDATE_BLURB(bb, v, bb->read_crc16);			bb->consumed_blurbs++;			/* bb->consumed_bits is already 0 */			/* we hold off updating bb->total_consumed_bits until the end */		}#else		while(bits_ >= FLAC__BITS_PER_BLURB) {			v <<= FLAC__BITS_PER_BLURB;			v |= bb->buffer[bb->consumed_blurbs];			bits_ -= FLAC__BITS_PER_BLURB;			CRC16_UPDATE_BLURB(bb, bb->buffer[bb->consumed_blurbs], bb->read_crc16);			bb->consumed_blurbs++;			/* bb->consumed_bits is already 0 */			/* we hold off updating bb->total_consumed_bits until the end */		}#endif		if(bits_ > 0) {			v <<= bits_;			v |= (bb->buffer[bb->consumed_blurbs] >> (FLAC__BITS_PER_BLURB-bits_));			bb->consumed_bits = bits_;			/* we hold off updating bb->total_consumed_bits until the end */		}		bb->total_consumed_bits += bits;#if FLAC__BITS_PER_BLURB > 8	}	else {		for(i = 0; i < bits; i++) {			if(!FLAC__bitbuffer_read_bit_to_uint32(bb, &v, read_callback, client_data))				return false;		}	}#endif	/* fix the sign */	i = 32 - bits;	if(i) {		v <<= i;		*val = (FLAC__int32)v;		*val >>= i;	}	else		*val = (FLAC__int32)v;	return true;}#endifFLAC__bool FLAC__bitbuffer_read_raw_uint64(FLAC__BitBuffer *bb, FLAC__uint64 *val, const unsigned bits, FLAC__bool (*read_callback)(FLAC__byte buffer[], unsigned *bytes, void *client_data), void *client_data)#ifdef FLAC__NO_MANUAL_INLINING{	unsigned i;	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bits <= 64);	*val = 0;	for(i = 0; i < bits; i++) {		if(!FLAC__bitbuffer_read_bit_to_uint64(bb, val, read_callback, client_data))			return false;	}	return true;}#else{	unsigned i, bits_ = bits;	FLAC__uint64 v = 0;	FLAC__ASSERT(0 != bb);	FLAC__ASSERT(0 != bb->buffer);	FLAC__ASSERT(bits <= 64);	FLAC__ASSERT((bb->capacity*FLAC__BITS_PER_BLURB) * 2 >= bits);	if(bits == 0) {		*val = 0;		return true;	}

⌨️ 快捷键说明

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