Use audio detect function when 'fmt ' chunk data is suspicious.

This commit is contained in:
Erik de Castro Lopo 2007-04-15 13:04:45 +10:00
parent a4f7c8db03
commit 5ebb50a41f
3 changed files with 55 additions and 15 deletions

View File

@ -1,3 +1,8 @@
2007-04-15 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/wav.c src/wav_w64.c
Use audio detect function when 'fmt ' chunk data is suspicious.
2007-04-14 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* examples/sndfile-data-trim.c

View File

@ -690,13 +690,13 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
default : return SFE_UNIMPLEMENTED ;
} ;
if (wpriv->fmt_is_broken)
wav_w64_analyze (psf) ;
/* Only set the format endian-ness if its non-standard big-endian. */
if (psf->endian == SF_ENDIAN_BIG)
psf->sf.format |= SF_ENDIAN_BIG ;
if (wpriv->fmt_is_broken)
wav_w64_analyze (psf) ;
return 0 ;
} /* wav_read_header */

View File

@ -116,16 +116,13 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, int fmtsize)
{ psf_log_printf (psf, " Bit Width : 24\n") ;
psf_log_printf (psf, "\n"
"Ambiguous information in 'fmt ' chunk. Possibile file types:\n"
" 0) Invalid IEEE float file generated by Syntrillium's Cooledit!\n"
" 1) File generated by ALSA's arecord containing 24 bit samples in 32 bit containers.\n"
" 2) 24 bit file with incorrect Block Align value.\n"
" Ambiguous information in 'fmt ' chunk. Possibile file types:\n"
" 0) Invalid IEEE float file generated by Syntrillium's Cooledit!\n"
" 1) File generated by ALSA's arecord containing 24 bit samples in 32 bit containers.\n"
" 2) 24 bit file with incorrect Block Align value.\n"
"\n") ;
wpriv->fmt_is_broken = 1 ;
wav_fmt->min.bitwidth = 32 ;
wav_fmt->format = WAVE_FORMAT_IEEE_FLOAT ;
}
else if (wav_fmt->min.bitwidth == 0)
{ switch (wav_fmt->format)
@ -362,21 +359,59 @@ wavex_write_guid (SF_PRIVATE *psf, const EXT_SUBFORMAT * subformat)
void
wav_w64_analyze (SF_PRIVATE *psf)
{
{ AUDIO_DETECT ad ;
int format = 0 ;
if (psf->is_pipe)
{ psf_log_printf (psf, "*** Error : Reading from a pipe. Can't analyze data section to figure out real data format.\n\n") ;
return ;
} ;
printf ("wpriv->fmt_is_broken : dataoffset %lld datalength %lld current : %lld\n", psf->dataoffset, psf->datalength, psf_fseek (psf, 0, SEEK_CUR)) ;
psf_log_printf (psf, "---------------------------------------------------\n"
"Format is known to be broken. Using detection code.\n") ;
/* Code goes here. */
ad.endianness = SF_ENDIAN_LITTLE ;
ad.channels = psf->sf.channels ;
psf_fseek (psf, 3 * 4 * 50, SEEK_SET) ;
/* Seek back to start of audio data before returning. */
while (psf_fread (psf->u.ucbuf, 1, 4096, psf) == 4096)
{ format = audio_detect (psf, &ad, psf->u.ucbuf, 4096) ;
if (format != 0)
break ;
} ;
/* Seek to start of DATA section. */
psf_fseek (psf, psf->dataoffset, SEEK_SET) ;
if (format == 0)
{ psf_log_printf (psf, "wav_w64_analyze : detection failed.\n") ;
return ;
} ;
switch (format)
{ case SF_FORMAT_PCM_32 :
case SF_FORMAT_FLOAT :
psf_log_printf (psf, "wav_w64_analyze : found format : 0x%X\n", format) ;
psf->sf.format = (psf->sf.format & ~SF_FORMAT_SUBMASK) + format ;
psf->bytewidth = 4 ;
psf->blockwidth = psf->sf.channels * psf->bytewidth ;
break ;
case SF_FORMAT_PCM_24 :
psf_log_printf (psf, "wav_w64_analyze : found format : 0x%X\n", format) ;
psf->sf.format = (psf->sf.format & ~SF_FORMAT_SUBMASK) + format ;
psf->bytewidth = 3 ;
psf->blockwidth = psf->sf.channels * psf->bytewidth ;
break ;
default :
psf_log_printf (psf, "wav_w64_analyze : unhandled format : 0x%X\n", format) ;
break ;
} ;
return ;
} /* wav_w64_analyze */
/*==============================================================================