From f4ee595dea15a2b96ac2eda6fef1e0d2521b7d9e Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Sat, 18 Mar 2006 10:20:48 +0000 Subject: [PATCH] Fix two INST related AIFF bugs. --- ChangeLog | 11 +++++++++++ src/aiff.c | 8 +++++--- src/sndfile.c | 3 +++ tests/command_test.c | 3 ++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5fa161b9..f71edea6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-03-18 Erik de Castro Lopo + + * src/aiff.c + Fix bug in writting of INST chunk in AIFF files. + + * src/sndfile.c + Make sure the instrument chunk can only be written at the start of the file. + + * tests/command_test.c + Add check of log buffer. + 2006-03-17 Erik de Castro Lopo * src/Makefile.am tests/Makefile.am diff --git a/src/aiff.c b/src/aiff.c index 24a6e318..fae8a829 100644 --- a/src/aiff.c +++ b/src/aiff.c @@ -1147,6 +1147,7 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length) unsigned short ct = 0 ; memset (m, 0, sizeof (m)) ; + memset (&ch, 0, sizeof (ch)) ; ch.baseNote = psf->instrument->basenote ; ch.detune = psf->instrument->detune ; @@ -1178,10 +1179,11 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length) ch.release_loop.beginLoop = 0 ; ch.release_loop.endLoop = 0 ; } ; - psf_binheader_writef (psf, "Em4b", INST_MARKER, sizeof (INST_CHUNK), &ch.baseNote, make_size_t (6)) ; + psf_binheader_writef (psf, "Em4111111", INST_MARKER, sizeof (INST_CHUNK), ch.baseNote, ch.detune, + ch.lowNote, ch.highNote, ch.lowVelocity, ch.highVelocity) ; psf_binheader_writef (psf, "2222222", ch.gain, ch.sustain_loop.playMode, - ch.sustain_loop.beginLoop, ch.sustain_loop.endLoop, ch.release_loop.playMode, - ch.release_loop.beginLoop, ch.release_loop.endLoop) ; + ch.sustain_loop.beginLoop, ch.sustain_loop.endLoop, ch.release_loop.playMode, + ch.release_loop.beginLoop, ch.release_loop.endLoop) ; if (ct == 2) psf_binheader_writef (psf, "Em42241b241b", diff --git a/src/sndfile.c b/src/sndfile.c index 40811c8e..63e49e8e 100644 --- a/src/sndfile.c +++ b/src/sndfile.c @@ -1061,6 +1061,9 @@ sf_command (SNDFILE *sndfile, int command, void *data, int datasize) return SF_TRUE ; case SFC_SET_INSTRUMENT : + /* If data has already been written this must fail. */ + if (psf->have_written) + return SF_FALSE ; if (datasize != sizeof (SF_INSTRUMENT) || data == NULL) return SF_FALSE ; if (psf->instrument == NULL && (psf->instrument = psf_instrument_alloc ()) == NULL) diff --git a/tests/command_test.c b/tests/command_test.c index 9fe6ecca..629f5040 100644 --- a/tests/command_test.c +++ b/tests/command_test.c @@ -622,11 +622,11 @@ instrument_test (const char *filename, int filetype) sfinfo.channels = 1 ; file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; - test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; if (sf_command (file, SFC_SET_INSTRUMENT, &write_inst, sizeof (write_inst)) == SF_FALSE) { printf ("\n\nLine %d : sf_command (SFC_SET_INSTRUMENT) failed.\n\n", __LINE__) ; exit (1) ; } ; + test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ; sf_close (file) ; memset (&read_inst, 0, sizeof (read_inst)) ; @@ -637,6 +637,7 @@ instrument_test (const char *filename, int filetype) exit (1) ; return ; } ; + check_log_buffer_or_die (file, __LINE__) ; sf_close (file) ; if ((filetype & SF_FORMAT_TYPEMASK) == SF_FORMAT_WAV)