src/wav.c: Fix WAV Sampler Chunk tune parsing 20/211320/1
authorMichael Panzlaff <michael.panzlaff@fau.de>
Sat, 28 Apr 2018 21:21:34 +0000 (23:21 +0200)
committerSeungbae Shin <seungbae.shin@samsung.com>
Thu, 1 Aug 2019 09:46:10 +0000 (18:46 +0900)
Fix parsing of instrument fine tuning instrument field. There is still
a possible rounding error involved which might require further
investigation at some stage.

Update the test as well.

Change-Id: I9c99c2707f75f52b55e1229e878aef5edc4b416e

src/wav.c
tests/command_test.c

index bade3fc..0f8d8e8 100644 (file)
--- a/src/wav.c
+++ b/src/wav.c
@@ -1227,7 +1227,7 @@ static int
 wav_read_smpl_chunk (SF_PRIVATE *psf, uint32_t chunklen)
 {      char buffer [512] ;
        uint32_t thisread, bytesread = 0, dword, sampler_data, loop_count ;
-       uint32_t note, start, end, type = -1, count ;
+       uint32_t note, pitch, start, end, type = -1, count ;
        int j, k ;
 
        chunklen += (chunklen & 1) ;
@@ -1244,10 +1244,10 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, uint32_t chunklen)
        bytesread += psf_binheader_readf (psf, "4", &note) ;
        psf_log_printf (psf, "  Midi Note    : %u\n", note) ;
 
-       bytesread += psf_binheader_readf (psf, "4", &dword) ;
-       if (dword != 0)
+       bytesread += psf_binheader_readf (psf, "4", &pitch) ;
+       if (pitch != 0)
        {       snprintf (buffer, sizeof (buffer), "%f",
-                                       (1.0 * 0x80000000) / ((uint32_t) dword)) ;
+                                       (1.0 * 0x80000000) / ((uint32_t) pitch)) ;
                psf_log_printf (psf, "  Pitch Fract. : %s\n", buffer) ;
                }
        else
@@ -1353,6 +1353,7 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, uint32_t chunklen)
                } ;
 
        psf->instrument->basenote = note ;
+       psf->instrument->detune = (int8_t)(pitch / (0x40000000 / 25.0) + 0.5) ;
        psf->instrument->gain = 1 ;
        psf->instrument->velocity_lo = psf->instrument->key_lo = 0 ;
        psf->instrument->velocity_hi = psf->instrument->key_hi = 127 ;
index 941e76b..bc6d70c 100644 (file)
@@ -766,7 +766,6 @@ instrument_test (const char *filename, int filetype)
                **      write_inst struct to hold the default value that the WAV
                **      module should hold.
                */
-               write_inst.detune = 0 ;
                write_inst.key_lo = write_inst.velocity_lo = 0 ;
                write_inst.key_hi = write_inst.velocity_hi = 127 ;
                write_inst.gain = 1 ;