Commit 28a127e3 authored by Jan Kiene's avatar Jan Kiene
Browse files

make alignment check user-configurable in config

parent 1b63ada4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ input:
    fmt: "STEREO"
    # TODO: to be clarified in Test Plan
    fs: 48000
    aligned_to:
        len: 20

################################################
### Pre-processing on individual items
@@ -36,6 +38,8 @@ preprocessing_2:
    # concatenation_order: []
    preamble: 10000
    preamble_noise: true
    postamble: 10000
    postamble_noise: true
    repeat_signal: true
    background_noise:
        ### REQUIRED: SNR for background noise in dB
+11 −11
Original line number Diff line number Diff line
@@ -523,7 +523,7 @@ def validate_input_files(cfg: TestConfig):
    """
    input_format = cfg.input["fmt"]
    num_chan_expected = audio.fromtype(input_format).num_channels
    check_block_aligned_to = 20

    for item in cfg.items_list:
        if "fs" in cfg.input:
            sampling_rate = cfg.input["fs"]
@@ -547,14 +547,14 @@ def validate_input_files(cfg: TestConfig):
                f"The number of channels in the file ({n_chan_x}) do NOT match with those of format ({num_chan_expected}, {input_format}) specified in the config yaml."
            )

        if check_block_aligned_to > 0:
            frame_length_samples = (check_block_aligned_to / 1000) * fs
            if n_samples_x % frame_length_samples != 0:
                if input_format.startswith("ISM") or input_format.startswith("MASA"):
                    raise ValueError(
                        f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms) - not allowed for input formats with metadata."
                    )
        if (input_aligned_cfg := cfg.input.get("aligned_to", None)) is not None:
            input_fmt_has_metadata = input_format.startswith("ISM") or input_format.startswith("MASA")
            force_alignment = input_aligned_cfg.get("force", False) or input_fmt_has_metadata

            alignment_len_samples = (input_aligned_cfg["len"] / 1000) * fs
            if n_samples_x % alignment_len_samples != 0:
                msg = f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of given alignment length ({input_aligned_cfg['len']} ms)."
                if force_alignment:
                    raise ValueError(msg)
                else:
                    warn(
                        f"The length ({n_samples_x} samples) of audio ({item.name}) is not a multiple of frame length (20 ms)."
                    )
                    warn(msg)