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

cleanup and formatting

parent 2b3ca2ea
Loading
Loading
Loading
Loading
+46 −10
Original line number Diff line number Diff line
@@ -18,12 +18,18 @@ ISM_NUM_FOR_EXP = {
}
MASA_TESTS = ("P800-8", "P800-9", "BS1534-7a", "BS1534-7a")


def get_testvectors_for_exp_cat_and_testset(experiment, category, testset):
    fname = f"{experiment}-cat{category}-{testset}-input.wav"
    signal = TESTV_PATH.joinpath(fname).absolute()

    # will be an empty list if not ISM experiment
    metadata = sorted([TESTV_PATH.joinpath(fname + f"{i}.csv") for i in range(ISM_NUM_FOR_EXP.get(experiment, 0))])
    metadata = sorted(
        [
            TESTV_PATH.joinpath(fname + f"{i}.csv")
            for i in range(ISM_NUM_FOR_EXP.get(experiment, 0))
        ]
    )
    if experiment in MASA_TESTS:
        metadata.append(TESTV_PATH.joinpath(fname + ".met"))

@@ -34,7 +40,10 @@ def get_out_bitstream_and_synthesis_name(input_signal, bitrate, dtx, fer):
    dtx_str = "DTXon" if dtx else "DTXoff"
    fer_str = "FER_5perc" if fer else "FER_0perc"
    suffix = [".192", ".wav"]
    return [DUT_PATH.joinpath(f"{input_signal.stem}-{bitrate}bps-{dtx_str}-{fer_str}{s}") for s in suffix]
    return [
        DUT_PATH.joinpath(f"{input_signal.stem}-{bitrate}bps-{dtx_str}-{fer_str}{s}")
        for s in suffix
    ]


def get_error_pattern_for_exp_cat_and_testset(experiment, category, testset):
@@ -42,7 +51,9 @@ def get_error_pattern_for_exp_cat_and_testset(experiment, category, testset):
    return ep_file


def apply_error_pattern_on_bitstream(in_bitstream: Path, error_pattern: Path, out_bitstream: Path):
def apply_error_pattern_on_bitstream(
    in_bitstream: Path, error_pattern: Path, out_bitstream: Path
):
    # temporary file only really needed if same name is given for in and out bs
    with tempfile.TemporaryDirectory() as tmpdir:
        if in_bitstream == out_bitstream:
@@ -61,16 +72,41 @@ def is_be_to_reference(dut_file: Path):
    return filecmp.cmp(ref_file, dut_file)


def run_check(experiment, category, testset, bitrate, dtx, fer, encoder_frontend, decoder_frontend, is_ref_creation):
def run_check(
    experiment,
    category,
    testset,
    bitrate,
    dtx,
    fer,
    encoder_frontend,
    decoder_frontend,
    is_ref_creation,
):
    sampling_rate = 48
    output_mode, options = OUTPUT_MODES_AND_OPTIONS_FOR_EXPERIMENT[experiment]

    testv, metadata = get_testvectors_for_exp_cat_and_testset(experiment, category, testset)
    error_pattern = get_error_pattern_for_exp_cat_and_testset(experiment, category, testset) if fer else None
    dut_bitstream, dut_output = get_out_bitstream_and_synthesis_name(testv, bitrate, dtx, fer)
    testv, metadata = get_testvectors_for_exp_cat_and_testset(
        experiment, category, testset
    )
    error_pattern = (
        get_error_pattern_for_exp_cat_and_testset(experiment, category, testset)
        if fer
        else None
    )
    dut_bitstream, dut_output = get_out_bitstream_and_synthesis_name(
        testv, bitrate, dtx, fer
    )

    options.extend(metadata)
    encoder_frontend.run(bitrate, sampling_rate, testv, dut_bitstream, dtx_mode=dtx, add_option_list=options)
    encoder_frontend.run(
        bitrate,
        sampling_rate,
        testv,
        dut_bitstream,
        dtx_mode=dtx,
        add_option_list=options,
    )

    if not is_ref_creation and not is_be_to_reference(dut_bitstream):
        pytest.fail("Bitstream file differs from reference")
