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

📄 alaw.c

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 C
📖 第 1 页 / 共 2 页
字号:
/*** Copyright (C) 1999-2000 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  void    alaw2s_array      (unsigned char *buffer, unsigned int count, short *ptr, unsigned int index) ;static  void    alaw2i_array      (unsigned char *buffer, unsigned int count, int *ptr, unsigned int index) ;static  void    alaw2d_array      (unsigned char *buffer, unsigned int count, double *ptr, unsigned int index, double normfact) ;static  void    s2alaw_array      (short *buffer, unsigned int count, unsigned char *ptr, unsigned int index) ;static  void    i2alaw_array      (int *buffer, unsigned int count, unsigned char *ptr, unsigned int index) ;static  void    d2alaw_array      (double *buffer, unsigned int count, unsigned char *ptr, unsigned int index, double normfact) ;int		alaw_read_alaw2s (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) ;		alaw2s_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 ;} /* alaw_read_alaw2s */int		alaw_read_alaw2i (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) ;		alaw2i_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 ;} /* alaw_read_alaw2i */int		alaw_read_alaw2d (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) ;		alaw2d_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 ;} /* alaw_read_alaw2d *//*=============================================================================================*/int	alaw_write_s2alaw	(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 ;		s2alaw_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 ;} /* alaw_write_s2alaw */int	alaw_write_i2alaw	(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 ;		i2alaw_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 ;} /* alaw_write_i2alaw */int	alaw_write_d2alaw	(SF_PRIVATE *psf, double *ptr, unsigned int len, int normalize){	unsigned int	writecount, thiswrite, index = 0 ;	int		bytecount, bufferlen ;	int		total = 0 ;	double	normfact ;		normfact = (normalize ? ((double) 0x8000) : 1.0) ;	bufferlen = (SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth ;	bytecount = len * psf->bytewidth ;	while (bytecount > 0)	{	writecount = (bytecount >= bufferlen) ? bufferlen : bytecount ;		d2alaw_array (ptr, index, (unsigned char*) (psf->buffer), writecount / psf->bytewidth, normfact) ;		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 ;} /* alaw_write_d2alaw *//*============================================================================================= *	Private static functions and data. */static	short	alaw_decode [128] ={	 -5504,  -5248,  -6016,  -5760,  -4480,  -4224,  -4992,  -4736, 	 -7552,  -7296,  -8064,  -7808,  -6528,  -6272,  -7040,  -6784, 	 -2752,  -2624,  -3008,  -2880,  -2240,  -2112,  -2496,  -2368, 	 -3776,  -3648,  -4032,  -3904,  -3264,  -3136,  -3520,  -3392, 	-22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944, 	-30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136, 	-11008, -10496, -12032, -11520,  -8960,  -8448,  -9984,  -9472, 	-15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568, 	  -344,   -328,   -376,   -360,   -280,   -264,   -312,   -296, 	  -472,   -456,   -504,   -488,   -408,   -392,   -440,   -424, 	   -88,    -72,   -120,   -104,    -24,     -8,    -56,    -40, 	  -216,   -200,   -248,   -232,   -152,   -136,   -184,   -168, 	 -1376,  -1312,  -1504,  -1440,  -1120,  -1056,  -1248,  -1184, 	 -1888,  -1824,  -2016,  -1952,  -1632,  -1568,  -1760,  -1696, 	  -688,   -656,   -752,   -720,   -560,   -528,   -624,   -592, 	  -944,   -912,  -1008,   -976,   -816,   -784,   -880,   -848} ; /* alaw_decode */static	unsigned char	alaw_encode [2049] ={	0xD5, 0xD4, 0xD7, 0xD6, 0xD1, 0xD0, 0xD3, 0xD2, 0xDD, 0xDC, 0xDF, 0xDE, 	0xD9, 0xD8, 0xDB, 0xDA, 0xC5, 0xC4, 0xC7, 0xC6, 0xC1, 0xC0, 0xC3, 0xC2, 	0xCD, 0xCC, 0xCF, 0xCE, 0xC9, 0xC8, 0xCB, 0xCA, 0xF5, 0xF5, 0xF4, 0xF4, 	0xF7, 0xF7, 0xF6, 0xF6, 0xF1, 0xF1, 0xF0, 0xF0, 0xF3, 0xF3, 0xF2, 0xF2, 	0xFD, 0xFD, 0xFC, 0xFC, 0xFF, 0xFF, 0xFE, 0xFE, 0xF9, 0xF9, 0xF8, 0xF8, 	0xFB, 0xFB, 0xFA, 0xFA, 0xE5, 0xE5, 0xE5, 0xE5, 0xE4, 0xE4, 0xE4, 0xE4, 	0xE7, 0xE7, 0xE7, 0xE7, 0xE6, 0xE6, 0xE6, 0xE6, 0xE1, 0xE1, 0xE1, 0xE1, 	0xE0, 0xE0, 0xE0, 0xE0, 0xE3, 0xE3, 0xE3, 0xE3, 0xE2, 0xE2, 0xE2, 0xE2, 	0xED, 0xED, 0xED, 0xED, 0xEC, 0xEC, 0xEC, 0xEC, 0xEF, 0xEF, 0xEF, 0xEF, 	0xEE, 0xEE, 0xEE, 0xEE, 0xE9, 0xE9, 0xE9, 0xE9, 0xE8, 0xE8, 0xE8, 0xE8, 	0xEB, 0xEB, 0xEB, 0xEB, 0xEA, 0xEA, 0xEA, 0xEA, 0x95, 0x95, 0x95, 0x95, 	0x95, 0x95, 0x95, 0x95, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 0x94, 	0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0x97, 0x96, 0x96, 0x96, 0x96, 	0x96, 0x96, 0x96, 0x96, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 0x91, 	0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x93, 0x93, 0x93, 0x93, 

⌨️ 快捷键说明

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