diff --git a/scripts/pyaudio3dtools/audioarray.py b/scripts/pyaudio3dtools/audioarray.py index 06c3d42171390c1a7fe39618fe7a230389b53ddf..ab6f3cb66515a7f6c08014e30600ebee2eddc223 100644 --- a/scripts/pyaudio3dtools/audioarray.py +++ b/scripts/pyaudio3dtools/audioarray.py @@ -239,6 +239,8 @@ def compare( ssnr_thresh_high: float = np.inf, apply_thresholds_to_ref_only: bool = False, test_start_offset_ms: int = 0, + ref_jbm_tf: Optional[Path] = None, + test_jbm_tf: Optional[Path] = None, ) -> dict: """Compare two audio arrays @@ -284,7 +286,11 @@ def compare( test = test[test_start_offset_samples:, :] framesize = fs // 50 - diff = abs(test - ref) + if ref.shape[0] != test.shape[0]: + min_len = min(ref.shape[0], test.shape[0]) + diff = abs(test[:min_len, :] - ref[:min_len, :]) + else: + diff = abs(test - ref) max_diff = int(diff.max()) result = { "bitexact": True, @@ -355,37 +361,74 @@ def compare( result["nframes_diff_percentage"] = nframes_diff_percentage if get_mld: + + def parse_wav_diff(proc: subprocess.CompletedProcess) -> float: + line = proc.stdout.splitlines()[-1].strip() + start = line.find(">") + 1 + stop = line.rfind("<") + mld = float(line[start:stop].strip()) + + return mld + + # TODO probably needs a fix to show up in pytest + if proc.returncode: + print(f"{proc.stderr}\n{proc.stdout}") + return mld_max + mld_max = 0 toolsdir = Path(__file__).parent.parent.joinpath("tools") - + curr_platform = platform.system() if curr_platform not in {"Windows", "Linux", "Darwin"}: - raise NotImplementedError(f"MLD tool not available for {curr_platform}") + raise NotImplementedError( + f"wav-diff tool not available for {curr_platform}" + ) search_path = toolsdir.joinpath(curr_platform.replace("Windows", "Win32")) - mld = search_path.joinpath("mld") + wdiff = search_path.joinpath("wav-diff") - if not mld.exists(): - mld = shutil.which("mld") - if mld is None: - raise FileNotFoundError(f"MLD tool not found in {search_path} or PATH!") - warnings.warn(f"MLD binary not found in {search_path}! Falling back to {mld}!") + if not wdiff.exists(): + wdiff = shutil.which("wav-diff") + if wdiff is None: + raise FileNotFoundError( + f"wav-diff tool not found in {search_path} or PATH!" + ) with tempfile.TemporaryDirectory() as tmpdir: - for i in range(nchannels): - tmpfile_ref = Path(tmpdir).joinpath(f"ref_ch{i+1}.wav") - tmpfile_test = Path(tmpdir).joinpath(f"test_ch{i+1}.wav") - r48 = np.clip( - resample(ref[:, i].astype(float), fs, 48000), -32768, 32767 - ).astype( - np.int16 - ) # Convert to float for resample, then to int16 for wavfile.write - t48 = np.clip( - resample(test[:, i].astype(float), fs, 48000), -32768, 32767 - ).astype(np.int16) - wavfile.write(str(tmpfile_ref), 48000, r48) - wavfile.write(str(tmpfile_test), 48000, t48) - out = subprocess.check_output([mld, tmpfile_ref, tmpfile_test]) - mld_max = max(mld_max, float(out.split()[3])) + tmpfile_ref = Path(tmpdir).joinpath("ref.wav") + tmpfile_test = Path(tmpdir).joinpath("test.wav") + + ### need to resample to 48kHz for MLD computation to be correct + if fs != 48000: + ref_tmp = np.clip( + resample(ref.astype(float), fs, 48000), -32768, 32767 + ) + test_tmp = np.clip( + resample(test.astype(float), fs, 48000), -32768, 32767 + ) + else: + ref_tmp = ref.copy() + test_tmp = test.copy() + + wavfile.write(str(tmpfile_ref), fs, ref_tmp.astype(np.int16)) + wavfile.write(str(tmpfile_test), fs, test_tmp.astype(np.int16)) + + cmd = [ + str(wdiff), + "--print-ctest-measurement", + str(tmpfile_ref), + str(tmpfile_test), + ] + if ref_jbm_tf and test_jbm_tf: + cmd.extend( + [ + "--ref-jbm-trace", + str(ref_jbm_tf), + "--cut-jbm-trace", + str(test_jbm_tf), + ] + ) + proc = subprocess.run(cmd, capture_output=True, text=True) + mld_max = parse_wav_diff(proc) result["MLD"] = mld_max diff --git a/scripts/tools/Darwin/LICENSE_wav-diff.txt b/scripts/tools/Darwin/LICENSE_wav-diff.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a8ff77f25e4117b972b6c644b3595584b99e9e0 --- /dev/null +++ b/scripts/tools/Darwin/LICENSE_wav-diff.txt @@ -0,0 +1,31 @@ +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ \ No newline at end of file diff --git a/scripts/tools/Darwin/thirdPartyLegalnotices/licenses_wav-diff.html b/scripts/tools/Darwin/thirdPartyLegalnotices/licenses_wav-diff.html new file mode 100644 index 0000000000000000000000000000000000000000..1bdee68950575ca1db5c3b71da74ad7986efc1a7 --- /dev/null +++ b/scripts/tools/Darwin/thirdPartyLegalnotices/licenses_wav-diff.html @@ -0,0 +1,1817 @@ + + + + + + + +
+
+

Third Party Licenses

+

This page lists the licenses of the projects used in wav-diff.

+
+ +

Overview of licenses:

+ + +

All license text:

+ +
+ + + diff --git a/scripts/tools/Darwin/wav-diff b/scripts/tools/Darwin/wav-diff new file mode 100755 index 0000000000000000000000000000000000000000..88823c01f9b11a117cee9a8447b8a981bb4ad5a5 Binary files /dev/null and b/scripts/tools/Darwin/wav-diff differ diff --git a/scripts/tools/Linux/LICENSE_wav-diff.txt b/scripts/tools/Linux/LICENSE_wav-diff.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a8ff77f25e4117b972b6c644b3595584b99e9e0 --- /dev/null +++ b/scripts/tools/Linux/LICENSE_wav-diff.txt @@ -0,0 +1,31 @@ +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ \ No newline at end of file diff --git a/scripts/tools/Linux/thirdPartyLegalnotices/licenses_wav-diff.html b/scripts/tools/Linux/thirdPartyLegalnotices/licenses_wav-diff.html new file mode 100644 index 0000000000000000000000000000000000000000..1bdee68950575ca1db5c3b71da74ad7986efc1a7 --- /dev/null +++ b/scripts/tools/Linux/thirdPartyLegalnotices/licenses_wav-diff.html @@ -0,0 +1,1817 @@ + + + + + + + +
+
+

Third Party Licenses

+

This page lists the licenses of the projects used in wav-diff.

+
+ +

Overview of licenses:

+ + +

All license text:

+ +
+ + + diff --git a/scripts/tools/Linux/wav-diff b/scripts/tools/Linux/wav-diff new file mode 100755 index 0000000000000000000000000000000000000000..47f77e82b56e51b84bc52ab7fb01d605d6265ab6 Binary files /dev/null and b/scripts/tools/Linux/wav-diff differ diff --git a/scripts/tools/Win32/LICENSE_wav-diff.txt b/scripts/tools/Win32/LICENSE_wav-diff.txt new file mode 100644 index 0000000000000000000000000000000000000000..8a8ff77f25e4117b972b6c644b3595584b99e9e0 --- /dev/null +++ b/scripts/tools/Win32/LICENSE_wav-diff.txt @@ -0,0 +1,31 @@ +/****************************************************************************************************** + + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. + +*******************************************************************************************************/ \ No newline at end of file diff --git a/scripts/tools/Win32/thirdPartyLegalnotices/licenses_wav-diff.html b/scripts/tools/Win32/thirdPartyLegalnotices/licenses_wav-diff.html new file mode 100644 index 0000000000000000000000000000000000000000..1bdee68950575ca1db5c3b71da74ad7986efc1a7 --- /dev/null +++ b/scripts/tools/Win32/thirdPartyLegalnotices/licenses_wav-diff.html @@ -0,0 +1,1817 @@ + + + + + + + +
+
+

Third Party Licenses

+

This page lists the licenses of the projects used in wav-diff.

+
+ +

Overview of licenses:

+ + +

All license text:

+ +
+ + + diff --git a/scripts/tools/Win32/wav-diff.exe b/scripts/tools/Win32/wav-diff.exe new file mode 100644 index 0000000000000000000000000000000000000000..b87b0888e4da8b559be017c4fb8c15e62152b1cb --- /dev/null +++ b/scripts/tools/Win32/wav-diff.exe @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:92c49557ce750bd1eb05278ced4a64b98d66a654f3604b8003f72f4a05df8df3 +size 889344 diff --git a/tests/cmp_pcm.py b/tests/cmp_pcm.py index 5b335840e6634ed3286c4fe0ecc99eaa2bad3302..67aeff0dd96ac91c2a2241972a37e9db1a0e2b6a 100755 --- a/tests/cmp_pcm.py +++ b/tests/cmp_pcm.py @@ -29,6 +29,8 @@ def cmp_pcm( abs_tol=0, get_ssnr=False, get_odg=False, + ref_jbm_tf: Optional[Path] = None, + cut_jbm_tf: Optional[Path] = None, ) -> (int, str): """ Compare 2 PCM files for bitexactness @@ -57,12 +59,7 @@ def cmp_pcm( # In case of wav input, override the nchannels with the one from the wav header nchannels = s1.shape[1] - if allow_differing_lengths: - # to allow for MLD comparison, shorten longer file - min_len = min(s1.shape[0], s2.shape[0]) - s1 = s1[:min_len, :] - s2 = s2[:min_len, :] - elif s1.shape != s2.shape: + if s1.shape != s2.shape and not allow_differing_lengths: print( f"file size in samples: file 1 = {s1.shape[0]},", f"file 2 = {s2.shape[0]}", @@ -81,6 +78,8 @@ def cmp_pcm( get_mld=get_mld, get_ssnr=get_ssnr, ssnr_thresh_low=-50, + ref_jbm_tf=ref_jbm_tf, + test_jbm_tf=cut_jbm_tf, ) output_differs = 0 diff --git a/tests/codec_be_on_mr_nonselection/test_param_file.py b/tests/codec_be_on_mr_nonselection/test_param_file.py index 9a11b4d6d42be2e143e56dfa2bef0b9b84963640..34bffea7b60bbffee745bf81c21993ff92032dc6 100644 --- a/tests/codec_be_on_mr_nonselection/test_param_file.py +++ b/tests/codec_be_on_mr_nonselection/test_param_file.py @@ -390,6 +390,9 @@ def test_param_file_tests( ref_tracefile_dec, delimiter=";", usecols=[0] )[-1] tracefile_last_rtp_numbers_differ = dut_rtp_num_last != ref_rtp_num_last + else: + dut_tracefile_dec = None + ref_tracefile_dec = None # same sequence number -> likely no crash, assume length difference is due to difference in TSM # to get MLD and abs diff values for now - even though they might be meaningless due to @@ -408,6 +411,8 @@ def test_param_file_tests( allow_differing_lengths=allow_differing_lengths, get_ssnr=get_ssnr, get_odg=get_odg, + ref_jbm_tf=ref_tracefile_dec, + cut_jbm_tf=dut_tracefile_dec, ) md_out_files = get_expected_md_files(ref_output_file, enc_split, output_config)