+171 −83
Original line number Diff line number Diff line
from itertools import product
from typing import Union, List

def zip_with_check(*args):
    """
    Like normal zip, but raises error if given iterables have different lengths.
    Used here to avoid forgetting a bitrate or so.
    """
    lengths = [len(it) for it in args]
    assert len(set(lengths)) == 1

    return zip(*args)

def assemble_unified_params_for_experiment(experiment, params, testset):
    return [(experiment, *p, t) for p, t in product(params, testset)]


class ExperimentParams():
    def __init__(self, name: str, n_conditions: int, bitrates: List[int], testsets: List[str], dtx: Union[List[bool], bool] = False, fer: Union[List[bool], bool] = False):
class ExperimentParams:
    def __init__(
        self,
        name: str,
        n_conditions: int,
        bitrates: List[int],
        testsets: List[str],
        dtx: Union[List[bool], bool] = False,
        fer: Union[List[bool], bool] = False,
    ):
        dtx = n_conditions * [dtx] if isinstance(dtx, bool) else dtx
        fer = n_conditions * [fer] if isinstance(fer, bool) else fer
        assert len(bitrates) == n_conditions and len(testsets) == 2 and len(dtx) == n_conditions and len(fer) == n_conditions
        assert (
            len(bitrates) == n_conditions
            and len(testsets) == 2
            and len(dtx) == n_conditions
            and len(fer) == n_conditions
        )

        self.name = name
        self.bitrates = bitrates
