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

📄 voc.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 2 页
字号:
	*/	if (subformat == SF_FORMAT_PCM_U8 && psf->sf.channels == 1)	{	/* samplerate = 1000000 / (256 - rate_const) ; */		rate_const = 256 - 1000000 / psf->sf.samplerate ;		/* First type marker, length, rate_const and compression */		psf_binheader_writef (psf, "e1311", VOC_SOUND_DATA, (int) (psf->datalength + 1), rate_const, 0) ;		}	else if (subformat == SF_FORMAT_PCM_U8 && psf->sf.channels == 2)	{	/* sample_rate = 128000000 / (65536 - rate_short) ; */		rate_const = 65536 - 128000000 / psf->sf.samplerate ;		/* First write the VOC_EXTENDED section		** 		marker, length, rate_const and compression		*/		psf_binheader_writef (psf, "e13211", VOC_EXTENDED, 4, rate_const, 0, 1) ;		/* samplerate = 1000000 / (256 - rate_const) ; */		rate_const = 256 - 1000000 / psf->sf.samplerate ;		/*	Now write the VOC_SOUND_DATA section		** 		marker, length, rate_const and compression		*/		psf_binheader_writef (psf, "e1311", VOC_SOUND_DATA, (int) (psf->datalength + 1), rate_const, 0) ;		}	else	{	int length ;		if (psf->sf.channels < 1 || psf->sf.channels > 2)			return SFE_CHANNEL_COUNT ;		switch (subformat)		{	case SF_FORMAT_PCM_U8 :					psf->bytewidth = 1 ;					length = psf->sf.frames * psf->sf.channels * psf->bytewidth + 12 ;					/* Marker, length, sample rate, bitwidth, stereo flag, encoding and fourt zero bytes. */					psf_binheader_writef (psf, "e1341124", VOC_EXTENDED_II, length, psf->sf.samplerate, 16, psf->sf.channels, 4, 0) ;					break ;			case SF_FORMAT_PCM_16 :					psf->bytewidth = 2 ;					length = psf->sf.frames * psf->sf.channels * psf->bytewidth + 12 ;					/* Marker, length, sample rate, bitwidth, stereo flag, encoding and fourt zero bytes. */					psf_binheader_writef (psf, "e1341124", VOC_EXTENDED_II, length, psf->sf.samplerate, 16, psf->sf.channels, 4, 0) ;					break ;			case SF_FORMAT_ALAW :					psf->bytewidth = 1 ;					length = psf->sf.frames * psf->sf.channels * psf->bytewidth + 12 ;					psf_binheader_writef (psf, "e1341124", VOC_EXTENDED_II, length, psf->sf.samplerate, 8, psf->sf.channels, 6, 0) ;					break ;			case SF_FORMAT_ULAW :					psf->bytewidth = 1 ;					length = psf->sf.frames * psf->sf.channels * psf->bytewidth + 12 ;					psf_binheader_writef (psf, "e1341124", VOC_EXTENDED_II, length, psf->sf.samplerate, 8, psf->sf.channels, 7, 0) ;					break ;			default : return SFE_UNIMPLEMENTED ;			} ;		} ;	psf_fwrite (psf->header, psf->headindex, 1, psf) ;	if (psf->error)		return psf->error ;	psf->dataoffset = psf->headindex ;	if (current > 0)		psf_fseek (psf, current, SEEK_SET) ;	return psf->error ;} /* voc_write_header */static intvoc_close	(SF_PRIVATE *psf){	if (psf->mode == SFM_WRITE || psf->mode == SFM_RDWR)	{	/*  Now we know for certain the length of the file we can re-write		**	correct values for the FORM, 8SVX and BODY chunks.		*/		unsigned byte = VOC_TERMINATOR ;		psf_fseek (psf, 0, SEEK_END) ;		/* Write terminator */		psf_fwrite (&byte, 1, 1, psf) ;		voc_write_header (psf, SF_TRUE) ;		} ;	return 0 ;} /* voc_close */static const 	char*voc_encoding2str (int encoding){	switch (encoding)	{	case 0 :	return "8 bit unsigned PCM" ;		case 4 :	return "16 bit signed PCM" ;		case 6 :	return "A-law" ;		case 7 :	return "u-law" ;		default :	break ;		}	return "*** Unknown ***" ;} /* voc_encoding2str *//*====================================================================================*/#if 0static intvoc_multi_init (SF_PRIVATE *psf, VOC_DATA *pvoc){	psf->sf.frames = 0 ;	if (pvoc->bitwidth == 8)	{	psf->read_short		= voc_multi_read_uc2s ;		psf->read_int		= voc_multi_read_uc2i ;		psf->read_float		= voc_multi_read_uc2f ;		psf->read_double	= voc_multi_read_uc2d ;		return 0 ;		} ;	if (pvoc->bitwidth == 16)	{	psf->read_short		= voc_multi_read_les2s ;		psf->read_int		= voc_multi_read_les2i ;		psf->read_float		= voc_multi_read_les2f ;		psf->read_double	= voc_multi_read_les2d ;		return 0 ;		} ;	psf_log_printf (psf, "Error : bitwith != 8 && bitwidth != 16.\n") ;	return SFE_UNIMPLEMENTED ;} /* voc_multi_read_int *//*------------------------------------------------------------------------------------*/static intvoc_multi_read_uc2s (SF_PRIVATE *psf, short *ptr, int len){	return 0 ;} /* voc_multi_read_uc2s */static intvoc_multi_read_les2s (SF_PRIVATE *psf, short *ptr, int len){	return 0 ;} /* voc_multi_read_les2s */static intvoc_multi_read_uc2i (SF_PRIVATE *psf, int *ptr, int len){	return 0 ;} /* voc_multi_read_uc2i */static intvoc_multi_read_les2i (SF_PRIVATE *psf, int *ptr, int len){	return 0 ;} /* voc_multi_read_les2i */static intvoc_multi_read_uc2f (SF_PRIVATE *psf, float *ptr, int len){	return 0 ;} /* voc_multi_read_uc2f */static intvoc_multi_read_les2f (SF_PRIVATE *psf, float *ptr, int len){	return 0 ;} /* voc_multi_read_les2f */static intvoc_multi_read_uc2d (SF_PRIVATE *psf, double *ptr, int len){	return 0 ;} /* voc_multi_read_uc2d */static intvoc_multi_read_les2d (SF_PRIVATE *psf, double *ptr, int len){	return 0 ;} /* voc_multi_read_les2d */#endif/*------------------------------------------------------------------------------------Creative Voice (VOC) file format--------------------------------~From: galt@dsd.es.com(byte numbers are hex!)    HEADER (bytes 00-19)    Series of DATA BLOCKS (bytes 1A+) [Must end w/ Terminator Block]- ---------------------------------------------------------------HEADER:=======     byte #     Description     ------     ------------------------------------------     00-12      "Creative Voice File"     13         1A (eof to abort printing of file)     14-15      Offset of first datablock in .voc file (std 1A 00                in Intel Notation)     16-17      Version number (minor,major) (VOC-HDR puts 0A 01)     18-19      1's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)- ---------------------------------------------------------------DATA BLOCK:===========   Data Block:  TYPE(1-byte), SIZE(3-bytes), INFO(0+ bytes)   NOTE: Terminator Block is an exception -- it has only the TYPE byte.      TYPE   Description     Size (3-byte int)   Info      ----   -----------     -----------------   -----------------------      00     Terminator      (NONE)              (NONE)      01     Sound data      2+length of data    *      02     Sound continue  length of data      Voice Data      03     Silence         3                   **      04     Marker          2                   Marker# (2 bytes)      05     ASCII           length of string    null terminated string      06     Repeat          2                   Count# (2 bytes)      07     End repeat      0                   (NONE)      08     Extended        4                   ***      *Sound Info Format:       ---------------------       00   Sample Rate       01   Compression Type       02+  Voice Data      **Silence Info Format:      ----------------------------      00-01  Length of silence - 1      02     Sample Rate    ***Extended Info Format:       ---------------------       00-01  Time Constant: Mono: 65536 - (256000000/sample_rate)                             Stereo: 65536 - (25600000/(2*sample_rate))       02     Pack       03     Mode: 0 = mono                    1 = stereo  Marker#           -- Driver keeps the most recent marker in a status byte  Count#            -- Number of repetitions + 1                         Count# may be 1 to FFFE for 0 - FFFD repetitions                         or FFFF for endless repetitions  Sample Rate       -- SR byte = 256-(1000000/sample_rate)  Length of silence -- in units of sampling cycle  Compression Type  -- of voice data                         8-bits    = 0                         4-bits    = 1                         2.6-bits  = 2                         2-bits    = 3                         Multi DAC = 3+(# of channels) [interesting--                                       this isn't in the developer's manual]---------------------------------------------------------------------------------Addendum submitted by Votis Kokavessis:After some experimenting with .VOC files I found out that there is a Data BlockType 9, which is not covered in the VOC.TXT file. Here is what I was able to discoverabout this block type:TYPE: 09SIZE: 12 + length of dataINFO: 12 (twelve) bytesINFO STRUCTURE:Bytes 0-1: (Word) Sample Rate (e.g. 44100)Bytes 2-3: zero (could be that bytes 0-3 are a DWord for Sample Rate)Byte 4: Sample Size in bits (e.g. 16)Byte 5: Number of channels (e.g. 1 for mono, 2 for stereo)Byte 6: Unknown (equal to 4 in all files I examined)Bytes 7-11: zero-------------------------------------------------------------------------------------*//*=====================================================================================**=====================================================================================**=====================================================================================**=====================================================================================*//*------------------------------------------------------------------------The following is taken from the Audio File Formats FAQ dated 2-Jan-1995and submitted by Guido van Rossum <guido@cwi.nl>.--------------------------------------------------------------------------Creative Voice (VOC) file format--------------------------------From: galt@dsd.es.com(byte numbers are hex!)    HEADER (bytes 00-19)    Series of DATA BLOCKS (bytes 1A+) [Must end w/ Terminator Block]- ---------------------------------------------------------------HEADER:-------     byte #     Description     ------     ------------------------------------------     00-12      "Creative Voice File"     13         1A (eof to abort printing of file)     14-15      Offset of first datablock in .voc file (std 1A 00                in Intel Notation)     16-17      Version number (minor,major) (VOC-HDR puts 0A 01)     18-19      2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)- ---------------------------------------------------------------DATA BLOCK:-----------   Data Block:  TYPE(1-byte), SIZE(3-bytes), INFO(0+ bytes)   NOTE: Terminator Block is an exception -- it has only the TYPE byte.      TYPE   Description     Size (3-byte int)   Info      ----   -----------     -----------------   -----------------------      00     Terminator      (NONE)              (NONE)      01     Sound data      2+length of data    *      02     Sound continue  length of data      Voice Data      03     Silence         3                   **      04     Marker          2                   Marker# (2 bytes)      05     ASCII           length of string    null terminated string      06     Repeat          2                   Count# (2 bytes)      07     End repeat      0                   (NONE)      08     Extended        4                   ***      *Sound Info Format:       **Silence Info Format:       ---------------------      ----------------------------       00   Sample Rate           00-01  Length of silence - 1       01   Compression Type      02     Sample Rate       02+  Voice Data    ***Extended Info Format:       ---------------------       00-01  Time Constant: Mono: 65536 - (256000000/sample_rate)                             Stereo: 65536 - (25600000/(2*sample_rate))       02     Pack       03     Mode: 0 = mono                    1 = stereo  Marker#           -- Driver keeps the most recent marker in a status byte  Count#            -- Number of repetitions + 1                         Count# may be 1 to FFFE for 0 - FFFD repetitions                         or FFFF for endless repetitions  Sample Rate       -- SR byte = 256-(1000000/sample_rate)  Length of silence -- in units of sampling cycle  Compression Type  -- of voice data                         8-bits    = 0                         4-bits    = 1                         2.6-bits  = 2                         2-bits    = 3                         Multi DAC = 3+(# of channels) [interesting--                                       this isn't in the developer's manual]Detailed description of new data blocks (VOC files version 1.20 and above):        (Source is fax from Barry Boone at Creative Labs, 405/742-6622)BLOCK 8 - digitized sound attribute extension, must preceed block 1.          Used to define stereo, 8 bit audio        BYTE bBlockID;       // = 8        BYTE nBlockLen[3];   // 3 byte length        WORD wTimeConstant;  // time constant = same as block 1        BYTE bPackMethod;    // same as in block 1        BYTE bVoiceMode;     // 0-mono, 1-stereo        Data is stored left, rightBLOCK 9 - data block that supersedes blocks 1 and 8.          Used for stereo, 16 bit.        BYTE bBlockID;          // = 9        BYTE nBlockLen[3];      // length 12 plus length of sound        DWORD dwSamplesPerSec;  // samples per second, not time const.        BYTE bBitsPerSample;    // e.g., 8 or 16        BYTE bChannels;         // 1 for mono, 2 for stereo        WORD wFormat;           // see below        BYTE reserved[4];       // pad to make block w/o data                                // have a size of 16 bytes        Valid values of wFormat are:                0x0000  8-bit unsigned PCM                0x0001  Creative 8-bit to 4-bit ADPCM                0x0002  Creative 8-bit to 3-bit ADPCM                0x0003  Creative 8-bit to 2-bit ADPCM                0x0004  16-bit signed PCM                0x0006  CCITT a-Law                0x0007  CCITT u-Law                0x02000 Creative 16-bit to 4-bit ADPCM        Data is stored left, right------------------------------------------------------------------------*//*** 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: 40a50167-a81c-463a-9e1d-3282ff84e09d*/

⌨️ 快捷键说明

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