diff options
Diffstat (limited to 'gr-blocks')
-rw-r--r-- | gr-blocks/lib/wavfile.cc | 22 | ||||
-rwxr-xr-x | gr-blocks/python/blocks/qa_wavfile.py | 10 | ||||
-rw-r--r-- | gr-blocks/python/blocks/test_16bit_1chunk.wav | bin | 52 -> 70 bytes |
3 files changed, 26 insertions, 6 deletions
diff --git a/gr-blocks/lib/wavfile.cc b/gr-blocks/lib/wavfile.cc index 0a4336f443..865082e05f 100644 --- a/gr-blocks/lib/wavfile.cc +++ b/gr-blocks/lib/wavfile.cc @@ -138,10 +138,26 @@ namespace gr { } } - // data chunk + // find data chunk fresult = fread(str_buf, 1, 4, fp); - if(strncmp(str_buf, "data", 4)) { - return false; + // keep parsing chunk until we hit the data chunk + while(fresult != 4 || strncmp(str_buf, "data", 4)) + { + // all good? + if(fresult != 4 || ferror(fp) || feof(fp)) { + return false; + } + // get chunk body size and skip + fresult = fread(&chunk_size, 1, 4, fp); + if(fresult != 4 || ferror(fp) || feof(fp)) { + return false; + } + chunk_size = wav_to_host(chunk_size); + if(fseek(fp, chunk_size, SEEK_CUR) != 0) { + return false; + } + // read next chunk type + fresult = fread(str_buf, 1, 4, fp); } fresult = fread(&chunk_size, 1, 4, fp); diff --git a/gr-blocks/python/blocks/qa_wavfile.py b/gr-blocks/python/blocks/qa_wavfile.py index ce1806c5ef..5c3a69e1d0 100755 --- a/gr-blocks/python/blocks/qa_wavfile.py +++ b/gr-blocks/python/blocks/qa_wavfile.py @@ -26,6 +26,8 @@ import os from os.path import getsize g_in_file = os.path.join(os.getenv("srcdir"), "test_16bit_1chunk.wav") +g_extra_header_offset = 36 +g_extra_header_len = 18 class test_wavefile(gr_unittest.TestCase): @@ -52,7 +54,8 @@ class test_wavefile(gr_unittest.TestCase): self.tb.run() wf_out.close() - self.assertEqual(getsize(infile), getsize(outfile)) + # we're loosing all extra header chunks + self.assertEqual(getsize(infile) - g_extra_header_len, getsize(outfile)) in_f = file(infile, 'rb') out_f = file(outfile, 'rb') @@ -61,8 +64,9 @@ class test_wavefile(gr_unittest.TestCase): out_data = out_f.read() out_f.close() os.remove(outfile) - - self.assertEqual(in_data, out_data) + # cut extra header chunks input file + self.assertEqual(in_data[:g_extra_header_offset] + \ + in_data[g_extra_header_offset + g_extra_header_len:], out_data) if __name__ == '__main__': gr_unittest.run(test_wavefile, "test_wavefile.xml") diff --git a/gr-blocks/python/blocks/test_16bit_1chunk.wav b/gr-blocks/python/blocks/test_16bit_1chunk.wav Binary files differindex 0fe12a7a13..d1b5ba91bd 100644 --- a/gr-blocks/python/blocks/test_16bit_1chunk.wav +++ b/gr-blocks/python/blocks/test_16bit_1chunk.wav |