From 53c996b794474a58c7d594b287ed27365a39150c Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Thu, 21 Jul 2005 09:33:58 +0000 Subject: [PATCH] Move peak_loc field of SF_PRIVATE struct to PEAK_CHUNK struct. --- ChangeLog | 13 +++++++++++++ src/aiff.c | 6 +++--- src/caf.c | 4 ++-- src/common.h | 5 +++-- src/wav.c | 10 +++++----- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index e23907d9..a78f8c25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-07-21 Erik de Castro Lopo + + * src/common.h + Move the peak_loc field of SF_PRIVATE to the PEAK_CHUNK struct. + + * src/aiff.c src/caf.c src/wav.c + Fix knock on effects from above. + +2005-07-19 Erik de Castro Lopo + + * src/wav.c + Prevent files with unknown chunks from being opened read/write. + 2005-07-14 Erik de Castro Lopo * src/flac.c diff --git a/src/aiff.c b/src/aiff.c index 3a58260c..5387f64f 100644 --- a/src/aiff.c +++ b/src/aiff.c @@ -215,7 +215,7 @@ aiff_open (SF_PRIVATE *psf) if (psf->pchunk == NULL) return SFE_MALLOC_FAILED ; psf->has_peak = SF_TRUE ; - psf->peak_loc = SF_PEAK_START ; + psf->pchunk->peak_loc = SF_PEAK_START ; } ; if (psf->mode != SFM_RDWR || psf->filelength < 40) @@ -1066,7 +1066,7 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length) if (psf->str_flags & SF_STR_LOCATE_START) aiff_write_strings (psf, SF_STR_LOCATE_START) ; - if (psf->has_peak && psf->peak_loc == SF_PEAK_START) + if (psf->has_peak && psf->pchunk->peak_loc == SF_PEAK_START) { psf_binheader_writef (psf, "Em4", PEAK_MARKER, sizeof (PEAK_CHUNK) + psf->sf.channels * sizeof (PEAK_POS)) ; psf_binheader_writef (psf, "E44", 1, time (NULL)) ; @@ -1103,7 +1103,7 @@ aiff_write_tailer (SF_PRIVATE *psf) psf->dataend = psf_fseek (psf, 0, SEEK_END) ; - if (psf->has_peak && psf->peak_loc == SF_PEAK_END) + if (psf->has_peak && psf->pchunk->peak_loc == SF_PEAK_END) { psf_binheader_writef (psf, "Em4", PEAK_MARKER, sizeof (PEAK_CHUNK) + psf->sf.channels * sizeof (PEAK_POS)) ; psf_binheader_writef (psf, "E44", 1, time (NULL)) ; diff --git a/src/caf.c b/src/caf.c index 338d1748..b2e4b8b8 100644 --- a/src/caf.c +++ b/src/caf.c @@ -130,7 +130,7 @@ caf_open (SF_PRIVATE *psf) if (psf->pchunk == NULL) return SFE_MALLOC_FAILED ; psf->has_peak = SF_TRUE ; - psf->peak_loc = SF_PEAK_START ; + psf->pchunk->peak_loc = SF_PEAK_START ; } ; if ((error = caf_write_header (psf, SF_FALSE)) != 0) @@ -504,7 +504,7 @@ caf_write_header (SF_PRIVATE *psf, int calc_length) if (psf->str_flags & SF_STR_LOCATE_START) caf_write_strings (psf, SF_STR_LOCATE_START) ; - if (psf->has_peak && psf->peak_loc == SF_PEAK_START) + if (psf->has_peak && psf->pchunk->peak_loc == SF_PEAK_START) { psf_binheader_writef (psf, "em4", PEAK_MARKER, sizeof (PEAK_CHUNK) + psf->sf.channels * sizeof (PEAK_POS)) ; psf_binheader_writef (psf, "e44", 1, time (NULL)) ; diff --git a/src/common.h b/src/common.h index 3979318c..7ad77c5f 100644 --- a/src/common.h +++ b/src/common.h @@ -136,7 +136,9 @@ typedef struct } PEAK_POS ; typedef struct -{ unsigned int version ; /* version of the PEAK chunk */ +{ int peak_loc ; /* Write a PEAK chunk at the start or end of the file? */ + + unsigned int version ; /* version of the PEAK chunk */ unsigned int timestamp ; /* secs since 1/1/1970 */ #if HAVE_FLEXIBLE_ARRAY /* the per channel peak info */ @@ -240,7 +242,6 @@ typedef struct sf_private_tag int have_written ; /* Has a single write been done to the file? */ int has_peak ; /* Has a PEAK chunk (AIFF and WAVE) been read? */ - int peak_loc ; /* Write a PEAK chunk at the start or end of the file? */ PEAK_CHUNK *pchunk ; /* Loop Info */ diff --git a/src/wav.c b/src/wav.c index 825f2bba..04316aee 100644 --- a/src/wav.c +++ b/src/wav.c @@ -190,7 +190,7 @@ wav_open (SF_PRIVATE *psf) if (psf->pchunk == NULL) return SFE_MALLOC_FAILED ; psf->has_peak = SF_TRUE ; - psf->peak_loc = SF_PEAK_START ; + psf->pchunk->peak_loc = SF_PEAK_START ; } ; psf->write_header = (format == SF_FORMAT_WAV) ? wav_write_header : wavex_write_header ; @@ -424,7 +424,7 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock) } ; psf->has_peak = SF_TRUE ; /* Found PEAK chunk. */ - psf->peak_loc = ((parsestage & HAVE_data) == 0) ? SF_PEAK_START : SF_PEAK_END ; + psf->pchunk->peak_loc = ((parsestage & HAVE_data) == 0) ? SF_PEAK_START : SF_PEAK_END ; break ; case cue_MARKER : @@ -792,7 +792,7 @@ wav_write_header (SF_PRIVATE *psf, int calc_length) if (psf->str_flags & SF_STR_LOCATE_START) wav_write_strings (psf, SF_STR_LOCATE_START) ; - if (psf->has_peak && psf->peak_loc == SF_PEAK_START) + if (psf->has_peak && psf->pchunk->peak_loc == SF_PEAK_START) { psf_binheader_writef (psf, "em4", PEAK_MARKER, sizeof (PEAK_CHUNK) + psf->sf.channels * sizeof (PEAK_POS)) ; psf_binheader_writef (psf, "e44", 1, time (NULL)) ; @@ -969,7 +969,7 @@ wavex_write_header (SF_PRIVATE *psf, int calc_length) if (psf->str_flags & SF_STR_LOCATE_START) wav_write_strings (psf, SF_STR_LOCATE_START) ; - if (psf->has_peak && psf->peak_loc == SF_PEAK_START) + if (psf->has_peak && psf->pchunk->peak_loc == SF_PEAK_START) { psf_binheader_writef (psf, "em4", PEAK_MARKER, sizeof (PEAK_CHUNK) + psf->sf.channels * sizeof (PEAK_POS)) ; psf_binheader_writef (psf, "e44", 1, time (NULL)) ; @@ -1005,7 +1005,7 @@ wav_write_tailer (SF_PRIVATE *psf) psf->dataend = psf_fseek (psf, 0, SEEK_END) ; /* Add a PEAK chunk if requested. */ - if (psf->has_peak && psf->peak_loc == SF_PEAK_END) + if (psf->has_peak && psf->pchunk->peak_loc == SF_PEAK_END) { psf_binheader_writef (psf, "em4", PEAK_MARKER, sizeof (PEAK_CHUNK) + psf->sf.channels * sizeof (PEAK_POS)) ; psf_binheader_writef (psf, "e44", 1, time (NULL)) ;