Allow files opened in RDWR mode with string data in the tailer to be extended.

This commit is contained in:
Erik de Castro Lopo 2012-01-20 20:11:25 +11:00
parent ecf7c5dd5c
commit 4ee03c75e7
3 changed files with 59 additions and 31 deletions

View File

@ -1,3 +1,9 @@
2012-01-20 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/sndfile.c src/wav.c
Allow files opened in RDWR mode with string data in the tailer to be
extended. Thanks to Bodo for the patch.
2012-01-09 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/aiff.c

View File

@ -1882,12 +1882,14 @@ sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t len)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count ;
} /* sf_write_raw */
@ -1930,12 +1932,14 @@ sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t len)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count ;
} /* sf_write_short */
@ -1970,12 +1974,14 @@ sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count / psf->sf.channels ;
} /* sf_writef_short */
@ -2018,12 +2024,14 @@ sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t len)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count ;
} /* sf_write_int */
@ -2058,12 +2066,14 @@ sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count / psf->sf.channels ;
} /* sf_writef_int */
@ -2106,12 +2116,14 @@ sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t len)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count ;
} /* sf_write_float */
@ -2146,12 +2158,14 @@ sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count / psf->sf.channels ;
} /* sf_writef_float */
@ -2194,12 +2208,14 @@ sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t len)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count ;
} /* sf_write_double */
@ -2234,12 +2250,14 @@ sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames)
psf->last_op = SFM_WRITE ;
if (psf->write_current > psf->sf.frames)
{ psf->sf.frames = psf->write_current ;
psf->dataend = 0 ;
} ;
if (psf->auto_header && psf->write_header != NULL)
psf->write_header (psf, SF_TRUE) ;
if (psf->write_current > psf->sf.frames)
psf->sf.frames = psf->write_current ;
return count / psf->sf.channels ;
} /* sf_writef_double */

View File

@ -1021,9 +1021,8 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
if (psf->dataend)
psf->datalength -= psf->filelength - psf->dataend ;
if (psf->bytewidth > 0)
psf->sf.frames = psf->datalength / (psf->bytewidth * psf->sf.channels) ;
else if (psf->bytewidth > 0 && psf->sf.seekable == SF_TRUE)
psf->datalength = psf->sf.frames * psf->bytewidth * psf->sf.channels ;
} ;
/* Reset the current header length to zero. */
@ -1094,7 +1093,7 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
{ int type ;
type = psf->instrument->loops [tmp].mode ;
type = (type == SF_LOOP_FORWARD ? 0 : type==SF_LOOP_BACKWARD ? 2 : type == SF_LOOP_ALTERNATING ? 1 : 32) ;
type = (type == SF_LOOP_FORWARD ? 0 : type == SF_LOOP_BACKWARD ? 2 : type == SF_LOOP_ALTERNATING ? 1 : 32) ;
psf_binheader_writef (psf, "44", tmp, type) ;
psf_binheader_writef (psf, "44", psf->instrument->loops [tmp].start, psf->instrument->loops [tmp].end - 1) ;
@ -1141,6 +1140,11 @@ wav_write_tailer (SF_PRIVATE *psf)
psf->header [0] = 0 ;
psf->headindex = 0 ;
if (psf->bytewidth > 0 && psf->sf.seekable == SF_TRUE)
{ psf->datalength = psf->sf.frames * psf->bytewidth * psf->sf.channels ;
psf->dataend = psf->dataoffset + psf->datalength ;
} ;
if (psf->dataend > 0)
psf_fseek (psf, psf->dataend, SEEK_SET) ;
else