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

📄 gsm610.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 2 页
字号:
	{	readcount = (len >= bufferlen) ? bufferlen : len ;		count = gsm610_read_block (psf, pgsm610, sptr, readcount) ;		for (k = 0 ; k < readcount ; k++)			ptr [total + k] = normfact * sptr [k] ;		total += count ;		len -= readcount ;		} ;	return total ;} /* gsm610_read_f */static sf_count_tgsm610_read_d	(SF_PRIVATE *psf, double *ptr, sf_count_t len){	GSM610_PRIVATE *pgsm610 ;	short		*sptr ;	int			k, bufferlen, readcount = 0, count ;	sf_count_t	total = 0 ;	double		normfact ;	normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x8000) : 1.0 ;	if (! psf->fdata)		return 0 ;	pgsm610 = (GSM610_PRIVATE*) psf->fdata ;	sptr = psf->u.sbuf ;	bufferlen = ARRAY_LEN (psf->u.sbuf) ;	while (len > 0)	{	readcount = (len >= bufferlen) ? bufferlen : len ;		count = gsm610_read_block (psf, pgsm610, sptr, readcount) ;		for (k = 0 ; k < readcount ; k++)			ptr [total + k] = normfact * sptr [k] ;		total += count ;		len -= readcount ;		} ;	return total ;} /* gsm610_read_d */static sf_count_tgsm610_seek	(SF_PRIVATE *psf, int mode, sf_count_t offset){	GSM610_PRIVATE *pgsm610 ;	int			newblock, newsample ;	mode = mode ;	if (! psf->fdata)		return 0 ;	pgsm610 = (GSM610_PRIVATE*) psf->fdata ;	if (psf->dataoffset < 0)	{	psf->error = SFE_BAD_SEEK ;		return	((sf_count_t) -1) ;		} ;	if (offset == 0)	{	int true_flag = 1 ;		psf_fseek (psf, psf->dataoffset, SEEK_SET) ;		pgsm610->blockcount = 0 ;		gsm_init (pgsm610->gsm_data) ;		if ((psf->sf.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV ||				(psf->sf.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_W64)			gsm_option (pgsm610->gsm_data, GSM_OPT_WAV49, &true_flag) ;		pgsm610->decode_block (psf, pgsm610) ;		pgsm610->samplecount = 0 ;		return 0 ;		} ;	if (offset < 0 || offset > pgsm610->blocks * pgsm610->samplesperblock)	{	psf->error = SFE_BAD_SEEK ;		return	((sf_count_t) -1) ;		} ;	newblock	= offset / pgsm610->samplesperblock ;	newsample	= offset % pgsm610->samplesperblock ;	if (psf->mode == SFM_READ)	{	if (psf->read_current != newblock * pgsm610->samplesperblock + newsample)		{	psf_fseek (psf, psf->dataoffset + newblock * pgsm610->samplesperblock, SEEK_SET) ;			pgsm610->blockcount = newblock ;			pgsm610->decode_block (psf, pgsm610) ;			pgsm610->samplecount = newsample ;			} ;		return newblock * pgsm610->samplesperblock + newsample ;		} ;	/* What to do about write??? */	psf->error = SFE_BAD_SEEK ;	return	((sf_count_t) -1) ;} /* gsm610_seek *//*==========================================================================================** GSM 6.10 Write Functions.*/static intgsm610_encode_block	(SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610){	int k ;	/* Encode the samples. */	gsm_encode (pgsm610->gsm_data, pgsm610->samples, pgsm610->block) ;	/* Write the block to disk. */	if ((k = psf_fwrite (pgsm610->block, 1, GSM610_BLOCKSIZE, psf)) != GSM610_BLOCKSIZE)		psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, GSM610_BLOCKSIZE) ;	pgsm610->samplecount = 0 ;	pgsm610->blockcount ++ ;	/* Set samples to zero for next block. */	memset (pgsm610->samples, 0, WAV_W64_GSM610_SAMPLES * sizeof (short)) ;	return 1 ;} /* gsm610_encode_block */static intgsm610_wav_encode_block	(SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610){	int k ;	/* Encode the samples. */	gsm_encode (pgsm610->gsm_data, pgsm610->samples, pgsm610->block) ;	gsm_encode (pgsm610->gsm_data, pgsm610->samples+WAV_W64_GSM610_SAMPLES/2, pgsm610->block+WAV_W64_GSM610_BLOCKSIZE/2) ;	/* Write the block to disk. */	if ((k = psf_fwrite (pgsm610->block, 1, WAV_W64_GSM610_BLOCKSIZE, psf)) != WAV_W64_GSM610_BLOCKSIZE)		psf_log_printf (psf, "*** Warning : short write (%d != %d).\n", k, WAV_W64_GSM610_BLOCKSIZE) ;	pgsm610->samplecount = 0 ;	pgsm610->blockcount ++ ;	/* Set samples to zero for next block. */	memset (pgsm610->samples, 0, WAV_W64_GSM610_SAMPLES * sizeof (short)) ;	return 1 ;} /* gsm610_wav_encode_block */static intgsm610_write_block	(SF_PRIVATE *psf, GSM610_PRIVATE *pgsm610, short *ptr, int len){	int		count, total = 0, indx = 0 ;	while (indx < len)	{	count = pgsm610->samplesperblock - pgsm610->samplecount ;		if (count > len - indx)			count = len - indx ;		memcpy (&(pgsm610->samples [pgsm610->samplecount]), &(ptr [indx]), count * sizeof (short)) ;		indx += count ;		pgsm610->samplecount += count ;		total = indx ;		if (pgsm610->samplecount >= pgsm610->samplesperblock)			pgsm610->encode_block (psf, pgsm610) ;		} ;	return total ;} /* gsm610_write_block */static sf_count_tgsm610_write_s	(SF_PRIVATE *psf, short *ptr, sf_count_t len){	GSM610_PRIVATE 	*pgsm610 ;	int			writecount, count ;	sf_count_t	total = 0 ;	if (! psf->fdata)		return 0 ;	pgsm610 = (GSM610_PRIVATE*) psf->fdata ;	while (len > 0)	{	writecount = (len > 0x10000000) ? 0x10000000 : (int) len ;		count = gsm610_write_block (psf, pgsm610, ptr, writecount) ;		total += count ;		len -= count ;		if (count != writecount)			break ;		} ;	return total ;} /* gsm610_write_s */static sf_count_tgsm610_write_i	(SF_PRIVATE *psf, int *ptr, sf_count_t len){	GSM610_PRIVATE *pgsm610 ;	short		*sptr ;	int			k, bufferlen, writecount = 0, count ;	sf_count_t	total = 0 ;	if (! psf->fdata)		return 0 ;	pgsm610 = (GSM610_PRIVATE*) psf->fdata ;	sptr = psf->u.sbuf ;	bufferlen = ARRAY_LEN (psf->u.sbuf) ;	while (len > 0)	{	writecount = (len >= bufferlen) ? bufferlen : len ;		for (k = 0 ; k < writecount ; k++)			sptr [k] = ptr [total + k] >> 16 ;		count = gsm610_write_block (psf, pgsm610, sptr, writecount) ;		total += count ;		len -= writecount ;		} ;	return total ;} /* gsm610_write_i */static sf_count_tgsm610_write_f	(SF_PRIVATE *psf, float *ptr, sf_count_t len){	GSM610_PRIVATE *pgsm610 ;	short		*sptr ;	int			k, bufferlen, writecount = 0, count ;	sf_count_t	total = 0 ;	float		normfact ;	if (! psf->fdata)		return 0 ;	pgsm610 = (GSM610_PRIVATE*) psf->fdata ;	normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;	sptr = psf->u.sbuf ;	bufferlen = ARRAY_LEN (psf->u.sbuf) ;	while (len > 0)	{	writecount = (len >= bufferlen) ? bufferlen : len ;		for (k = 0 ; k < writecount ; k++)			sptr [k] = lrintf (normfact * ptr [total + k]) ;		count = gsm610_write_block (psf, pgsm610, sptr, writecount) ;		total += count ;		len -= writecount ;		} ;	return total ;} /* gsm610_write_f */static sf_count_tgsm610_write_d	(SF_PRIVATE *psf, double *ptr, sf_count_t len){	GSM610_PRIVATE *pgsm610 ;	short		*sptr ;	int			k, bufferlen, writecount = 0, count ;	sf_count_t	total = 0 ;	double		normfact ;	if (! psf->fdata)		return 0 ;	pgsm610 = (GSM610_PRIVATE*) psf->fdata ;	normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;	sptr = psf->u.sbuf ;	bufferlen = ARRAY_LEN (psf->u.sbuf) ;	while (len > 0)	{	writecount = (len >= bufferlen) ? bufferlen : len ;		for (k = 0 ; k < writecount ; k++)			sptr [k] = lrint (normfact * ptr [total + k]) ;		count = gsm610_write_block (psf, pgsm610, sptr, writecount) ;		total += count ;		len -= writecount ;		} ;	return total ;} /* gsm610_write_d */static intgsm610_close	(SF_PRIVATE *psf){	GSM610_PRIVATE *pgsm610 ;	if (! psf->fdata)		return 0 ;	pgsm610 = (GSM610_PRIVATE*) psf->fdata ;	if (psf->mode == SFM_WRITE)	{	/*	If a block has been partially assembled, write it out		**	as the final block.		*/		if (pgsm610->samplecount && pgsm610->samplecount < pgsm610->samplesperblock)			pgsm610->encode_block (psf, pgsm610) ;		if (psf->write_header)			psf->write_header (psf, SF_TRUE) ;		} ;	if (pgsm610->gsm_data)		gsm_destroy (pgsm610->gsm_data) ;	return 0 ;} /* gsm610_close *//*** Do not edit or modify anything in this comment block.** The arch-tag line is a file identity tag for the GNU Arch ** revision control system.**** arch-tag: 8575187d-af4f-4acf-b9dd-6ff705628345*/

⌨️ 快捷键说明

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