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

📄 au.c

📁 Vovida 社区开源的 SIP 协议源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*** 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	<stdio.h>#include	<unistd.h>#include	<fcntl.h>#include	<string.h>#include	<ctype.h>#include	"sndfile.h"#include	"config.h"#include	"sfendian.h"#include	"common.h"#include	"au.h"/*------------------------------------------------------------------------------** Macros to handle big/little endian issues.*/#define DOTSND_MARKER	(MAKE_MARKER ('.', 's', 'n', 'd')) #define DNSDOT_MARKER	(MAKE_MARKER ('d', 'n', 's', '.')) #define AU_DATA_OFFSET	24/*------------------------------------------------------------------------------** Known AU file encoding types.*/enum{	AU_ENCODING_ULAW_8					= 1,	/* 8-bit u-law samples */	AU_ENCODING_PCM_8					= 2,	/* 8-bit linear samples */	AU_ENCODING_PCM_16					= 3,	/* 16-bit linear samples */	AU_ENCODING_PCM_24					= 4,	/* 24-bit linear samples */	AU_ENCODING_PCM_32					= 5,	/* 32-bit linear samples */		AU_ENCODING_FLOAT					= 6,	/* floating-point samples */	AU_ENCODING_DOUBLE					= 7,	/* double-precision float samples */	AU_ENCODING_INDIRECT				= 8,	/* fragmented sampled data */	AU_ENCODING_NESTED					= 9,	/* ? */	AU_ENCODING_DSP_CORE				= 10,	/* DSP program */	AU_ENCODING_DSP_DATA_8				= 11,	/* 8-bit fixed-point samples */	AU_ENCODING_DSP_DATA_16				= 12,	/* 16-bit fixed-point samples */	AU_ENCODING_DSP_DATA_24				= 13,	/* 24-bit fixed-point samples */	AU_ENCODING_DSP_DATA_32				= 14,	/* 32-bit fixed-point samples */	AU_ENCODING_DISPLAY					= 16,	/* non-audio display data */	AU_ENCODING_MULAW_SQUELCH			= 17,	/* ? */	AU_ENCODING_EMPHASIZED				= 18,	/* 16-bit linear with emphasis */	AU_ENCODING_NEXT					= 19,	/* 16-bit linear with compression (NEXT) */	AU_ENCODING_COMPRESSED_EMPHASIZED	= 20,	/* A combination of the two above */	AU_ENCODING_DSP_COMMANDS			= 21,	/* Music Kit DSP commands */	AU_ENCODING_DSP_COMMANDS_SAMPLES	= 22,	/* ? */	AU_ENCODING_ADPCM_G721_32			= 23,	/* G721 32 kbs ADPCM - 4 bits per sample. */	AU_ENCODING_ADPCM_G722				= 24,	AU_ENCODING_ADPCM_G723_24			= 25,	/* G723 24 kbs ADPCM - 3 bits per sample. */	AU_ENCODING_ADPCM_G723_5			= 26,		AU_ENCODING_ALAW_8					= 27} ;/*------------------------------------------------------------------------------** Typedefs.*/ typedef	struct{	int		dataoffset ;	int		datasize ;	int		encoding ;    int		samplerate ;    int		channels ;} AU_FMT ;/*------------------------------------------------------------------------------** Private static functions.*/static	int				au_close		(SF_PRIVATE *psf) ;static	int 			get_encoding	(unsigned int format, unsigned int	bitwidth) ;static	char const* 	get_encoding_str(int format) ;static int				au_write_header (SF_PRIVATE *psf) ;/*static	void			endswap_au_fmt	(AU_FMT *pau_fmt) ;*//*------------------------------------------------------------------------------** Public functions.*/intau_open_read	(SF_PRIVATE *psf){	AU_FMT			au_fmt ;	unsigned int	marker, dword ;	int				error = SFE_NO_ERROR ;		psf_binheader_readf (psf, "pm", 0, &marker) ;	psf_log_printf (psf, "%D\n", marker) ;	if (marker == DOTSND_MARKER)	{	psf->endian = SF_ENDIAN_BIG ;		psf_binheader_readf (psf, "LLLLL", &(au_fmt.dataoffset), &(au_fmt.datasize),					&(au_fmt.encoding), &(au_fmt.samplerate), &(au_fmt.channels)) ;		}	else if (marker == DNSDOT_MARKER)	{	psf->endian = SF_ENDIAN_LITTLE ;		psf_binheader_readf (psf, "lllll", &(au_fmt.dataoffset), &(au_fmt.datasize),					&(au_fmt.encoding), &(au_fmt.samplerate), &(au_fmt.channels)) ;		}	else		return SFE_AU_NO_DOTSND ;				psf_log_printf (psf, "  Data Offset : %d\n", au_fmt.dataoffset) ;		if (au_fmt.datasize != 0xFFFFFFFF && au_fmt.dataoffset + au_fmt.datasize != psf->filelength)	{	dword = psf->filelength - au_fmt.dataoffset ;		psf_log_printf (psf, "  Data Size   : %d (should be %d)\n", au_fmt.datasize, dword) ;		au_fmt.datasize = dword ;		}	else		psf_log_printf (psf, "  Data Size   : %d\n", au_fmt.datasize) ;		 	psf->dataoffset = au_fmt.dataoffset ;	psf->datalength = psf->filelength - psf->dataoffset ; 	psf->current  = 0 ;	psf->sf.seekable = SF_TRUE ; 	 	if (fseek (psf->file, psf->dataoffset, SEEK_SET))		return SFE_BAD_SEEK ;	psf->close = (func_close) au_close ;		psf->sf.samplerate	= au_fmt.samplerate ;	psf->sf.channels 	= au_fmt.channels ;						/* Only fill in type major. */	if (psf->endian == SF_ENDIAN_BIG)		psf->sf.format = SF_FORMAT_AU ;	else if (psf->endian == SF_ENDIAN_LITTLE)		psf->sf.format = SF_FORMAT_AULE ;	psf->sf.sections 	= 1 ;	psf_log_printf (psf, "  Encoding    : %d => %s\n", au_fmt.encoding, get_encoding_str (au_fmt.encoding)) ;	psf_log_printf (psf, "  Sample Rate : %d\n", au_fmt.samplerate) ;	psf_log_printf (psf, "  Channels    : %d\n", au_fmt.channels) ;		switch (au_fmt.encoding)	{	case  AU_ENCODING_ULAW_8 :					psf->sf.pcmbitwidth = 16 ;	/* After decoding */				psf->bytewidth   	= 1 ;	/* Before decoding */				psf->blockwidth = psf->sf.channels * psf->bytewidth ;									psf->sf.format |= SF_FORMAT_ULAW ;				ulaw_read_init (psf) ;				break ;												case  AU_ENCODING_PCM_8 :					psf->sf.pcmbitwidth = 8 ;				psf->bytewidth      = BITWIDTH2BYTES (psf->sf.pcmbitwidth) ;				psf->blockwidth = psf->sf.channels * psf->bytewidth ;				psf->sf.format |= SF_FORMAT_PCM ;				psf->chars = SF_CHARS_SIGNED ;													if ((error = pcm_read_init (psf)))					return error ;				break ;		case  AU_ENCODING_PCM_16 :					psf->sf.pcmbitwidth = 16 ;				psf->bytewidth      = BITWIDTH2BYTES (psf->sf.pcmbitwidth) ;				psf->blockwidth = psf->sf.channels * psf->bytewidth ;				psf->sf.format |= SF_FORMAT_PCM ;									if ((error = pcm_read_init (psf)))					return error ;				break ;		case  AU_ENCODING_PCM_24 :					psf->sf.pcmbitwidth = 24 ;				psf->bytewidth      = BITWIDTH2BYTES (psf->sf.pcmbitwidth) ;				psf->blockwidth = psf->sf.channels * psf->bytewidth ;									psf->sf.format |= SF_FORMAT_PCM ;				if ((error = pcm_read_init (psf)))					return error ;				break ;		case  AU_ENCODING_PCM_32 :					psf->sf.pcmbitwidth = 32 ;				psf->bytewidth      = BITWIDTH2BYTES (psf->sf.pcmbitwidth) ;				psf->blockwidth = psf->sf.channels * psf->bytewidth ;									psf->sf.format |= SF_FORMAT_PCM ;									if ((error = pcm_read_init (psf)))					return error ;				break ;							case  AU_ENCODING_ALAW_8 :				psf->sf.pcmbitwidth = 16 ;	/* After decoding */				psf->bytewidth   	= 1 ;	/* Before decoding */				psf->blockwidth = psf->sf.channels * psf->bytewidth ;								psf->sf.format |= SF_FORMAT_ALAW ;								alaw_read_init (psf) ;				break ;							case  AU_ENCODING_ADPCM_G721_32 :  /* G721 32kbs ADPCM */				if (psf->sf.channels != 1)				{	psf_log_printf (psf, "Channels != 1\n") ;					break ;					} ;				psf->sf.pcmbitwidth = 16 ;	/* After decoding */								psf->sf.format |= SF_FORMAT_G721_32 ;								error = au_g72x_reader_init (psf, AU_H_G721_32) ;				psf->sf.seekable = SF_FALSE ;				break ;												case  AU_ENCODING_ADPCM_G723_24 :  /* G723 24kbs ADPCM */				if (psf->sf.channels != 1)				{	psf_log_printf (psf, "Channels != 1\n") ;					break ;					} ;				psf->sf.pcmbitwidth = 16 ;	/* After decoding */								psf->sf.format |= SF_FORMAT_G723_24 ;								error = au_g72x_reader_init (psf, AU_H_G723_24) ;				psf->sf.seekable = SF_FALSE ;				break ;												case  AU_ENCODING_NEXT :					error = SFE_AU_UNKNOWN_FORMAT ;				break ;		default : 				error = SFE_AU_UNKNOWN_FORMAT ;				break ;		} ;	if (error)

⌨️ 快捷键说明

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