コード例 #1
0
ファイル: raw.c プロジェクト: andreipaga/audacity
int 	raw_open_read	(SF_PRIVATE *psf)
{	unsigned int subformat ;
	int			error ;
	
	if(! psf->sf.channels || ! psf->sf.pcmbitwidth)
		return SFE_RAW_READ_BAD_SPEC ;
		
	subformat = psf->sf.format & SF_FORMAT_SUBMASK ;

	psf->endian = 0 ;

	if (subformat == SF_FORMAT_PCM_BE)
		psf->endian = SF_ENDIAN_BIG ;
	else if (subformat == SF_FORMAT_PCM_LE)
		psf->endian = SF_ENDIAN_LITTLE ;
	else if (subformat == SF_FORMAT_PCM_S8)
		psf->chars = SF_CHARS_SIGNED ;
	else if (subformat == SF_FORMAT_PCM_U8)
		psf->chars = SF_CHARS_UNSIGNED ;
	else
		return SFE_RAW_READ_BAD_SPEC ;
		
	psf->seek_func = (func_seek) raw_seek ;

	psf->sf.seekable = SF_TRUE ;
	psf->sf.sections = 1 ;

	psf->dataoffset = 0 ;
	psf->bytewidth  = BITWIDTH2BYTES (psf->sf.pcmbitwidth) ;
	psf->blockwidth = psf->sf.channels * psf->bytewidth ;

	if ((error = pcm_read_init (psf)))
		return error ;
		
	if (psf->blockwidth)
		psf->sf.samples = psf->filelength / psf->blockwidth ;

 	psf->datalength = psf->filelength - psf->dataoffset ;

 	psf->current  = 0 ;
	
	return 0 ;
} /* raw_open_read */
コード例 #2
0
ファイル: nist.c プロジェクト: OS2World/MM-SOUND-GOGO
int 	
nist_open_read	(SF_PRIVATE *psf)
{	char	*psf_header ;
	int		error ;

	fseek (psf->file, 0, SEEK_SET) ;
	
	psf_header = (char*) psf->header ;

	fgets (psf_header, SF_HEADER_LEN, psf->file) ;
	psf_log_printf (psf, psf_header) ;
	if (strlen (psf_header) != 8 || strcmp (psf_header, "NIST_1A\n"))
		return SFE_NIST_BAD_HEADER ;
	
	fgets (psf_header, SF_HEADER_LEN, psf->file) ;
	psf_log_printf (psf, psf_header) ;
	if (strlen (psf_header) != 8 || atoi (psf_header) != 1024)
		return SFE_NIST_BAD_HEADER ;

	while (ftell (psf->file) < 1024 && !ferror (psf->file))
	{	fgets (psf_header, SF_HEADER_LEN, psf->file) ;
		psf_log_printf (psf, psf_header) ;
		
		if (strstr (psf_header, "channel_count -i ") == psf_header)
			sscanf (psf_header, "channel_count -i %u", &(psf->sf.channels)) ;
		
		if (strstr (psf_header, "sample_count -i ") == psf_header)
			sscanf (psf_header, "sample_count -i %u", &(psf->sf.samples)) ;

		if (strstr (psf_header, "sample_rate -i ") == psf_header)
			sscanf (psf_header, "sample_rate -i %u", &(psf->sf.samplerate)) ;

		if (strstr (psf_header, "sample_n_bytes -i ") == psf_header)
			sscanf (psf_header, "sample_n_bytes -i %u", &(psf->bytewidth)) ;

		if (strstr (psf_header, "sample_sig_bits -i ") == psf_header)
			sscanf (psf_header, "sample_sig_bits -i %u", &(psf->sf.pcmbitwidth)) ;

		if (strstr (psf_header, "sample_byte_format -s") == psf_header)
		{	int bytes ;
			char str [8] = { 0, 0, 0, 0, 0, 0, 0, 0 } ;
			
			sscanf (psf_header, "sample_byte_format -s%d %5s", &bytes, str) ;
			if (bytes < 2 || bytes > 4)
				return SFE_NIST_BAD_ENCODING ;
				
			psf->bytewidth = bytes ;
				
			if (strstr (str, "01") == str)
			{	psf->endian    = SF_ENDIAN_LITTLE ;
				psf->sf.format = SF_FORMAT_NIST | SF_FORMAT_PCM_LE ;
				}
			else if (strstr (str, "10"))
			{	psf->endian    = SF_ENDIAN_BIG ;
				psf->sf.format = SF_FORMAT_NIST | SF_FORMAT_PCM_BE ;
				} ;
			} ;

		if (strstr (psf_header, "sample_coding -s") == psf_header)
			return SFE_NIST_BAD_ENCODING ;

		if (strstr (psf_header, "end_head") == psf_header)
			break ;
		} ;
		
 	psf->dataoffset = NIST_HEADER_LENGTH ;
 	psf->current  = 0 ;
	psf->sf.seekable = SF_TRUE ;
	psf->sf.sections = 1 ;

	psf->close = (func_close) nist_close ;

	psf->blockwidth = psf->sf.channels * psf->bytewidth ;
	psf->datalength = psf->filelength - psf->dataoffset ;

	if ((error = pcm_read_init (psf)))
		return error ;

	fseek (psf->file, psf->dataoffset, SEEK_SET) ;

	return 0 ;
} /* nist_open_read */