@@ -38,154 +38,242 @@ EXPERIMENT_PARAMS = [
    ExperimentParams(
        name="P800-1",
        n_conditions=12,
        bitrates=[13200, 16400, 24400, 32000, 48000, 13200, 16400, 24400, 32000, 48000, 24400, 13200],
        bitrates=[
            13200,
            16400,
            24400,
            32000,
            48000,
            13200,
            16400,
            24400,
            32000,
            48000,
            24400,
            13200,
        ],
        dtx=10 * [False] + 2 * [True],
        fer=5 * [False] + 5 * [True] + [False, True],
        testsets=["a", "d"]
        testsets=["a", "d"],
    ),
    ExperimentParams(
        name="P800-2",
        n_conditions=11,
        bitrates=[13200, 16400, 24400, 32000, 48000, 64000, 13200, 16400, 24400, 32000, 48000],
        bitrates=[
            13200,
            16400,
            24400,
            32000,
            48000,
            64000,
            13200,
            16400,
            24400,
            32000,
            48000,
        ],
        dtx=6 * [False] + 5 * [True],
        testsets=["b", "d"]
        testsets=["b", "d"],
    ),
    ExperimentParams(
        name="P800-3",
        n_conditions=13,
        bitrates=[13200, 16400, 24400, 32000, 48000, 64000, 13200, 16400, 24400, 32000, 48000, 24400, 13200],
        bitrates=[
            13200,
            16400,
            24400,
            32000,
            48000,
            64000,
            13200,
            16400,
            24400,
            32000,
            48000,
            24400,
            13200,
        ],
        dtx=11 * [False] + 2 * [True],
        fer=6 * [False] + 5 * [True] + [False, True],
        testsets=["a", "d"]
        testsets=["a", "d"],
    ),
    ExperimentParams(
        name="P800-4",
        n_conditions=13,
        bitrates=[16400, 24400, 32000, 48000, 64000, 80000, 96000, 24400, 32000, 48000, 64000, 80000, 96000],
        bitrates=[
            16400,
            24400,
            32000,
            48000,
            64000,
            80000,
            96000,
            24400,
            32000,
            48000,
            64000,
            80000,
            96000,
        ],
        fer=7 * [False] + 6 * [True],
        testsets=["a", "c"]
        testsets=["a", "c"],
    ),
    ExperimentParams(
        name="P800-5",
        n_conditions=13,
        bitrates=[16400, 24400, 32000, 48000, 64000, 80000, 96000, 16400, 24400, 32000, 48000, 64000, 80000],
        bitrates=[
            16400,
            24400,
            32000,
            48000,
            64000,
            80000,
            96000,
            16400,
            24400,
            32000,
            48000,
            64000,
            80000,
        ],
        dtx=7 * [False] + 6 * [True],
        testsets=["a", "b"]
        testsets=["a", "b"],
    ),
    ExperimentParams(
        name="P800-6",
        n_conditions=13,
        bitrates=[13200, 16400, 24400, 32000, 48000, 64000, 13200, 16400, 24400, 32000, 13200, 16400, 24400],
        bitrates=[
            13200,
            16400,
            24400,
            32000,
            48000,
            64000,
            13200,
            16400,
            24400,
            32000,
            13200,
            16400,
            24400,
        ],
        dtx=10 * [False] + 3 * [True],
        fer=6 * [False] + 4 * [True] + 3 * [False],
        testsets=["a", "c"]
        testsets=["a", "c"],
    ),
    ExperimentParams(
        name="P800-7",
        n_conditions=13,
        bitrates=[16400, 24400, 32000, 48000, 64000, 16400, 24400, 32000, 48000, 16400, 24400, 32000, 48000],
        bitrates=[
            16400,
            24400,
            32000,
            48000,
            64000,
            16400,
            24400,
            32000,
            48000,
            16400,
            24400,
            32000,
            48000,
        ],
        dtx=9 * [False] + 4 * [True],
        fer=5 * [False] + 4 * [True] + 4 * [False],
        testsets=["a", "d"]
        testsets=["a", "d"],
    ),
    ExperimentParams(
        name="P800-8",
        n_conditions=12,
        bitrates=[13200, 16400, 24400, 32000, 48000, 64000, 80000, 13200, 16400, 24400, 48000, 64000],
        bitrates=[
            13200,
            16400,
            24400,
            32000,
            48000,
            64000,
            80000,
            13200,
            16400,
            24400,
            48000,
            64000,
        ],
        fer=7 * [False] + 5 * [True],
        testsets=["a", "b"]
        testsets=["a", "b"],
    ),
    ExperimentParams(
        name="P800-9",
        n_conditions=13,
        bitrates=[13200, 16400, 24400, 32000, 48000, 64000, 80000, 13200, 16400, 24400, 32000, 48000, 64000],
        bitrates=[
            13200,
            16400,
            24400,
            32000,
            48000,
            64000,
            80000,
            13200,
            16400,
            24400,
            32000,
            48000,
            64000,
        ],
        dtx=7 * [False] + 6 * [True],
        testsets=["a", "d"]
        testsets=["a", "d"],
    ),

    ExperimentParams(
        name="BS1534-1a",
        n_conditions=2,
        bitrates=[48000, 64000],
        testsets=["a", "d"]
        name="BS1534-1a", n_conditions=2, bitrates=[48000, 64000], testsets=["a", "d"]
    ),
    ExperimentParams(
        name="BS1534-1b",
        n_conditions=2,
        bitrates=[96000, 128000],
        testsets=["b", "d"]
        name="BS1534-1b", n_conditions=2, bitrates=[96000, 128000], testsets=["b", "d"]
    ),
    ExperimentParams(
        name="BS1534-2a",
        n_conditions=2,
        bitrates=[64000, 96000],
        testsets=["a", "b"]
        name="BS1534-2a", n_conditions=2, bitrates=[64000, 96000], testsets=["a", "b"]
    ),
    ExperimentParams(
        name="BS1534-2b",
        n_conditions=2,
        bitrates=[128000, 160000],
        testsets=["a", "b"]
        name="BS1534-2b", n_conditions=2, bitrates=[128000, 160000], testsets=["a", "b"]
    ),
    ExperimentParams(
        name="BS1534-3a",
        n_conditions=2,
        bitrates=[128000, 160000],
        testsets=["a", "b"]
        name="BS1534-3a", n_conditions=2, bitrates=[128000, 160000], testsets=["a", "b"]
    ),
    ExperimentParams(
        name="BS1534-3b",
        n_conditions=2,
        bitrates=[384000, 512000],
        testsets=["a", "b"]
        name="BS1534-3b", n_conditions=2, bitrates=[384000, 512000], testsets=["a", "b"]
    ),
    ExperimentParams(
        name="BS1534-4a",
        n_conditions=3,
        bitrates=[96000, 128000, 160000],
        testsets=["a", "d"]
        testsets=["a", "d"],
    ),
    ExperimentParams(
        name="BS1534-4b",
        n_conditions=2,
        bitrates=[160000, 192000],
        testsets=["b", "d"]
        name="BS1534-4b", n_conditions=2, bitrates=[160000, 192000], testsets=["b", "d"]
    ),
    ExperimentParams(
        name="BS1534-5a",
        n_conditions=2,
        bitrates=[192000, 256000],
        testsets=["a", "d"]
        name="BS1534-5a", n_conditions=2, bitrates=[192000, 256000], testsets=["a", "d"]
    ),
    ExperimentParams(
        name="BS1534-5b",
        n_conditions=2,
        bitrates=[384000, 512000],
        testsets=["a", "b"]
        name="BS1534-5b", n_conditions=2, bitrates=[384000, 512000], testsets=["a", "b"]
    ),
    ExperimentParams(
        name="BS1534-6a",
        n_conditions=3,
        bitrates=[48000, 64000, 96000],
        testsets=["b", "d"]
        testsets=["b", "d"],
    ),
    ExperimentParams(
        name="BS1534-6b",
        n_conditions=3,
        bitrates=[96000, 128000, 256000],
        testsets=["b", "d"]
        testsets=["b", "d"],
    ),
    ExperimentParams(
        name="BS1534-7a",
        n_conditions=2,
        bitrates=[96000, 128000],
        testsets=["b", "d"]
        name="BS1534-7a", n_conditions=2, bitrates=[96000, 128000], testsets=["b", "d"]
    ),
    ExperimentParams(
        name="BS1534-7b",
        n_conditions=2,
        bitrates=[192000, 256000],
        testsets=["b", "d"]
        name="BS1534-7b", n_conditions=2, bitrates=[192000, 256000], testsets=["b", "d"]
    ),
]

