diff options
author | japm48 <japm48@users.noreply.github.com> | 2020-04-01 03:26:52 +0200 |
---|---|---|
committer | Michael Dickens <michael.dickens@ettus.com> | 2020-04-14 15:47:29 -0400 |
commit | d0a351a6fc2f018f36f6e89395f346707a059099 (patch) | |
tree | b5a2389eeee92a5441a31597ecd6b45fcee9baff /gr-blocks/python | |
parent | c1a91d140919518de18eda1fd5b598b2c11ef0cd (diff) |
blocks: fix wavfile test
The example test_16bit_1chunk.wav was invalid even if the tests passed.
This file caused errors in ffprobe (from ffmpeg) and wave (from python
standard lib).
This is what changed:
- LIST chunk corrected, according to spec. Previously `ffprobe` complained:
[wav @ 0x5653f92d6dc0] too short LIST tag
- File size corrected. Previously the test assumed that the resulting
headers to be identical, this is now taken into account.
Because of this, python's `wave` did not work. This is added to the test.
Parser is updated to check file size.
- Tests that did not close opened files were corrected.
References:
[1] https://sites.google.com/site/musicgapi/technical-documents/wav-file-format
[2] http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf
Diffstat (limited to 'gr-blocks/python')
-rw-r--r-- | gr-blocks/python/blocks/qa_wavfile.py | 32 | ||||
-rw-r--r-- | gr-blocks/python/blocks/test_16bit_1chunk.wav | bin | 70 -> 74 bytes |
2 files changed, 23 insertions, 9 deletions
diff --git a/gr-blocks/python/blocks/qa_wavfile.py b/gr-blocks/python/blocks/qa_wavfile.py index ecfa3a4c27..ba2d80dc66 100644 --- a/gr-blocks/python/blocks/qa_wavfile.py +++ b/gr-blocks/python/blocks/qa_wavfile.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2008,2010,2013 Free Software Foundation, Inc. +# Copyright 2008,2010,2013,2020 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -16,7 +16,7 @@ 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 +g_extra_header_len = 22 class test_wavefile(gr_unittest.TestCase): @@ -43,19 +43,33 @@ class test_wavefile(gr_unittest.TestCase): self.tb.run() wf_out.close() + # Test file validity. + import wave + try: + with wave.open(infile, 'rb') as f: + pass + with wave.open(outfile, 'rb') as f: + pass + except: + raise AssertionError('Invalid WAV file') + # we're losing all extra header chunks self.assertEqual(getsize(infile) - g_extra_header_len, getsize(outfile)) - in_f = open(infile, 'rb') - out_f = open(outfile, 'rb') + with open(infile, 'rb') as f: + in_data = bytearray(f.read()) + with open(outfile, 'rb') as f: + out_data = bytearray(f.read()) - in_data = in_f.read() - out_data = out_f.read() - out_f.close() os.remove(outfile) - # cut extra header chunks input file + + # Ignore size field: + in_data[4:8] = b'\x00\x00\x00\x00' + out_data[4:8] = b'\x00\x00\x00\x00' + + # cut extra header chunks from 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") + gr_unittest.run(test_wavefile) diff --git a/gr-blocks/python/blocks/test_16bit_1chunk.wav b/gr-blocks/python/blocks/test_16bit_1chunk.wav Binary files differindex d1b5ba91bd..3d028a9582 100644 --- a/gr-blocks/python/blocks/test_16bit_1chunk.wav +++ b/gr-blocks/python/blocks/test_16bit_1chunk.wav |