Commit 154fd6c1 authored by Adam Mills's avatar Adam Mills
Browse files

Bad update

parent b49c8f8e
Loading
Loading
Loading
Loading
Loading
+113 −99
Original line number Diff line number Diff line
__copyright__ = \
    """
__copyright__ = """
    (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
@@ -29,8 +28,7 @@ __copyright__ = \
    the United Nations Convention on Contracts on the International Sales of Goods.
    """

__doc__ = \
    """
__doc__ = """
    Test file to run C encoder and decoder code.
    The outputs are compared with C generated references.
    """
@@ -43,28 +41,40 @@ from tests.cmp_pcm import cmp_pcm
from tests.cut_pcm import cut_samples
from tests.conftest import EncoderFrontend, DecoderFrontend
from cut_bs import cut_from_start

# params

tag_list = ['stvFOA']
tag_list_HOA2 = ['stv2OA']
tag_list_HOA3 = ['stv3OA']

tag_list_bw_force = ['stvFOA']
dtx_set = ['0', '1']
dict_fsample_bw = {'48': '3', '32': '2', '16': '1'}
dict_bw_idx = {'FB': '3', 'SWB': '2', 'WB': '1'}
dict_bw_tag = {'SWB': '_ForceSWB', 'WB': '_ForceWB'}
ivas_br_FOA = ['13200','16400','32000','64000', '96000', '160000', '256000', '384000', '512000','sw_24k4_256k.bin']
ivas_br_HOA2 = ['256000', '384000', '512000']
ivas_br_HOA3 = ['256000', '384000', '512000']
SID_list = [0, 1]
sample_rate_list = ['48', '32', '16']
tag_list = ["stvFOA"]
tag_list_HOA2 = ["stv2OA"]
tag_list_HOA3 = ["stv3OA"]

tag_list_bw_force = ["stvFOA"]
dtx_set = ["0", "1"]
dict_fsample_bw = {"48": "3", "32": "2", "16": "1"}
dict_bw_idx = {"FB": "3", "SWB": "2", "WB": "1"}
dict_bw_tag = {"SWB": "_ForceSWB", "WB": "_ForceWB"}
ivas_br_FOA = [
    "13200",
    "16400",
    "32000",
    "64000",
    "96000",
    "160000",
    "256000",
    "384000",
    "512000",
    "sw_24k4_256k.bin",
]
ivas_br_HOA2 = ["256000", "384000", "512000"]
ivas_br_HOA3 = ["256000", "384000", "512000"]

sample_rate_list = ["48", "32", "16"]
bypass_list = [1, 2]
gain_list = [0, 1]

sample_rate_bw_idx_list = [('48', 'SWB'), ('48', 'WB'), ('32', 'WB')]
sample_rate_bw_idx_list = [("48", "SWB"), ("48", "WB"), ("32", "WB")]

AbsTol = '0'
AbsTol = "0"


def check_and_makedir(dir_path):
@@ -86,8 +96,8 @@ def test_bypass_enc(
    test_vector_path,
    reference_path,
    dut_base_path,
    ref_encoder_path,
    ref_decoder_path,
    ref_encoder_frontend,
    ref_decoder_frontend,
    update_ref,
    keep_files,
    tag,
@@ -97,9 +107,9 @@ def test_bypass_enc(
    if update_ref == 1 and bypass == 1:
        pytest.skip()

    tag = tag + fs + 'c'
    ivas_br = '256000'
    dtx = '0'
    tag = tag + fs + "c"
    ivas_br = "256000"
    dtx = "0"
    max_bw = "FB"
    gain_flag = -1
    sba_order = "+1"
@@ -109,7 +119,7 @@ def test_bypass_enc(
    sba_enc(
        dut_encoder_frontend,
        test_vector_path,
        ref_encoder_path,
        ref_encoder_frontend,
        reference_path,
        dut_base_path,
        None,
@@ -123,13 +133,13 @@ def test_bypass_enc(
        sba_order,
        update_ref,
        gain_flag,
        cut_testv=True
        cut_testv=True,
    )

    # dec
    sba_dec(
        dut_decoder_frontend,
        ref_decoder_path,
        ref_decoder_frontend,
        reference_path,
        dut_base_path,
        tag,
@@ -152,15 +162,14 @@ def test_bypass_enc(
@pytest.mark.parametrize("tag", tag_list)
@pytest.mark.parametrize("fs", sample_rate_list)
@pytest.mark.parametrize("gain_flag", gain_list)
@pytest.mark.parametrize("SID", SID_list)
def test_sba_enc_system(
    dut_encoder_frontend: EncoderFrontend,
    dut_decoder_frontend: DecoderFrontend,
    test_vector_path,
    reference_path,
    dut_base_path,
    ref_encoder_path,
    ref_decoder_path,
    ref_encoder_frontend,
    ref_decoder_frontend,
    br_switch_file_path,
    update_ref,
    keep_files,
@@ -169,30 +178,28 @@ def test_sba_enc_system(
    tag,
    fs,
    gain_flag,
    SID,
):

    if dtx == '1' and ivas_br not in ['13200','16400','24400','32000','64000']:
    SID = 0
    if dtx == "1" and ivas_br not in ["13200", "16400", "24400", "32000", "64000"]:
        # skip high bitrates for DTX until DTX issue is resolved
        pytest.skip()
    if SID == 1:
        if ivas_br not in ['13200','16400','64000'] or fs == '16' or gain_flag == 1 or dtx == '0':
    if ivas_br == "sw_24k4_256k.bin" and gain_flag != 1:
        pytest.skip()
    if ivas_br == "13200" or ivas_br == "16400":
        if dtx == "1" and gain_flag == 0 and fs != "16":
            SID = 1
        else:
        if ivas_br in ['13200','16400']:
            pytest.skip()
    if ivas_br == 'sw_24k4_256k.bin' and gain_flag != 1:
    if gain_flag == 1 and ivas_br not in ["13200", "16400", "24400", "32000"]:
        pytest.skip()
    if gain_flag == 1 and ivas_br not in ['13200','16400','24400','32000']:
        pytest.skip()
    tag = tag + fs + 'c'
    tag = tag + fs + "c"
    max_bw = "FB"
    bypass = -1
    sba_order = "+1"
    output_config = "FOA"
    if gain_flag == 1:
        cut_gain = "16.0"
    elif dtx == '1':
    elif dtx == "1":
        cut_gain = ".004"
    else:
        cut_gain = "1.0"
@@ -200,7 +207,7 @@ def test_sba_enc_system(
    sba_enc(
        dut_encoder_frontend,
        test_vector_path,
        ref_encoder_path,
        ref_encoder_frontend,
        reference_path,
        dut_base_path,
        br_switch_file_path,
@@ -216,13 +223,13 @@ def test_sba_enc_system(
        gain_flag,
        cut_gain=cut_gain,
        create_dutenc=True,
        cut_testv=True
        cut_testv=True,
    )

    # dec
    sba_dec(
        dut_decoder_frontend,
        ref_decoder_path,
        ref_decoder_frontend,
        reference_path,
        dut_base_path,
        tag,
@@ -248,18 +255,18 @@ def test_spar_hoa2_enc_system(
    test_vector_path,
    reference_path,
    dut_base_path,
    ref_encoder_path,
    ref_decoder_path,
    ref_encoder_frontend,
    ref_decoder_frontend,
    update_ref,
    keep_files,
    ivas_br,
    tag,
):
    fs = '48'
    dtx = '0'
    fs = "48"
    dtx = "0"
    gain_flag = -1

    tag = tag + fs + 'c'
    tag = tag + fs + "c"
    max_bw = "FB"
    bypass = -1
    sba_order = "+2"
@@ -269,7 +276,7 @@ def test_spar_hoa2_enc_system(
    sba_enc(
        dut_encoder_frontend,
        test_vector_path,
        ref_encoder_path,
        ref_encoder_frontend,
        reference_path,
        dut_base_path,
        None,
@@ -288,7 +295,7 @@ def test_spar_hoa2_enc_system(
    # dec
    sba_dec(
        dut_decoder_frontend,
        ref_decoder_path,
        ref_decoder_frontend,
        reference_path,
        dut_base_path,
        tag,
@@ -314,18 +321,18 @@ def test_spar_hoa3_enc_system(
    test_vector_path,
    reference_path,
    dut_base_path,
    ref_encoder_path,
    ref_decoder_path,
    ref_encoder_frontend,
    ref_decoder_frontend,
    update_ref,
    keep_files,
    ivas_br,
    tag,
):
    fs = '48'
    dtx = '0'
    fs = "48"
    dtx = "0"
    gain_flag = -1

    tag = tag + fs + 'c'
    tag = tag + fs + "c"
    max_bw = "FB"
    bypass = -1
    sba_order = "+3"
@@ -335,7 +342,7 @@ def test_spar_hoa3_enc_system(
    sba_enc(
        dut_encoder_frontend,
        test_vector_path,
        ref_encoder_path,
        ref_encoder_frontend,
        reference_path,
        dut_base_path,
        None,
@@ -354,7 +361,7 @@ def test_spar_hoa3_enc_system(
    # dec
    sba_dec(
        dut_decoder_frontend,
        ref_decoder_path,
        ref_decoder_frontend,
        reference_path,
        dut_base_path,
        tag,
@@ -382,8 +389,8 @@ def test_sba_enc_BWforce_system(
    test_vector_path,
    reference_path,
    dut_base_path,
    ref_encoder_path,
    ref_decoder_path,
    ref_encoder_frontend,
    ref_decoder_frontend,
    update_ref,
    keep_files,
    ivas_br,
@@ -391,16 +398,16 @@ def test_sba_enc_BWforce_system(
    tag,
    sample_rate_bw_idx,
):
    if dtx == '1' and ivas_br not in ['32000','64000']:
    if dtx == "1" and ivas_br not in ["32000", "64000"]:
        # skip high bitrates for DTX until DTX issue is resolved
        pytest.skip()
    if ivas_br == '13200' or ivas_br == '16400':
    if ivas_br == "13200" or ivas_br == "16400":
        pytest.skip()
    if ivas_br == 'sw_24k4_256k.bin':
    if ivas_br == "sw_24k4_256k.bin":
        pytest.skip()
    fs = sample_rate_bw_idx[0]
    bw = sample_rate_bw_idx[1]
    tag = tag + fs + 'c'
    tag = tag + fs + "c"
    bypass = -1
    gain_flag = -1
    sba_order = "+1"
@@ -410,7 +417,7 @@ def test_sba_enc_BWforce_system(
    sba_enc(
        dut_encoder_frontend,
        test_vector_path,
        ref_encoder_path,
        ref_encoder_frontend,
        reference_path,
        dut_base_path,
        None,
@@ -424,13 +431,13 @@ def test_sba_enc_BWforce_system(
        sba_order,
        update_ref,
        gain_flag,
        cut_testv=True
        cut_testv=True,
    )

    # dec
    sba_dec(
        dut_decoder_frontend,
        ref_decoder_path,
        ref_decoder_frontend,
        reference_path,
        dut_base_path,
        tag,
@@ -452,7 +459,7 @@ def test_sba_enc_BWforce_system(
def sba_enc(
    encoder_frontend,
    test_vector_path,
    ref_encoder_path,
    ref_encoder_frontend,
    reference_path,
    dut_base_path,
    br_switch_file_path,
@@ -466,11 +473,10 @@ def sba_enc(
    sba_order,
    update_ref,
    gain_flag,
    cut_gain='1.0',
    cut_gain="1.0",
    create_dutenc=False,
    cut_testv=False
    cut_testv=False,
):

    # ------------  run cmd  ------------
    dut_out_dir = f"{dut_base_path}/sba_bs/pkt"
    ref_out_dir = f"{reference_path}/sba_bs/pkt"
@@ -487,13 +493,13 @@ def sba_enc(
        tag = tag + dict_bw_tag[ivas_max_bw]

    tag_out = f"{tag}_ivasbr{ivas_br[:-3]}k_DTX{dtx}"
    if ivas_br == 'sw_24k4_256k.bin':
    if ivas_br == "sw_24k4_256k.bin":
        ivas_br = f"{br_switch_file_path}/sw_24k4_256k.bin"
    short_tag_ext = ""
    if gain_flag == 1:
        short_tag_ext += f'_Gain{gain_flag}'
        short_tag_ext += f"_Gain{gain_flag}"
    if SID == 1:
        short_tag_ext += f'_SID'
        short_tag_ext += f"_SID"
    # we update only bypass = 0/2 (bypass 1 is the same as the baseline)
    if bypass in [0, 2]:
        short_tag_ext += f"_pca{bypass}"
@@ -510,10 +516,12 @@ def sba_enc(
    if SID == 1:
        dut_pkt_file_cut = f"{dut_out_dir}/{tag_out}{long_tag_ext}_cut.pkt"
        ref_pkt_file_cut = f"{ref_out_dir}/{tag_out}{short_tag_ext}_cut.pkt"
        ref_pkt_file_dutenc_cut = f"{ref_out_dir}/{tag_out}{short_tag_ext}_dutenc_cut.pkt"
        ref_pkt_file_dutenc_cut = (
            f"{ref_out_dir}/{tag_out}{short_tag_ext}_dutenc_cut.pkt"
        )
    input_path = f"{test_vector_path}/{tag_in}{in_extension}"
    bypass_mode = bypass if bypass >= 0 else None
    dtx_mode = dtx == '1'
    dtx_mode = dtx == "1"

    if cut_testv:
        # use shortened and potentially gain adjusted input PCM file - create if not present
@@ -526,13 +534,20 @@ def sba_enc(
        else:
            cut_file = f"{test_vector_path}/{tag_in}_cut_{cut_gain}{in_extension}"
        if not os.path.exists(cut_file):
            cut_samples(input_path, cut_file, num_channels, sampling_rate + "000", cut_from, cut_len, cut_gain)
            cut_samples(
                input_path,
                cut_file,
                num_channels,
                sampling_rate + "000",
                cut_from,
                cut_len,
                cut_gain,
            )
        input_path = cut_file

    if ref_encoder_path:
        ref_encoder = EncoderFrontend(ref_encoder_path, "REF")
    if ref_encoder_frontend:
        # call REF encoder
        ref_encoder.run(
        ref_encoder_frontend.run(
            ivas_br,
            sampling_rate,
            input_path,
@@ -569,7 +584,7 @@ def sba_enc(
        )

    if SID == 1:
        if ref_encoder_path:
        if ref_encoder_frontend:
            with open(ref_pkt_file, "rb") as fp_in:
                with open(ref_pkt_file_cut, "wb") as fp_out:
                    fr_cnt, cut_cnt = cut_from_start(fp_in, fp_out, 0, True)
@@ -583,9 +598,11 @@ def sba_enc(
                with open(dut_pkt_file_cut, "wb") as fp_out:
                    fr_cnt, cut_cnt = cut_from_start(fp_in, fp_out, 0, True)
            os.remove(dut_pkt_file)


def sba_dec(
    decoder_frontend,
    ref_decoder_path,
    ref_decoder_frontend,
    reference_path,
    dut_base_path,
    tag,
@@ -600,7 +617,6 @@ def sba_dec(
    gain_flag,
    keep_files,
):

    # --------  run cmd  ------------
    # sampling rate to BW mapping
    bw_idx = dict_fsample_bw[sampling_rate]
@@ -611,12 +627,12 @@ def sba_dec(

    short_tag_ext = ""
    if gain_flag == 1:
        short_tag_ext += f'_Gain{gain_flag}'
        short_tag_ext += f"_Gain{gain_flag}"
    # we update only bypass = 0/2 (bypass 1 is the same as the baseline)
    if bypass in [0, 2]:
        short_tag_ext += f"_pca{bypass}"
    if SID == 1:
       short_tag_ext += f'_SID_cut'
        short_tag_ext += f"_SID_cut"
    # to avoid conflicting names in case of parallel test execution, differentiate all cases
    if gain_flag == 1:
        long_tag_ext = f"_Gain{gain_flag}"
@@ -636,11 +652,9 @@ def sba_dec(
    check_and_makedir(dut_out_dir)
    check_and_makedir(ref_out_dir)

    if ref_decoder_path:
        ref_decoder = DecoderFrontend(ref_decoder_path, "REF")

    if ref_decoder_frontend:
        # call REF decoder
        ref_decoder.run(
        ref_decoder_frontend.run(
            output_config,
            sampling_rate,
            ref_in_pkt,