+26 −4
Original line number Diff line number Diff line
@@ -3,11 +3,33 @@ from . import run_check
from .constants import EXPERIMENT_PARAMS, P800_CATEGORIES


P800_PARAMS_UNIFIED = [i for sl in [p.assemble_unified_params() for p in EXPERIMENT_PARAMS] for i in sl]
TEST_PARAMS = [
    i for sl in [p.assemble_unified_params() for p in EXPERIMENT_PARAMS] for i in sl
]


@pytest.mark.create_ref
@pytest.mark.parametrize("experiment,bitrate,dtx,fer,testset", P800_PARAMS_UNIFIED)
@pytest.mark.parametrize("experiment,bitrate,dtx,fer,testset", TEST_PARAMS)
@pytest.mark.parametrize("category", P800_CATEGORIES)
def test_experiment(experiment, bitrate, dtx, fer, testset, category, dut_encoder_frontend, dut_decoder_frontend, update_ref):
    run_check(experiment, category, testset, bitrate, dtx, fer, dut_encoder_frontend, dut_decoder_frontend, update_ref == 1)
def test_experiment(
    experiment,
    bitrate,
    dtx,
    fer,
    testset,
    category,
    dut_encoder_frontend,
    dut_decoder_frontend,
    update_ref,
):
    run_check(
        experiment,
        category,
        testset,
        bitrate,
        dtx,
        fer,
        dut_encoder_frontend,
        dut_decoder_frontend,
        update_ref == 1,
    )