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

📄 ulaw.c

📁 Vovida 社区开源的 SIP 协议源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*** Copyright (C) 1999-2001 Erik de Castro Lopo <erikd@zip.com.au>**  ** This program is free software; you can redistribute it and/or modify** it under the terms of the GNU Lesser General Public License as published by** the Free Software Foundation; either version 2.1 of the License, or** (at your option) any later version.** ** This program is distributed in the hope that it will be useful,** but WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the** GNU Lesser General Public License for more details.** ** You should have received a copy of the GNU Lesser General Public License** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/#include	<unistd.h>#include	"sndfile.h"#include	"common.h"static int		ulaw_read_ulaw2s (SF_PRIVATE *psf, short *ptr, unsigned int len) ;static int		ulaw_read_ulaw2i (SF_PRIVATE *psf, int *ptr, unsigned int len) ;static int		ulaw_read_ulaw2f (SF_PRIVATE *psf, float *ptr, unsigned int len) ;static int		ulaw_read_ulaw2d (SF_PRIVATE *psf, double *ptr, unsigned int len, int normalize) ;static int		ulaw_write_s2ulaw (SF_PRIVATE *psf, short *ptr, unsigned int len) ;static int		ulaw_write_i2ulaw (SF_PRIVATE *psf, int *ptr, unsigned int len) ;static int		ulaw_write_f2ulaw (SF_PRIVATE *psf, float *ptr, unsigned int len) ;static int		ulaw_write_d2ulaw (SF_PRIVATE *psf, double *ptr, unsigned int len, int normalize) ;static  void    ulaw2s_array      (unsigned char *buffer, unsigned int count, short *ptr, unsigned int index) ;static  void    ulaw2i_array      (unsigned char *buffer, unsigned int count, int *ptr, unsigned int index) ;static  void    ulaw2f_array      (unsigned char *buffer, unsigned int count, float *ptr, unsigned int index, float normfact) ;static  void    ulaw2d_array      (unsigned char *buffer, unsigned int count, double *ptr, unsigned int index, double normfact) ;static  void    s2ulaw_array      (short *buffer, unsigned int count, unsigned char *ptr, unsigned int index) ;static  void    i2ulaw_array      (int *buffer, unsigned int count, unsigned char *ptr, unsigned int index) ;static  void    f2ulaw_array      (float *buffer, unsigned int count, unsigned char *ptr, unsigned int index, float normfact) ;static  void    d2ulaw_array      (double *buffer, unsigned int count, unsigned char *ptr, unsigned int index, double normfact) ;int ulaw_read_init (SF_PRIVATE *psf){	psf->read_short  = (func_short)  ulaw_read_ulaw2s ;	psf->read_int    = (func_int)    ulaw_read_ulaw2i ;	psf->read_float  = (func_float)  ulaw_read_ulaw2f ;	psf->read_double = (func_double) ulaw_read_ulaw2d ;	return 0 ;} /* ulaw_read_int */int ulaw_write_init (SF_PRIVATE *psf){	psf->write_short  = (func_short)  ulaw_write_s2ulaw ;	psf->write_int    = (func_int)    ulaw_write_i2ulaw ;	psf->write_float  = (func_float)  ulaw_write_f2ulaw ;	psf->write_double = (func_double) ulaw_write_d2ulaw ;	return 0 ;} /* ulaw_write_int */static intulaw_read_ulaw2s (SF_PRIVATE *psf, short *ptr, unsigned int len){	unsigned int readcount, thisread, index = 0 ;	int		bytecount, bufferlen ;	int		total = 0 ;	bufferlen = (SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth ;	bytecount = len * psf->bytewidth ;	while (bytecount > 0)	{	readcount = (bytecount >= bufferlen) ? bufferlen : bytecount ;		thisread = fread (psf->buffer, 1, readcount, psf->file) ;		ulaw2s_array ((unsigned char*) (psf->buffer), thisread / psf->bytewidth, ptr, index) ;		total += thisread ;		if (thisread < readcount)			break ;		index += thisread / psf->bytewidth ;		bytecount -= thisread ;		} ;	total /= psf->bytewidth ;	if (total < len)		psf->error = SFE_SHORT_READ ;		return total ;} /* ulaw_read_ulaw2s */static intulaw_read_ulaw2i (SF_PRIVATE *psf, int *ptr, unsigned int len){	unsigned int readcount, thisread, index = 0 ;	int		bytecount, bufferlen ;	int		total = 0 ;	bufferlen = (SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth ;	bytecount = len * psf->bytewidth ;	while (bytecount > 0)	{	readcount = (bytecount >= bufferlen) ? bufferlen : bytecount ;		thisread = fread (psf->buffer, 1, readcount, psf->file) ;		ulaw2i_array ((unsigned char*) (psf->buffer), thisread / psf->bytewidth, ptr, index) ;		total += thisread ;		if (thisread < readcount)			break ;		index += thisread / psf->bytewidth ;		bytecount -= thisread ;		} ;	total /= psf->bytewidth ;	if (total < len)		psf->error = SFE_SHORT_READ ;		return total ;} /* ulaw_read_ulaw2i */static intulaw_read_ulaw2f (SF_PRIVATE *psf, float *ptr, unsigned int len){	unsigned int readcount, thisread, index = 0 ;	int		bytecount, bufferlen ;	int		total = 0 ;	bufferlen = (SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth ;	bytecount = len * psf->bytewidth ;	while (bytecount > 0)	{	readcount = (bytecount >= bufferlen) ? bufferlen : bytecount ;		thisread = fread (psf->buffer, 1, readcount, psf->file) ;		ulaw2f_array ((unsigned char*) (psf->buffer), thisread / psf->bytewidth, ptr, index, 1.0) ;		total += thisread ;		if (thisread < readcount)			break ;		index += thisread / psf->bytewidth ;		bytecount -= thisread ;		} ;	total /= psf->bytewidth ;	if (total < len)		psf->error = SFE_SHORT_READ ;		return total ;} /* ulaw_read_ulaw2f */static intulaw_read_ulaw2d (SF_PRIVATE *psf, double *ptr, unsigned int len, int normalize){	unsigned int readcount, thisread, index = 0 ;	int		bytecount, bufferlen ;	int		total = 0 ;	double	normfact ;		normfact = (normalize ? 1.0 / ((double) 0x8000) : 1.0) ;	bufferlen = (SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth ;	bytecount = len * psf->bytewidth ;	while (bytecount > 0)	{	readcount = (bytecount >= bufferlen) ? bufferlen : bytecount ;		thisread = fread (psf->buffer, 1, readcount, psf->file) ;		ulaw2d_array ((unsigned char*) (psf->buffer), thisread / psf->bytewidth, ptr, index, normfact) ;		total += thisread ;		if (thisread < readcount)			break ;		index += thisread / psf->bytewidth ;		bytecount -= thisread ;		} ;	total /= psf->bytewidth ;	if (total < len)		psf->error = SFE_SHORT_READ ;		return total ;} /* ulaw_read_ulaw2d *//*=============================================================================================*/static intulaw_write_s2ulaw	(SF_PRIVATE *psf, short *ptr, unsigned int len){	unsigned int	writecount, thiswrite, index = 0 ;	int		bytecount, bufferlen ;	int		total = 0 ;	bufferlen = (SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth ;	bytecount = len * psf->bytewidth ;	while (bytecount > 0)	{	writecount = (bytecount >= bufferlen) ? bufferlen : bytecount ;		s2ulaw_array (ptr, index, (unsigned char*) (psf->buffer), writecount / psf->bytewidth) ;		thiswrite = fwrite (psf->buffer, 1, writecount, psf->file) ;		total += thiswrite ;		if (thiswrite < writecount)			break ;		index += thiswrite / psf->bytewidth ;		bytecount -= thiswrite ;		} ;	total /= psf->bytewidth ;	if (total < len)		psf->error = SFE_SHORT_READ ;		return total ;} /* ulaw_write_s2ulaw */static intulaw_write_i2ulaw	(SF_PRIVATE *psf, int *ptr, unsigned int len){	unsigned int	writecount, thiswrite, index = 0 ;	int		bytecount, bufferlen ;	int		total = 0 ;	bufferlen = (SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth ;	bytecount = len * psf->bytewidth ;	while (bytecount > 0)	{	writecount = (bytecount >= bufferlen) ? bufferlen : bytecount ;		i2ulaw_array (ptr, index, (unsigned char*) (psf->buffer), writecount / psf->bytewidth) ;		thiswrite = fwrite (psf->buffer, 1, writecount, psf->file) ;		total += thiswrite ;		if (thiswrite < writecount)			break ;		index += thiswrite / psf->bytewidth ;		bytecount -= thiswrite ;

⌨️ 快捷键说明

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