Commit 4be705f6 authored by Jan Kiene's avatar Jan Kiene
Browse files

move check for equality to the very top

parent 34c87d3f
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -352,7 +352,9 @@ def compare(
            )

        search_path = toolsdir.joinpath(curr_platform.replace("Windows", "Win32"))
        wdiff = search_path.joinpath("wav-diff").with_suffix(".exe" if curr_platform == "Windows" else "")
        wdiff = search_path.joinpath("wav-diff").with_suffix(
            ".exe" if curr_platform == "Windows" else ""
        )

        if not wdiff.exists():
            wdiff = shutil.which("wav-diff")
@@ -405,7 +407,6 @@ def compare(

        result["MLD"] = mld_max


    # Run remanining tests after checking if the lenght differs

    lengths_differ = ref.shape[0] != test.shape[0]
@@ -678,16 +679,21 @@ def ssnr(
    """
    Calculate Segmental SNR for test_sig to ref_sig as defined in ISO/IEC 14496-4
    """
    # check if diff of signal is zero already, then SNR is infinite, since no noise
    signals_equal = (ref_sig == test_sig).all()
    if signals_equal:
        return np.asarray([np.inf] * ref_sig.shape[1])

    ss = list()

    # allocation here
    ref_sig_norm = ref_sig / -np.iinfo(np.int16).min
    # allocation here
    test_sig_norm = test_sig / -np.iinfo(np.int16).min

    # check if diff of signal is zero already, then SNR is infinite, since no noise
    # allocation here
    diff_sig_norm = ref_sig_norm - test_sig_norm
    if np.all(diff_sig_norm == 0):
        return np.asarray([np.inf] * ref_sig_norm.shape[1])

    # allocation here
    channels_identical_idx = np.sum(np.abs(diff_sig_norm), axis=0) == 0

    denom_add = 10**-13 * len_seg