Commit 2969baca authored by Jan Kiene's avatar Jan Kiene
Browse files

refactor

parent 06809cf5
Loading
Loading
Loading
Loading
+33 −17
Original line number Diff line number Diff line
import pytest
from . import get_testvector_for_exp_cat_and_testset, get_out_bitstream_and_synthesis_name, apply_error_pattern_on_bitstream, get_error_pattern_for_exp_cat_and_testset, is_be_to_reference

P800_CATEGORIES = range(1, 3)

P800_1_BITRATES = [13200, 16400, 24400, 32000, 48000, 13200, 16400, 24400, 32000, 48000, 24400, 13200]
P800_1_DTX = 10 * [False] +  2 * [True]
P800_1_FER = 5 * [False] + 5 * [True] + [False, True]
# TODO: use correct range
P800_1_CATEGORIES = range(1, 3)
P800_1_TESTSETS = ["a", "d"]
P800_1_PARAMS = list(zip(P800_1_BITRATES, P800_1_DTX, P800_1_FER))
P800_1_PARAMS = zip(P800_1_BITRATES, P800_1_DTX, P800_1_FER)

P800_2_BITRATES = [13200, 16400, 24400, 32000, 48000, 64000, 13200, 16400, 24400, 32000, 48000]
P800_2_DTX = 6 * [False] + 5 * [False]
P800_2_TESTSETS = ["b", "d"]
P800_2_PARAMS = list(zip(P800_2_BITRATES, P800_2_DTX))

@pytest.mark.create_ref
@pytest.mark.parametrize("bitrate,dtx,fer", P800_1_PARAMS)
@pytest.mark.parametrize("category", P800_1_CATEGORIES)
@pytest.mark.parametrize("testset", P800_1_TESTSETS)
def test_p800_1(bitrate, dtx, fer, category, testset, dut_encoder_frontend, dut_decoder_frontend, update_ref):
OUTPUT_MODES_AND_OPTIONS_FOR_EXPERIMENT = {
    "P800-1": ("STEREO", ["-stereo"]),
    "P800-2": ("STEREO", ["-stereo"]),
}


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

    testv = get_testvector_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

    testv = get_testvector_for_exp_cat_and_testset("P800-1", category, testset)
    dut_bitstream, dut_output = get_out_bitstream_and_synthesis_name(testv, bitrate, dtx, fer)
    dut_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 update_ref != 1 and not is_be_to_reference(dut_bitstream):
    if not is_ref_creation and not is_be_to_reference(dut_bitstream):
        pytest.fail("Bitstream file differs from reference")

    if fer:
        error_pattern = get_error_pattern_for_exp_cat_and_testset("P800-1", category, testset)
    if error_pattern is not None:
        apply_error_pattern_on_bitstream(dut_bitstream, error_pattern, dut_bitstream)

    dut_decoder_frontend.run(output_mode, sampling_rate, dut_bitstream, dut_output)
    decoder_frontend.run(output_mode, sampling_rate, dut_bitstream, dut_output)

    # TODO: also compare metadata if present
    if update_ref != 1 and not is_be_to_reference(dut_output):
    if not is_ref_creation and not is_be_to_reference(dut_output):
        pytest.fail("Decoder output differs from reference")


@pytest.mark.create_ref
@pytest.mark.parametrize("bitrate,dtx,fer", P800_1_PARAMS)
@pytest.mark.parametrize("category", P800_CATEGORIES)
@pytest.mark.parametrize("testset", P800_1_TESTSETS)
def test_p800_1(bitrate, dtx, fer, category, testset, dut_encoder_frontend, dut_decoder_frontend, update_ref):
    experiment = "P800-1"
    run_check(experiment, category, testset, bitrate, dtx, fer, dut_encoder_frontend, dut_decoder_frontend, update_ref == 1)
 No newline at end of file