mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
Fix a couple of AIFF and WAV regressions from version 1.0.25.
This commit is contained in:
parent
4a541cd729
commit
9c34ca4ba5
@ -1,7 +1,12 @@
|
||||
2012-02-02 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/aiff.c src/wav.c
|
||||
Fix a couple of regressions from version 1.0.25.
|
||||
|
||||
2012-02-01 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/strings.c
|
||||
Small refactoring. Make sure that the memory allocation size if always > 0
|
||||
Minor refactoring. Make sure that the memory allocation size if always > 0
|
||||
to avoid undefined behaviour.
|
||||
|
||||
2012-02-29 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
220
src/aiff.c
220
src/aiff.c
@ -382,7 +382,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
{ SSND_CHUNK ssnd_fmt ;
|
||||
AIFF_PRIVATE *paiff ;
|
||||
BUF_UNION ubuf ;
|
||||
unsigned marker, chunk_size, dword, FORMsize, SSNDsize, bytesread ;
|
||||
unsigned marker, chunk_size = 0, FORMsize, SSNDsize, bytesread ;
|
||||
int k, found_chunk = 0, done = 0, error = 0 ;
|
||||
char *cptr ;
|
||||
int instr_found = 0, mark_found = 0, mark_count = 0 ;
|
||||
@ -409,7 +409,10 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
** one and then check for the mandatory chunks at the end.
|
||||
*/
|
||||
while (! done)
|
||||
{ psf_binheader_readf (psf, "Em4", &marker, &chunk_size) ;
|
||||
{ size_t jump = chunk_size & 1 ;
|
||||
|
||||
marker = chunk_size = 0 ;
|
||||
psf_binheader_readf (psf, "Ejm4", jump, &marker, &chunk_size) ;
|
||||
|
||||
if (psf->file.mode == SFM_RDWR && (found_chunk & HAVE_SSND))
|
||||
return SFE_AIFF_RW_SSND_NOT_LAST ;
|
||||
@ -423,18 +426,6 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
|
||||
FORMsize = chunk_size ;
|
||||
|
||||
if (psf->fileoffset > 0 && psf->filelength > FORMsize + 8)
|
||||
{ /* Set file length. */
|
||||
psf->filelength = FORMsize + 8 ;
|
||||
psf_log_printf (psf, "FORM : %u\n", FORMsize) ;
|
||||
}
|
||||
else if (FORMsize != psf->filelength - 2 * SIGNED_SIZEOF (dword))
|
||||
{ dword = psf->filelength - 2 * sizeof (dword) ;
|
||||
psf_log_printf (psf, "FORM : %u (should be %u)\n", FORMsize, dword) ;
|
||||
FORMsize = dword ;
|
||||
}
|
||||
else
|
||||
psf_log_printf (psf, "FORM : %u\n", FORMsize) ;
|
||||
found_chunk |= HAVE_FORM ;
|
||||
psf_binheader_readf (psf, "m", &marker) ;
|
||||
switch (marker)
|
||||
@ -445,20 +436,29 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
default :
|
||||
break ;
|
||||
} ;
|
||||
|
||||
if (psf->fileoffset > 0 && psf->filelength > FORMsize + 8)
|
||||
{ /* Set file length. */
|
||||
psf->filelength = FORMsize + 8 ;
|
||||
psf_log_printf (psf, "FORM : %u\n %M\n", FORMsize, marker) ;
|
||||
}
|
||||
else if (FORMsize != psf->filelength - 2 * SIGNED_SIZEOF (chunk_size))
|
||||
{ chunk_size = psf->filelength - 2 * sizeof (chunk_size) ;
|
||||
psf_log_printf (psf, "FORM : %u (should be %u)\n %M\n", FORMsize, chunk_size, marker) ;
|
||||
FORMsize = chunk_size ;
|
||||
}
|
||||
else
|
||||
psf_log_printf (psf, "FORM : %u\n %M\n", FORMsize, marker) ;
|
||||
/* Set this to 0, so we don't jump a byte when parsing the next marker. */
|
||||
chunk_size = 0 ;
|
||||
break ;
|
||||
|
||||
|
||||
case COMM_MARKER :
|
||||
paiff->comm_offset = psf_ftell (psf) - 8 ;
|
||||
chunk_size += chunk_size & 1 ;
|
||||
comm_fmt->size = chunk_size ;
|
||||
error = aiff_read_comm_chunk (psf, comm_fmt) ;
|
||||
|
||||
psf->sf.samplerate = tenbytefloat2int (comm_fmt->sampleRate) ;
|
||||
psf->sf.frames = comm_fmt->numSampleFrames ;
|
||||
psf->sf.channels = comm_fmt->numChannels ;
|
||||
psf->bytewidth = BITWIDTH2BYTES (comm_fmt->sampleSize) ;
|
||||
|
||||
if (error)
|
||||
if ((error = aiff_read_comm_chunk (psf, comm_fmt)) != 0)
|
||||
return error ;
|
||||
|
||||
found_chunk |= HAVE_COMM ;
|
||||
@ -491,16 +491,16 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
psf_log_printf (psf, " Ch Position Value\n") ;
|
||||
|
||||
cptr = ubuf.cbuf ;
|
||||
for (dword = 0 ; dword < (unsigned) psf->sf.channels ; dword++)
|
||||
for (k = 0 ; k < psf->sf.channels ; k++)
|
||||
{ float value ;
|
||||
unsigned int position ;
|
||||
|
||||
psf_binheader_readf (psf, "Ef4", &value, &position) ;
|
||||
psf->peak_info->peaks [dword].value = value ;
|
||||
psf->peak_info->peaks [dword].position = position ;
|
||||
psf->peak_info->peaks [k].value = value ;
|
||||
psf->peak_info->peaks [k].position = position ;
|
||||
|
||||
snprintf (cptr, sizeof (ubuf.scbuf), " %2d %-12" PRId64 " %g\n",
|
||||
dword, psf->peak_info->peaks [dword].position, psf->peak_info->peaks [dword].value) ;
|
||||
k, psf->peak_info->peaks [k].position, psf->peak_info->peaks [k].value) ;
|
||||
cptr [sizeof (ubuf.scbuf) - 1] = 0 ;
|
||||
psf_log_printf (psf, "%s", cptr) ;
|
||||
} ;
|
||||
@ -554,54 +554,52 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
break ;
|
||||
|
||||
case c_MARKER :
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
if (chunk_size == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf))
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, dword) ;
|
||||
if (chunk_size >= SIGNED_SIZEOF (ubuf.scbuf))
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, chunk_size) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_binheader_readf (psf, "b", cptr, chunk_size + (chunk_size & 1)) ;
|
||||
cptr [chunk_size] = 0 ;
|
||||
|
||||
psf_sanitize_string (cptr, dword) ;
|
||||
psf_sanitize_string (cptr, chunk_size) ;
|
||||
|
||||
psf_log_printf (psf, " %M : %s\n", marker, cptr) ;
|
||||
psf_store_string (psf, SF_STR_COPYRIGHT, cptr) ;
|
||||
chunk_size += chunk_size & 1 ;
|
||||
break ;
|
||||
|
||||
case AUTH_MARKER :
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
if (chunk_size == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf) - 1)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, dword) ;
|
||||
if (chunk_size >= SIGNED_SIZEOF (ubuf.scbuf) - 1)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, chunk_size) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_binheader_readf (psf, "b", cptr, chunk_size + (chunk_size & 1)) ;
|
||||
cptr [chunk_size] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", marker, cptr) ;
|
||||
psf_store_string (psf, SF_STR_ARTIST, cptr) ;
|
||||
chunk_size += chunk_size & 1 ;
|
||||
break ;
|
||||
|
||||
case COMT_MARKER :
|
||||
{ unsigned short count, id, len ;
|
||||
unsigned int timestamp ;
|
||||
unsigned int timestamp, bytes ;
|
||||
|
||||
dword = chunk_size ;
|
||||
psf_binheader_readf (psf, "E2", &count) ;
|
||||
psf_log_printf (psf, " %M : %d\n count : %d\n", marker, dword, count) ;
|
||||
dword += (dword & 1) ;
|
||||
if (dword == 0)
|
||||
if (chunk_size == 0)
|
||||
break ;
|
||||
dword -= 2 ;
|
||||
bytes = chunk_size ;
|
||||
bytes -= psf_binheader_readf (psf, "E2", &count) ;
|
||||
psf_log_printf (psf, " %M : %d\n count : %d\n", marker, chunk_size, count) ;
|
||||
|
||||
for (k = 0 ; k < count ; k++)
|
||||
{ dword -= psf_binheader_readf (psf, "E422", ×tamp, &id, &len) ;
|
||||
{ bytes -= psf_binheader_readf (psf, "E422", ×tamp, &id, &len) ;
|
||||
psf_log_printf (psf, " time : 0x%x\n marker : %x\n length : %d\n", timestamp, id, len) ;
|
||||
|
||||
if (len + 1 > SIGNED_SIZEOF (ubuf.scbuf))
|
||||
@ -610,89 +608,88 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
} ;
|
||||
|
||||
cptr = ubuf.cbuf ;
|
||||
dword -= psf_binheader_readf (psf, "b", cptr, len) ;
|
||||
bytes -= psf_binheader_readf (psf, "b", cptr, len) ;
|
||||
cptr [len] = 0 ;
|
||||
psf_log_printf (psf, " string : %s\n", cptr) ;
|
||||
} ;
|
||||
|
||||
if (dword > 0)
|
||||
psf_binheader_readf (psf, "j", dword) ;
|
||||
if (bytes > 0)
|
||||
psf_binheader_readf (psf, "j", bytes) ;
|
||||
} ;
|
||||
break ;
|
||||
|
||||
case APPL_MARKER :
|
||||
{ unsigned appl_marker ;
|
||||
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
if (chunk_size == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf) - 1)
|
||||
{ psf_log_printf (psf, " %M : %d (too big, skipping)\n", marker, dword) ;
|
||||
psf_binheader_readf (psf, "j", dword + (dword & 1)) ;
|
||||
if (chunk_size >= SIGNED_SIZEOF (ubuf.scbuf) - 1)
|
||||
{ psf_log_printf (psf, " %M : %d (too big, skipping)\n", marker, chunk_size) ;
|
||||
psf_binheader_readf (psf, "j", chunk_size + (chunk_size & 1)) ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
if (dword < 4)
|
||||
{ psf_log_printf (psf, " %M : %d (too small, skipping)\n", marker, dword) ;
|
||||
psf_binheader_readf (psf, "j", dword + (dword & 1)) ;
|
||||
if (chunk_size < 4)
|
||||
{ psf_log_printf (psf, " %M : %d (too small, skipping)\n", marker, chunk_size) ;
|
||||
psf_binheader_readf (psf, "j", chunk_size + (chunk_size & 1)) ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "mb", &appl_marker, cptr, dword + (dword & 1) - 4) ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_binheader_readf (psf, "mb", &appl_marker, cptr, chunk_size + (chunk_size & 1) - 4) ;
|
||||
cptr [chunk_size] = 0 ;
|
||||
|
||||
for (k = 0 ; k < (int) dword ; k++)
|
||||
for (k = 0 ; k < (int) chunk_size ; k++)
|
||||
if (! psf_isprint (cptr [k]))
|
||||
{ cptr [k] = 0 ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
psf_log_printf (psf, " %M : %d\n AppSig : %M\n Name : %s\n", marker, dword, appl_marker, cptr) ;
|
||||
psf_log_printf (psf, " %M : %d\n AppSig : %M\n Name : %s\n", marker, chunk_size, appl_marker, cptr) ;
|
||||
psf_store_string (psf, SF_STR_SOFTWARE, cptr) ;
|
||||
chunk_size += chunk_size & 1 ;
|
||||
} ;
|
||||
break ;
|
||||
|
||||
case NAME_MARKER :
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
if (chunk_size == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf) - 2)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, dword) ;
|
||||
if (chunk_size >= SIGNED_SIZEOF (ubuf.scbuf) - 2)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, chunk_size) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_binheader_readf (psf, "b", cptr, chunk_size + (chunk_size & 1)) ;
|
||||
cptr [chunk_size] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", marker, cptr) ;
|
||||
psf_store_string (psf, SF_STR_TITLE, cptr) ;
|
||||
chunk_size += chunk_size & 1 ;
|
||||
break ;
|
||||
|
||||
case ANNO_MARKER :
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
if (chunk_size == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf) - 2)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, dword) ;
|
||||
if (chunk_size >= SIGNED_SIZEOF (ubuf.scbuf) - 2)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, chunk_size) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_binheader_readf (psf, "b", cptr, chunk_size + (chunk_size & 1)) ;
|
||||
cptr [chunk_size] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", marker, cptr) ;
|
||||
psf_store_string (psf, SF_STR_COMMENT, cptr) ;
|
||||
chunk_size += chunk_size & 1 ;
|
||||
break ;
|
||||
|
||||
case INST_MARKER :
|
||||
dword = chunk_size ;
|
||||
if (dword != SIZEOF_INST_CHUNK)
|
||||
{ psf_log_printf (psf, " %M : %d (should be %d)\n", marker, dword, SIZEOF_INST_CHUNK) ;
|
||||
psf_binheader_readf (psf, "j", dword) ;
|
||||
if (chunk_size != SIZEOF_INST_CHUNK)
|
||||
{ psf_log_printf (psf, " %M : %d (should be %d)\n", marker, chunk_size, SIZEOF_INST_CHUNK) ;
|
||||
psf_binheader_readf (psf, "j", chunk_size) ;
|
||||
break ;
|
||||
} ;
|
||||
psf_log_printf (psf, " %M : %d\n", marker, dword) ;
|
||||
psf_log_printf (psf, " %M : %d\n", marker, chunk_size) ;
|
||||
{ unsigned char bytes [6] ;
|
||||
short gain ;
|
||||
|
||||
@ -753,16 +750,14 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
break ;
|
||||
|
||||
case basc_MARKER :
|
||||
dword = chunk_size ;
|
||||
psf_log_printf (psf, " basc : %u\n", dword) ;
|
||||
psf_log_printf (psf, " basc : %u\n", chunk_size) ;
|
||||
|
||||
if ((error = aiff_read_basc_chunk (psf, dword)))
|
||||
if ((error = aiff_read_basc_chunk (psf, chunk_size)))
|
||||
return error ;
|
||||
break ;
|
||||
|
||||
case MARK_MARKER :
|
||||
dword = chunk_size ;
|
||||
psf_log_printf (psf, " %M : %d\n", marker, dword) ;
|
||||
psf_log_printf (psf, " %M : %d\n", marker, chunk_size) ;
|
||||
{ unsigned short mark_id, n = 0 ;
|
||||
unsigned int position ;
|
||||
|
||||
@ -777,7 +772,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
if (paiff->markstr == NULL)
|
||||
return SFE_MALLOC_FAILED ;
|
||||
|
||||
for (n = 0 ; n < mark_count && bytesread < dword ; n++)
|
||||
for (n = 0 ; n < mark_count && bytesread < chunk_size ; n++)
|
||||
{ unsigned int pstr_len ;
|
||||
unsigned char ch ;
|
||||
|
||||
@ -809,7 +804,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
} ;
|
||||
} ;
|
||||
mark_found++ ;
|
||||
psf_binheader_readf (psf, "j", dword - bytesread) ;
|
||||
psf_binheader_readf (psf, "j", chunk_size - bytesread) ;
|
||||
break ;
|
||||
|
||||
case FVER_MARKER :
|
||||
@ -817,47 +812,40 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
/* Fall through to next case. */
|
||||
|
||||
case SFX_MARKER :
|
||||
dword = chunk_size ;
|
||||
psf_log_printf (psf, " %M : %d\n", marker, dword) ;
|
||||
|
||||
psf_binheader_readf (psf, "j", dword) ;
|
||||
psf_log_printf (psf, " %M : %d\n", marker, chunk_size) ;
|
||||
psf_binheader_readf (psf, "j", chunk_size) ;
|
||||
break ;
|
||||
|
||||
case NONE_MARKER :
|
||||
/* Fix for broken AIFC files with incorrect COMM chunk length. */
|
||||
{ unsigned char byte ;
|
||||
psf_binheader_readf (psf, "1", &byte) ;
|
||||
dword = byte ;
|
||||
psf_binheader_readf (psf, "j", dword) ;
|
||||
}
|
||||
chunk_size = (chunk_size >> 24) - 3 ;
|
||||
psf_log_printf (psf, " %M : %d\n", marker, chunk_size) ;
|
||||
psf_binheader_readf (psf, "j", make_size_t (chunk_size)) ;
|
||||
break ;
|
||||
|
||||
case CHAN_MARKER :
|
||||
dword = chunk_size ;
|
||||
|
||||
if (dword < 12)
|
||||
{ psf_log_printf (psf, " %M : %d (should be >= 12)\n", marker, dword) ;
|
||||
psf_binheader_readf (psf, "j", dword) ;
|
||||
if (chunk_size < 12)
|
||||
{ psf_log_printf (psf, " %M : %d (should be >= 12)\n", marker, chunk_size) ;
|
||||
psf_binheader_readf (psf, "j", chunk_size) ;
|
||||
break ;
|
||||
}
|
||||
|
||||
psf_log_printf (psf, " %M : %d\n", marker, dword) ;
|
||||
psf_log_printf (psf, " %M : %d\n", marker, chunk_size) ;
|
||||
|
||||
if ((error = aiff_read_chanmap (psf, dword)))
|
||||
if ((error = aiff_read_chanmap (psf, chunk_size)))
|
||||
return error ;
|
||||
break ;
|
||||
|
||||
default :
|
||||
if (psf_isprint ((marker >> 24) & 0xFF) && psf_isprint ((marker >> 16) & 0xFF)
|
||||
&& psf_isprint ((marker >> 8) & 0xFF) && psf_isprint (marker & 0xFF))
|
||||
{ dword = chunk_size ;
|
||||
psf_log_printf (psf, " %M : %d (unknown marker)\n", marker, dword) ;
|
||||
{ psf_log_printf (psf, " %M : %d (unknown marker)\n", marker, chunk_size) ;
|
||||
|
||||
psf_binheader_readf (psf, "j", dword) ;
|
||||
psf_binheader_readf (psf, "j", chunk_size) ;
|
||||
break ;
|
||||
} ;
|
||||
if ((dword = psf_ftell (psf)) & 0x03)
|
||||
{ psf_log_printf (psf, " Unknown chunk marker %X at position %d. Resyncing.\n", marker, dword - 4) ;
|
||||
if ((chunk_size = psf_ftell (psf)) & 0x03)
|
||||
{ psf_log_printf (psf, " Unknown chunk marker %X at position %d. Resyncing.\n", marker, chunk_size - 4) ;
|
||||
|
||||
psf_binheader_readf (psf, "j", -3) ;
|
||||
break ;
|
||||
@ -870,7 +858,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
if ((! psf->sf.seekable) && (found_chunk & HAVE_SSND))
|
||||
break ;
|
||||
|
||||
if (psf_ftell (psf) >= psf->filelength - (2 * SIGNED_SIZEOF (dword)))
|
||||
if (psf_ftell (psf) >= psf->filelength - (2 * SIGNED_SIZEOF (int32_t)))
|
||||
break ;
|
||||
} ; /* while (1) */
|
||||
|
||||
@ -921,7 +909,7 @@ aiff_close (SF_PRIVATE *psf)
|
||||
static int
|
||||
aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
{ BUF_UNION ubuf ;
|
||||
int error = 0, subformat ;
|
||||
int subformat, samplerate ;
|
||||
|
||||
ubuf.scbuf [0] = 0 ;
|
||||
|
||||
@ -929,7 +917,6 @@ aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
** procesors are not able to deal with this (ie bus fault) so we have
|
||||
** to take special care.
|
||||
*/
|
||||
comm_fmt->size += comm_fmt->size & 1 ;
|
||||
|
||||
psf_binheader_readf (psf, "E242b", &(comm_fmt->numChannels), &(comm_fmt->numSampleFrames),
|
||||
&(comm_fmt->sampleSize), &(comm_fmt->sampleRate), SIGNED_SIZEOF (comm_fmt->sampleRate)) ;
|
||||
@ -959,7 +946,9 @@ aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
ubuf.scbuf [read_len + 1] = 0 ;
|
||||
} ;
|
||||
|
||||
psf_log_printf (psf, " Sample Rate : %d\n", tenbytefloat2int (comm_fmt->sampleRate)) ;
|
||||
samplerate = tenbytefloat2int (comm_fmt->sampleRate) ;
|
||||
|
||||
psf_log_printf (psf, " Sample Rate : %d\n", samplerate) ;
|
||||
psf_log_printf (psf, " Frames : %u%s\n", comm_fmt->numSampleFrames, (comm_fmt->numSampleFrames == 0 && psf->filelength > 104) ? " (Should not be 0)" : "") ;
|
||||
psf_log_printf (psf, " Channels : %d\n", comm_fmt->numChannels) ;
|
||||
|
||||
@ -977,6 +966,11 @@ aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
|
||||
subformat = s_bitwidth_to_subformat (comm_fmt->sampleSize) ;
|
||||
|
||||
psf->sf.samplerate = samplerate ;
|
||||
psf->sf.frames = comm_fmt->numSampleFrames ;
|
||||
psf->sf.channels = comm_fmt->numChannels ;
|
||||
psf->bytewidth = BITWIDTH2BYTES (comm_fmt->sampleSize) ;
|
||||
|
||||
psf->endian = SF_ENDIAN_BIG ;
|
||||
|
||||
switch (comm_fmt->encoding)
|
||||
@ -1053,7 +1047,7 @@ aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
|
||||
default :
|
||||
psf_log_printf (psf, "AIFC : Unimplemented format : %M\n", comm_fmt->encoding) ;
|
||||
error = SFE_UNIMPLEMENTED ;
|
||||
return SFE_UNIMPLEMENTED ;
|
||||
} ;
|
||||
|
||||
if (! ubuf.scbuf [0])
|
||||
@ -1061,7 +1055,7 @@ aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
else
|
||||
psf_log_printf (psf, " Encoding : %M => %s\n", comm_fmt->encoding, ubuf.scbuf) ;
|
||||
|
||||
return error ;
|
||||
return 0 ;
|
||||
} /* aiff_read_comm_chunk */
|
||||
|
||||
|
||||
|
25
src/wav.c
25
src/wav.c
@ -84,7 +84,7 @@
|
||||
#define umid_MARKER (MAKE_MARKER ('u', 'm', 'i', 'd'))
|
||||
#define SyLp_MARKER (MAKE_MARKER ('S', 'y', 'L', 'p'))
|
||||
#define Cr8r_MARKER (MAKE_MARKER ('C', 'r', '8', 'r'))
|
||||
#define JUNQ_MARKER (MAKE_MARKER ('J', 'U', 'N', 'Q'))
|
||||
#define JUNK_MARKER (MAKE_MARKER ('J', 'U', 'N', 'K'))
|
||||
#define PMX_MARKER (MAKE_MARKER ('_', 'P', 'M', 'X'))
|
||||
#define inst_MARKER (MAKE_MARKER ('i', 'n', 's', 't'))
|
||||
#define AFAn_MARKER (MAKE_MARKER ('A', 'F', 'A', 'n'))
|
||||
@ -103,6 +103,7 @@
|
||||
#define ISRC_MARKER (MAKE_MARKER ('I', 'S', 'R', 'C'))
|
||||
#define ISBJ_MARKER (MAKE_MARKER ('I', 'S', 'B', 'J'))
|
||||
#define ICMT_MARKER (MAKE_MARKER ('I', 'C', 'M', 'T'))
|
||||
#define IAUT_MARKER (MAKE_MARKER ('I', 'A', 'U', 'T'))
|
||||
|
||||
/* Weird WAVPACK marker which can show up at the start of the DATA section. */
|
||||
#define wvpk_MARKER (MAKE_MARKER ('w', 'v', 'p', 'k'))
|
||||
@ -342,7 +343,10 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
psf->rwf_endian = (marker == RIFF_MARKER) ? SF_ENDIAN_LITTLE : SF_ENDIAN_BIG ;
|
||||
|
||||
while (! done)
|
||||
{ psf_binheader_readf (psf, "jm4", chunk_size & 1 ? 1 : 0, &marker, &chunk_size) ;
|
||||
{ size_t jump = chunk_size & 1 ;
|
||||
|
||||
marker = chunk_size = 0 ;
|
||||
psf_binheader_readf (psf, "jm4", jump, &marker, &chunk_size) ;
|
||||
|
||||
psf_store_read_chunk (&psf->rchunks, marker, psf_ftell (psf), chunk_size) ;
|
||||
|
||||
@ -384,6 +388,7 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
return SFE_WAV_NO_WAVE ;
|
||||
parsestage |= HAVE_WAVE ;
|
||||
psf_log_printf (psf, "WAVE\n") ;
|
||||
chunk_size = 0 ;
|
||||
break ;
|
||||
|
||||
case fmt_MARKER :
|
||||
@ -433,10 +438,8 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
if (psf->datalength + psf->dataoffset < psf->filelength)
|
||||
psf->dataend = psf->datalength + psf->dataoffset ;
|
||||
|
||||
if (format == WAVE_FORMAT_MS_ADPCM && psf->datalength % 2)
|
||||
{ psf->datalength ++ ;
|
||||
psf_log_printf (psf, "*** Data length odd. Increasing it by 1.\n") ;
|
||||
} ;
|
||||
psf->datalength += chunk_size & 1 ;
|
||||
chunk_size = 0 ;
|
||||
} ;
|
||||
|
||||
if (! psf->sf.seekable || psf->dataoffset < 0)
|
||||
@ -611,7 +614,7 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
case umid_MARKER :
|
||||
case SyLp_MARKER :
|
||||
case Cr8r_MARKER :
|
||||
case JUNQ_MARKER :
|
||||
case JUNK_MARKER :
|
||||
case PMX_MARKER :
|
||||
case DISP_MARKER :
|
||||
case MEXT_MARKER :
|
||||
@ -628,13 +631,13 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
break ;
|
||||
} ;
|
||||
if (psf_ftell (psf) & 0x03)
|
||||
{ psf_log_printf (psf, " Unknown chunk marker at position %D. Resynching.\n", psf_ftell (psf) - 4) ;
|
||||
{ psf_log_printf (psf, " Unknown chunk marker at position %D. Resynching.\n", psf_ftell (psf) - 8) ;
|
||||
psf_binheader_readf (psf, "j", -3) ;
|
||||
/* File is too messed up so we prevent editing in RDWR mode here. */
|
||||
parsestage |= HAVE_other ;
|
||||
break ;
|
||||
} ;
|
||||
psf_log_printf (psf, "*** Unknown chunk marker (%X) at position %D. Exiting parser.\n", marker, psf_ftell (psf) - 4) ;
|
||||
psf_log_printf (psf, "*** Unknown chunk marker (%X) at position %D. Exiting parser.\n", marker, psf_ftell (psf) - 8) ;
|
||||
done = SF_TRUE ;
|
||||
break ;
|
||||
} ; /* switch (marker) */
|
||||
@ -1363,6 +1366,7 @@ wav_subchunk_parse (SF_PRIVATE *psf, int chunk, unsigned length)
|
||||
case IPRD_MARKER :
|
||||
case ISBJ_MARKER :
|
||||
case ISRC_MARKER :
|
||||
case IAUT_MARKER :
|
||||
bytesread += psf_binheader_readf (psf, "4", &dword) ;
|
||||
dword += (dword & 1) ;
|
||||
if (dword >= SIGNED_SIZEOF (buffer))
|
||||
@ -1371,8 +1375,7 @@ wav_subchunk_parse (SF_PRIVATE *psf, int chunk, unsigned length)
|
||||
break ;
|
||||
} ;
|
||||
|
||||
psf_binheader_readf (psf, "b", buffer, dword) ;
|
||||
bytesread += dword ;
|
||||
bytesread += psf_binheader_readf (psf, "b", buffer, dword) ;
|
||||
buffer [dword] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", chunk, buffer) ;
|
||||
break ;
|
||||
|
Loading…
Reference in New Issue
Block a user