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

📄 w64.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 2 页
字号:
/*** Copyright (C) 1999-2004 Erik de Castro Lopo <erikd@mega-nerd.com>**** 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	<string.h>#include	<ctype.h>#include	<time.h>#include	"sndfile.h"#include	"config.h"#include	"sfendian.h"#include	"common.h"#include	"wav_w64.h"/*------------------------------------------------------------------------------** W64 files use 16 byte markers as opposed to the four byte marker of** WAV files.** For comparison purposes, an integer is required, so make an integer** hash for the 16 bytes using MAKE_HASH16 macro, but also create a 16** byte array containing the complete 16 bytes required when writing the** header.*/#define MAKE_HASH16(x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,xa,xb,xc,xd,xe,xf)	\			(	(x0)			^ ((x1) << 1)	^ ((x2) << 2)	^ ((x3) << 3) ^	\				((x4) << 4) 	^ ((x5) << 5)	^ ((x6) << 6)	^ ((x7) << 7) ^	\				((x8) << 8) 	^ ((x9) << 9)	^ ((xa) << 10)	^ ((xb) << 11) ^ \				((xc) << 12) 	^ ((xd) << 13)	^ ((xe) << 14)	^ ((xf) << 15)	)#define MAKE_MARKER16(name,x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,xa,xb,xc,xd,xe,xf)	\			static unsigned char name [16] = { (x0), (x1), (x2), (x3), (x4), (x5), \				(x6), (x7), (x8), (x9), (xa), (xb), (xc), (xd), (xe), (xf) }#define	riff_HASH16 MAKE_HASH16 ('r', 'i', 'f', 'f', 0x2E, 0x91, 0xCF, 0x11, 0xA5, \								0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00)#define	wave_HASH16 	MAKE_HASH16 ('w', 'a', 'v', 'e', 0xF3, 0xAC, 0xD3, 0x11, \								0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A)#define	fmt_HASH16 		MAKE_HASH16 ('f', 'm', 't', ' ', 0xF3, 0xAC, 0xD3, 0x11, \								0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A)#define	fact_HASH16 	MAKE_HASH16 ('f', 'a', 'c', 't', 0xF3, 0xAC, 0xD3, 0x11, \								0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A)#define	data_HASH16 	MAKE_HASH16 ('d', 'a', 't', 'a', 0xF3, 0xAC, 0xD3, 0x11, \								0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A)#define	ACID_HASH16 	MAKE_HASH16 (0x6D, 0x07, 0x1C, 0xEA, 0xA3, 0xEF, 0x78, 0x4C, \								0x90, 0x57, 0x7F, 0x79, 0xEE, 0x25, 0x2A, 0xAE)MAKE_MARKER16 (riff_MARKER16, 'r', 'i', 'f', 'f', 0x2E, 0x91, 0xCF, 0x11,								0xA5, 0xD6, 0x28, 0xDB, 0x04, 0xC1, 0x00, 0x00) ;MAKE_MARKER16 (wave_MARKER16, 'w', 'a', 'v', 'e', 0xF3, 0xAC, 0xD3, 0x11,								0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A) ;MAKE_MARKER16 (fmt_MARKER16, 'f', 'm', 't', ' ', 0xF3, 0xAC, 0xD3, 0x11,								0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A) ;MAKE_MARKER16 (fact_MARKER16, 'f', 'a', 'c', 't', 0xF3, 0xAC, 0xD3, 0x11,								0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A) ;MAKE_MARKER16 (data_MARKER16, 'd', 'a', 't', 'a', 0xF3, 0xAC, 0xD3, 0x11,								0x8C, 0xD1, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A) ;enum{	HAVE_riff	= 0x01,	HAVE_wave	= 0x02,	HAVE_fmt	= 0x04,	HAVE_fact	= 0x08,	HAVE_data	= 0x20} ;/*------------------------------------------------------------------------------ * Private static functions. */static int	w64_read_header	(SF_PRIVATE *psf, int *blockalign, int *framesperblock) ;static int	w64_write_header (SF_PRIVATE *psf, int calc_length) ;static int	w64_close (SF_PRIVATE *psf) ;/*------------------------------------------------------------------------------** Public function.*/intw64_open	(SF_PRIVATE *psf){	int	subformat, error, blockalign = 0, framesperblock = 0 ;	if (psf->mode == SFM_READ || (psf->mode == SFM_RDWR &&psf->filelength > 0))	{	if ((error = w64_read_header (psf, &blockalign, &framesperblock)))			return error ;		} ;	if ((psf->sf.format & SF_FORMAT_TYPEMASK) != SF_FORMAT_W64)		return	SFE_BAD_OPEN_FORMAT ;	subformat = psf->sf.format & SF_FORMAT_SUBMASK ;	if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)	{	if (psf->is_pipe)			return SFE_NO_PIPE_WRITE ;		psf->endian = SF_ENDIAN_LITTLE ;		/* All W64 files are little endian. */		psf->blockwidth = psf->bytewidth * psf->sf.channels ;		if (subformat == SF_FORMAT_IMA_ADPCM || subformat == SF_FORMAT_MS_ADPCM)		{	blockalign = wav_w64_srate2blocksize (psf->sf.samplerate * psf->sf.channels) ;			framesperblock = -1 ;			/* FIXME : This block must go */			psf->filelength = SF_COUNT_MAX ;			psf->datalength = psf->filelength ;			if (psf->sf.frames <= 0)				psf->sf.frames = (psf->blockwidth) ? psf->filelength / psf->blockwidth : psf->filelength ;			/* EMXIF : This block must go */			} ;		if ((error = w64_write_header (psf, SF_FALSE)))			return error ;		psf->write_header = w64_write_header ;		} ;	psf->close = w64_close ;	switch (subformat)	{	case SF_FORMAT_PCM_U8 :					error = pcm_init (psf) ;					break ;		case SF_FORMAT_PCM_16 :		case SF_FORMAT_PCM_24 :		case SF_FORMAT_PCM_32 :					error = pcm_init (psf) ;					break ;		case SF_FORMAT_ULAW :					error = ulaw_init (psf) ;					break ;		case SF_FORMAT_ALAW :					error = alaw_init (psf) ;					break ;		/* Lite remove start */		case SF_FORMAT_FLOAT :					error = float32_init (psf) ;					break ;		case SF_FORMAT_DOUBLE :					error = double64_init (psf) ;					break ;		case SF_FORMAT_IMA_ADPCM :					error = wav_w64_ima_init (psf, blockalign, framesperblock) ;					break ;		case SF_FORMAT_MS_ADPCM :					error = wav_w64_msadpcm_init (psf, blockalign, framesperblock) ;					break ;		/* Lite remove end */		case SF_FORMAT_GSM610 :					error = gsm610_init (psf) ;					break ;		default : 	return SFE_UNIMPLEMENTED ;		} ;	return error ;} /* w64_open *//*=========================================================================** Private functions.*/static intw64_read_header	(SF_PRIVATE *psf, int *blockalign, int *framesperblock){	WAV_FMT 	wav_fmt ;	int			dword = 0, marker, format = 0 ;	sf_count_t	chunk_size, bytesread = 0 ;	int			parsestage = 0, error, done = 0 ;	/* Set position to start of file to begin reading header. */	psf_binheader_readf (psf, "p", 0) ;	while (! done)	{	/* Read the 4 byte marker and jump 12 bytes. */		bytesread += psf_binheader_readf (psf, "h", &marker) ;		chunk_size = 0 ;		switch (marker)		{	case riff_HASH16 :					if (parsestage)						return SFE_W64_NO_RIFF ;					bytesread += psf_binheader_readf (psf, "e8", &chunk_size) ;					if (psf->filelength < chunk_size)						psf_log_printf (psf, "riff : %D (should be %D)\n", chunk_size, psf->filelength) ;					else						psf_log_printf (psf, "riff : %D\n", chunk_size) ;					parsestage |= HAVE_riff ;					break ;			case ACID_HASH16:					psf_log_printf (psf, "Looks like an ACID file. Exiting.\n") ;					return SFE_UNIMPLEMENTED ;			case wave_HASH16 :					if ((parsestage & HAVE_riff) != HAVE_riff)						return SFE_W64_NO_WAVE ;					psf_log_printf (psf, "wave\n") ;					parsestage |= HAVE_wave ;					break ;			case fmt_HASH16 :					if ((parsestage & (HAVE_riff | HAVE_wave)) != (HAVE_riff | HAVE_wave))						return SFE_W64_NO_FMT ;					bytesread += psf_binheader_readf (psf, "e8", &chunk_size) ;					psf_log_printf (psf, " fmt : %D\n", chunk_size) ;					/* size of 16 byte marker and 8 byte chunk_size value. */					chunk_size -= 24 ;					if ((error = wav_w64_read_fmt_chunk (psf, &wav_fmt, (int) chunk_size)))						return error ;					if (chunk_size % 8)						psf_binheader_readf (psf, "j", 8 - (chunk_size % 8)) ;					format		= wav_fmt.format ;					parsestage |= HAVE_fmt ;					break ;			case fact_HASH16:					{	sf_count_t frames ;						psf_binheader_readf (psf, "e88", &chunk_size, &frames) ;						psf_log_printf (psf, "   fact : %D\n     frames : %D\n",										chunk_size, frames) ;						} ;					break ;			case data_HASH16 :					if ((parsestage & (HAVE_riff | HAVE_wave | HAVE_fmt)) != (HAVE_riff | HAVE_wave | HAVE_fmt))						return SFE_W64_NO_DATA ;					psf_binheader_readf (psf, "e8", &chunk_size) ;					psf->dataoffset = psf_ftell (psf) ;					psf->datalength = chunk_size - 24 ;					if (chunk_size % 8)						chunk_size += 8 - (chunk_size % 8) ;					psf_log_printf (psf, "data : %D\n", chunk_size) ;					parsestage |= HAVE_data ;					if (! psf->sf.seekable)						break ;					/* Seek past data and continue reading header. */					psf_fseek (psf, chunk_size, SEEK_CUR) ;					break ;			default :

⌨️ 快捷键说明

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