mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-27 03:50:29 +00:00
src/nist.c : Fix parsing of odd ulaw encoded file provided by Jan Silovsky.
This commit is contained in:
parent
7167f6d808
commit
e30d581879
@ -1,3 +1,8 @@
|
||||
2009-10-09 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/nist.c
|
||||
Fix parsing of odd ulaw encoded file provided by Jan Silovsky.
|
||||
|
||||
2009-10-06 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* man/sndfile-convert.1
|
||||
|
39
src/nist.c
39
src/nist.c
@ -119,12 +119,11 @@ static char bad_header [] =
|
||||
static int
|
||||
nist_read_header (SF_PRIVATE *psf)
|
||||
{ char *psf_header ;
|
||||
int bitwidth = 0, bytes = 0, count, encoding ;
|
||||
int bitwidth = 0, count, encoding ;
|
||||
unsigned bytes = 0 ;
|
||||
char str [64], *cptr ;
|
||||
long samples ;
|
||||
|
||||
psf->sf.format = SF_FORMAT_NIST ;
|
||||
|
||||
psf_header = psf->u.cbuf ;
|
||||
|
||||
if (sizeof (psf->header) <= NIST_HEADER_LENGTH)
|
||||
@ -164,7 +163,9 @@ nist_read_header (SF_PRIVATE *psf)
|
||||
{ sscanf (cptr, "sample_coding -s%d %63s", &count, str) ;
|
||||
|
||||
if (strcmp (str, "pcm") == 0)
|
||||
{ /* Correct this later when we find out the bitwidth. */
|
||||
encoding = SF_FORMAT_PCM_U8 ;
|
||||
}
|
||||
else if (strcmp (str, "alaw") == 0)
|
||||
encoding = SF_FORMAT_ALAW ;
|
||||
else if ((strcmp (str, "ulaw") == 0) || (strcmp (str, "mu-law") == 0))
|
||||
@ -193,19 +194,16 @@ nist_read_header (SF_PRIVATE *psf)
|
||||
psf->endian = (CPU_IS_BIG_ENDIAN) ? SF_ENDIAN_BIG : SF_ENDIAN_LITTLE ;
|
||||
|
||||
/* This is where we figure out endian-ness. */
|
||||
if ((cptr = strstr (psf_header, "sample_byte_format -s")))
|
||||
{ sscanf (cptr, "sample_byte_format -s%d %8s", &bytes, str) ;
|
||||
if (bytes > 1)
|
||||
{ if (psf->bytewidth == 0)
|
||||
psf->bytewidth = bytes ;
|
||||
else if (psf->bytewidth != bytes)
|
||||
{ psf_log_printf (psf, "psf->bytewidth (%d) != bytes (%d)\n", psf->bytewidth, bytes) ;
|
||||
return SFE_NIST_BAD_ENCODING ;
|
||||
} ;
|
||||
if ((cptr = strstr (psf_header, "sample_byte_format -s"))
|
||||
&& sscanf (cptr, "sample_byte_format -s%u %8s", &bytes, str) == 2)
|
||||
{
|
||||
if (bytes != strlen (str))
|
||||
psf_log_printf (psf, "Weird sample_byte_format : strlen '%s' != %d\n", str, bytes) ;
|
||||
|
||||
if (strstr (str, "01") == str)
|
||||
if (bytes > 1)
|
||||
{ if (strcmp (str, "01") == 0)
|
||||
psf->endian = SF_ENDIAN_LITTLE ;
|
||||
else if (strstr (str, "10"))
|
||||
else if (strcmp (str, "10") == 0)
|
||||
psf->endian = SF_ENDIAN_BIG ;
|
||||
else
|
||||
{ psf_log_printf (psf, "Weird endian-ness : %s\n", str) ;
|
||||
@ -255,6 +253,19 @@ nist_read_header (SF_PRIVATE *psf)
|
||||
else
|
||||
return SFE_UNIMPLEMENTED ;
|
||||
|
||||
/* Sanitize psf->sf.format. */
|
||||
switch (SF_CODEC (psf->sf.format))
|
||||
{ case SF_FORMAT_ULAW :
|
||||
case SF_FORMAT_ALAW :
|
||||
case SF_FORMAT_PCM_U8 :
|
||||
/* Blank out endian bits. */
|
||||
psf->sf.format = SF_FORMAT_NIST | SF_CODEC (psf->sf.format) ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
break ;
|
||||
} ;
|
||||
|
||||
return 0 ;
|
||||
} /* nist_read_header */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user