Commit d6fcf004 authored by Jan Kiene's avatar Jan Kiene
Browse files

add printout of first diff pos in samples and frames

parent 015a779b
Loading
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -248,6 +248,9 @@ def compare(ref: np.ndarray, test: np.ndarray, fs: int, per_frame: bool=True) ->
        "max_abs_diff_pos_channel": 0,
        "nsamples_diff": 0,
        "nsamples_diff_percentage": 0.0,
        "first_diff_pos_sample": -1,
        "first_diff_pos_channel": -1,
        "first_diff_pos_frame": -1
    }
    if per_frame:
        result["max_abs_diff_pos_frame"] = 0
@@ -266,6 +269,14 @@ def compare(ref: np.ndarray, test: np.ndarray, fs: int, per_frame: bool=True) ->
            max_diff_pos[0][0] // framesize,
            max_diff_pos[1][0],
        ]
    
        first_diff_pos = np.nonzero(diff)
        first_diff_pos = [
            first_diff_pos[0][0],
            first_diff_pos[0][0] // framesize,
            first_diff_pos[1][0],
        ]

        nsamples_diff = np.nonzero(diff)[0].size
        nsamples_diff_percentage = nsamples_diff / (nsamples_total * nchannels) * 100.0
        nframes = nsamples_total // framesize
@@ -278,6 +289,9 @@ def compare(ref: np.ndarray, test: np.ndarray, fs: int, per_frame: bool=True) ->
            "max_abs_diff_pos_channel": max_diff_pos[2],
            "nsamples_diff": nsamples_diff,
            "nsamples_diff_percentage": nsamples_diff_percentage,
            "first_diff_pos_sample": first_diff_pos[0],
            "first_diff_pos_channel": first_diff_pos[2],
            "first_diff_pos_frame": first_diff_pos[1],
        }

        if per_frame:
+14 −2
Original line number Diff line number Diff line
@@ -22,7 +22,11 @@ def cmp_pcm(file1, file2, out_config, fs) -> (int, str):
    out_config = "MONO" if out_config == "" else out_config
    if out_config.upper() not in pyivastest.constants.OC_TO_NCHANNELS:
        out_config_in_file_names = os.path.splitext(os.path.basename(out_config))[0]
        nchannels = pyivastest.IvasScriptsCommon.IvasScript.get_n_channels_from_ls_layout(out_config)
        nchannels = (
            pyivastest.IvasScriptsCommon.IvasScript.get_n_channels_from_ls_layout(
                out_config
            )
        )
    else:
        out_config_in_file_names = out_config
        nchannels = pyivastest.constants.OC_TO_NCHANNELS[out_config.upper()]
@@ -43,7 +47,9 @@ def cmp_pcm(file1, file2, out_config, fs) -> (int, str):
        return 0, "SUCCESS: Files are bitexact"
    else:
        diff_msg = f"MAXIMUM ABS DIFF ==> {cmp_result['max_abs_diff']} at sample num {cmp_result['max_abs_diff_pos_sample']} (assuming {nchannels} channels)"
        first_msg = f"First diff found at sample num {cmp_result['first_diff_pos_sample']} in channel {cmp_result['first_diff_pos_channel']}, frame {cmp_result['first_diff_pos_frame']} (assuming {nchannels} channels, {fs} sampling rate)"
        print(diff_msg)
        print(first_msg)
        return 1, "FAIL: Files have different content"


@@ -51,7 +57,13 @@ if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("file1", type=str)
    parser.add_argument("file2", type=str)
    parser.add_argument("-o", "--out_config", type=str.upper, default="MONO", choices=pyivastest.constants.OC_TO_NCHANNELS.keys())
    parser.add_argument(
        "-o",
        "--out_config",
        type=str.upper,
        default="MONO",
        choices=pyivastest.constants.OC_TO_NCHANNELS.keys(),
    )
    parser.add_argument("-s", "--sampling_rate", type=int, default=48000, dest="fs")
    args = parser.parse_args()